I have a plugin that I recently coded up that extracts the layer style of a layer into its own layer, but this operation takes up 5 steps, so a user would have to press undo 5 times to fully return to how the project was before the operation was run.
I want to make it so that the operation can be undone in just one undo. How can I do that?
I don’t think that it is possible because what makes and doesn’t make an undo entry is coded into the tool functions together with its “undo strategy”. So you can’t really prevent an undo entry from happening because that’s happening inside the function you call and that’s a black box to the python API.
With no transaction support, there is no easy way to do it. You’ll have to monitor the undo history docker and mark where your actions are in the state, then when undo is done on that point you automate the undo and redo to do 1 instead of 5
The other option is create a new document, do the operations there and then inject it back in as 1 step