Skip to main content
Participant
November 3, 2007
Question

DeletePreProcess and DeletePostProcess

  • November 3, 2007
  • 5 replies
  • 597 views
I get the same ASSERT as the one described in the InDesign CS3: Selecting Hyperlink text post, but I don't understand the answer that was given. (I'm not using hypertext links, though -- I want to be able to automatically delete all contiguous characters with a particular attribute.)

I know I shouldn't increase the range in the DeletePreProcess() call, but I don't inderstand how to "disable the pending command" or why I would want to. (I can disable the delete by setting the length to 0, but that prevents DeletePostProcess() from ever getting called.) I'm also not sure what it means to "schedule a command" as opposed to just executing one, but I can probably look that up somewhere.

What I want to do is delete a range of characters when someone deletes the first or last character in the range. (Users won't be able to delete any of the other characters because my selection observer selects the whole range when any character in the range is selected.)

It looks to me as though I have to determine the range to delete in DeletePreProcess() and schedule a command to delete them in DeletePostProcess(), but I don't know how to let the DeletePostProcess() know about the range, other than to save it in some static class, which seems pretty kludgy.

What's the recommended way of doing this?

Thanks.

Bob
This topic has been closed for replies.

5 replies

Inspiring
November 6, 2007
Use ICommand::kAutoUndoWithPreviousCmd of CS2 or the slightly renamed equivalent of CS3.

And please remember to improve the wiki!

Dirk
Participant
November 6, 2007
Okay, now everything is deleted properly, but I still have a problem.

Because the command to delete the range is scheduled (as opposed to simply being executed) in DeletePostProcess(), it isn't part of the original delete command, so the Undo operation isn't atomic, i.e., the first Undo will restore the range of deleted characters and the second Undo will restore the character originally deleted by the user.

Not surprisingly, Begin/EndAutoUndoSequence doesn't have any effect, so how can I make the user's delete and the delete I schedule in DeletePostProcess() all one command?

Thanks.

Bob
Inspiring
November 5, 2007
At least I did not write "you must not" ...

I understand if you want to guard a range against partial delete, you have to detect somehow it is really broken rather than just touched. Details are up to your implementation, you probably tag either side of your range with special characters, owned items, or attributes. If I remember that correctly, the hidden text example does something like that, but I haven't visited it in years.

As a completely different route, I would also have a deeper look into ways to create an own strand. Attributes have their purposes for information with an influence on composer or output, many users don't like them at all except indirectly through styles. E.g. how do you deal with it when the user chooses "clear all overrides" to zap the "+" override indicator...

Dirk
Participant
November 5, 2007
Thanks for the response, Dirk.

Re: "I'm not sure why you would store anything in statics - the PostProcess is given the same information so you could even do everything from there."

In the PostProcess, I get the range of characters that was deleted, but at that point I don't know whether or not those characters had the attribute I'm interested in. Don't I need to check them in PreProcess before they're deleted, i.e., how can I check the attributes of a character that's already been deleted?

Thanks for any additional info.

Bob
Inspiring
November 3, 2007
You are on the right track.

If you do not agree to the change (e.g. because you consider the range write protected), disable it during PreProcess.
If you agree to the change but want additional clean up (more deletes), do that from PostProcess. Only then you know that all other plugins have approved the change. In your situation there is no need to suppress the original delete.

Notifications (including these pre/post, also most observer changes) occur during command processing. If you interfer with the pending command while it is on the way, you can cause trouble such as recursions, inconsistencies. Especially if you modify the same object, in this case the text model.

InDesign has a solution for this problem, a queue of commands. You add yours to the queue using the schedule calls in CmdUtils, and the command processor will execute them as soon as possible.

I'm not sure why you would store anything in statics - the PostProcess is given the same information so you could even do everything from there.

Btw, please help to improve the wiki. If you benefit from information such as the other thread, remember this forum is purged after a while so you just got lucky. Please contribute a bit of your time, and move the relevant parts of such a thread to a new wiki entry.

For example, we don't yet have entries for the mentioned assert, but the main information would better go on a new page for text pre/post processing.

http://www.niemannross.com/developer/wiki/index.php?title=InDesign_Asserts