Skip to main content
Inspiring
December 16, 2024
Question

After observing a story, how can I get the parameters of the insert or delete commands for the story

  • December 16, 2024
  • 1 reply
  • 124 views
void MyStoryObserver::AutoAttach()
{
 
do
{
InterfacePtr<ISubject> subject(this, IID_ISUBJECT);
if (subject != nil)
{
 
 
if (subject->IsAttached(ISubject::kBothAttachments, this, IID_ITEXTMODEL, IID_MYSTORY_OBSERVER) == kFalse)
{
subject->AttachObserver(ISubject::kBothAttachments, this, IID_ITEXTMODEL, IID_MYSTORY_OBSERVER);
}
 
}
} while (kFalse);
}
 
 
void MyStoryObserver::Update(
const ClassID& theChange,
ISubject* theSubject,
const PMIID& protocol,
void* changedBy)
{
if (protocol == IID_ITEXTMODEL)
{
 
 
ClassID changeClassID = theChange.Get();
UIDRef storyUIDRef(::GetUIDRef(this));
InterfacePtr<IDocument> iDocument(storyUIDRef.GetDataBase(), storyUIDRef.GetDataBase()->GetRootUID(), UseDefaultIID());
if (iDocument == nil) {
 
return;
}
do 
{
 
if (changeClassID == kInsertTextCmdBoss
|| changeClassID == kDeleteTextCmdBoss
)
{
 
ICommand* theCmd = static_cast<ICommand*>(changedBy);
if (theCmd && theCmd->GetCommandState() == ICommand::kDone) 
{
 
// How can I get the insertion position and the length of the inserted content  in the insert command, as well as the deletion position and the content length  in the delete command?
}
}
 
 
 
} while (kFalse);
}
}

 

1 reply

Community Expert
January 15, 2025

I'm not great with this stuff but just my 2cents

 

kInsertTextCmdBoss, use the IInsertTextCmdData interface.

kDeleteTextCmdBoss, use the IDeleteTextCmdData interface.


Use IInsertTextCmdData to get the insertion position and the length of the inserted text.


Use IDeleteTextCmdData to get the deletion position and the content being deleted.

 

Hope that helps