Undo stack question
-
I've implemented a plugin that does custom coloring of the model based on user defined attributes. When my plugin is active, I want to let the user explore the model but not change anything. Right now I'm launching my web dialog using show and not show_modal to keep the navigation tools available. To undo my custom coloring, I'm using transactions. I do a start_operation when my plugin loads and an abort_operations when it closes.
Now the problem that has come up, is that if I do anything that modifies the undo stack while my plugin is active, then when I call abort_operation, the model doesn't properly reset since one of the intermediate operations has probably already commited the transaction.
I'm trying to solve this right now by implementing a model observer and watching the onTransactionStart, Abort, Commit, Empty methods to see if I can make any sense of that. Right now I've just implemented counters to see how many times the various events are firing and there doesnt seem to be a 1-1 correlation with the undo stack... I'm seeing way more start/commit events than things on the Undo stack.
Does anyone have any tips on how to solve this the right way?
Thanks,
Josh -
Firstly: a Transaction does not equal an Operation.
An Operation can have many Transactions.
In another thread we discussed the need for observers that fire for the Operation as a whole. (There are no such observers at this time.)
I would suggest abandoning your transaction observer modus, and switch your plugin code to a
Tool
class. When your tool is active, the user can still use any of the navigators (orbit, etc.) but not any of the other editing tools. -
Thanks Dan. Switching over to a tool from a plugin solved just about all of my issues. The only Undo/Redo stack modifier that I seem to be left with is the Layers window. When I've got my tool up, doing anything in the layers dialog causes the stack to be modified so my tool might not close out right. I've started looking at the transaction idea again to see if I can make sense of the stack state that way. Any ideas on this one?
Thanks again for all of your help,
Josh -
Your Tool could instantiate a custom LayersObserver subclass:
http://code.google.com/apis/sketchup/docs/ourdoc/layersobserver.html -
I saw that class, but it doesn't seem to have an event for letting you know when layer visibility has changed. It can tell you when layer(s) are deleted, or when a the active layer is changed... Is there another event that I'm not seeing that might tell me when visibility changes?
-
You are correct ...
... a
Layer
is a subclass ofEntity
, so perhaps theEntityObserver
might fire theonChangeEntity()
callback. You'd have to try it. I do not know if it will work.
Advertisement