Change of style in undo stack?
-
This is a smaller but somewhat annoying problem. The situation is this:
I have a few Plug-Ins which allow the user to switch between different working modes. To do so each Plug-In with its own button does 2 things:
1: Change the current style (between my predefined styles Construction and Display)
2: Turn on/off certain layersThe problem is that only the change of layers lands in the undo stack, which means that if I use one of the buttons to change the working mode, and then do a undo, I land right in between the modes where I don't want to be, the layers will be switched back like they were before, the style won't. Certain layers are only meant to be seen with certain styles though.
(The tools do use start/commit_operation to only add one step to the undo stack.)Possible solutions I could imagine would be:
- Completely prevent the tools from putting anything onto the undo stack. That way the current layout could be handled entirely by those plug-ins. I didn't encounter any way to do this though. This would be easy and elegant, and considering the only missing changes from the undo stack are layer visibility values there couldn't be any jumbled geometry either.
- Use observers to modify the undo stack, or rather make sure that when the last step was one of my tools the change of style will also be reverted. As far as I'd know this would require me to keep a separate stack parallel to the undo stack, which in turn would require almost twice as much code as the plug-ins themselves require, which seems rather unnecessary and inefficient to me.
If I could somehow access the name of the current undo/redo operations I could read and compare that value as I can freely name the operation with start_operation, which would make the separate stack unnecessary.
Considering though that the undo stack shouldn't be meddled with through these observers I'd prefer to somehow go with solution #1 and just prevent these tools from adding their layer changes to the undo stack.
-
@xorunison said:
Considering though that the undo stack shouldn't be meddled with through these observers I'd prefer to somehow go with solution #1 and just prevent these tools from adding their layer changes to the undo stack.
That's not possible. You can make things transparent - but that doesn't make the event avoid the undo stack it's still there.
Since the Style changes doesn't record on the undo stack, then I'd try to use observers to toggle the styles instead. It's only model changes (stuff that is recorded by the undo system) one should avoid doing in observer events.
-
@thomthom said:
@xorunison said:
Considering though that the undo stack shouldn't be meddled with through these observers I'd prefer to somehow go with solution #1 and just prevent these tools from adding their layer changes to the undo stack.
That's not possible. You can make things transparent - but that doesn't make the event avoid the undo stack it's still there.
Since the Style changes doesn't record on the undo stack, then I'd try to use observers to toggle the styles instead. It's only model changes (stuff that is recorded by the undo system) one should avoid doing in observer events.
I feared that might be the case. What about accessing the names of the things on the undo/redo stack then, would that be possible?
-
Afraid not. There is very little control over the undo stack in the API. It's an area where it needs improvement.
-
Well, that's too bad, thanks for your help though. I guess I will instead use observers to toggle the style according to which layers are visible, it'll ultimately achieve the same while saving me the trouble of writing huge chunks of code to meddle with the undo stack.
-
@xorunison said:
it'll ultimately achieve the same while saving me the trouble of writing huge chunks of code to meddle with the undo stack.
Yea, don't fight the undo stack - it's tricky and cause of grey hairs.
-
@xorunison said:
This is a smaller but somewhat annoying problem. The situation is this:
I have a few Plug-Ins which allow the user to switch between different working modes. To do so each Plug-In with its own button does 2 things:
1: Change the current style (between my predefined styles Construction and Display)
2: Turn on/off certain layersThis sounds like a perfect job for scenepages.
One for display, one for work. Each has their own styles set, and each has their own set of off layers, and on layers.
The button(s) could simply switch between the pages (if you did not want to waste the space for page tabs.)
The scenes could be preset into a template model.
Advertisement