I work on the plugin that somehow changes the selected artwork. Let's say that it simply sets the fill color of all the selected paths to the user selected value. I added it to the "Object" menu and then user clicks my item, I display a nice HTML UI (using CSXS) window. The UI part asks for a color, then sends it to my C++ code that does the job.
So far so good, but how do I implement that preview checkbox that you may see in other built-in Illustrator dialogs? Any change that I make to the scene is wrapped to its own undo record and if I select some colors, I'll end up with a bunch of undo/redo records in my document. More, if I have some redo records before I call my plugin - they will be lost
The built-in dialogs with preview somehow manage to keep the undo/redo stack intact, but still display preview.
I tried to keep a single app context through the lifetime of my UI window using push/pop of app contexts or by suspending and resuming it when needed, but it doesn't work. It looks like undo records are created for each plugin call and with that HTML UI I get more than just a single call, so get many contexts and many undo records...
So the question is: what is the best practice of implementing HTML UI with preview that doesn't alter undo/redo stack?
I think that is what AIUndo::SetSilent is for, but searching for SetSilent in this forum, it seems it may not be too reliable. There is also AIUndo::SetKind which can be called with kAISilentUndoContext. I haven't tried either of these functions.
Tried that without success. Both SetSilent() and SetKind() return no error, really change state, but don't affect undo/redo queue - the records are still there. The reason is probably that the CSXS UI is not modal for Illustrator, so all that undo/redo magic doesn't work. Looks like I need to make my UI really modal and block the main thread to keep everything in single undo context. I wonder if it is possible at all with CSXS.