Undo programmatically Follow
Can i undo few CommandProcessor's command in one action? Can i group several actions in transaction? Otherwise user should use Ctrl+Z multiple times and it looks ugly.
P.S.I know count of actions, so if i could undo programatically i will do it serially in loop.
Please sign in to leave a comment.
If your commands specify the same groupId, they will be undone in one step.
I use
which incapsulate his own CommandProcessor.getInstance().executeCommand(..)
Is it possible to add this action or wrap it in other action for undo in one step?
You can try to wrap it in your own command - only top-level command should matter.
I set groupId, but Ctrl+z still undone each action separatelly. (It's not wrapping, i just testing groupId with my actions)
This usually works for simple text editing actions. For actions or commands marked as 'global' (com.intellij.openapi.command.undo.UndoableAction#isGlobal, com.intellij.openapi.command.CommandProcessor#markCurrentCommandAsGlobal) this doesn't seem to be the case though. I'll try to find out whether it's possible to achieve what you want for such actions/commands.
Arsen,
which actions exactly do you want to compose into one undoable action?
Anton Makeev,
Dmitry Batrak, Anton Makeev, any ideas?
Is is possible to take a look at the code?
https://github.com/CeH9/PackageTemplates/blob/2bece3a824f91b4bbc4ca96fe664bb8e575b0d98/src/global/utils/FileWriter.java#L54-L62
Looks like each command executed separately and deferred in invokeLater.
Please try doing all tasks under one CommandProcessor.getInstance().executeCommand.
It works with dirs
but don't work with
which incapsulate:
So 2 dirs + template reverts in 2 step, both dirs in one action, template in another.
Command might be broken by dialogs, template steps etc. but I'm afraid you'll need to debug the specific code to make sense of it.
Start with com.intellij.openapi.command.impl.UndoManagerImpl#commandStarted/commandFinished and check what exactly breaks the commands apart.
After spending several days in debugging i figure out that the problem isn't in Idea, actually error in my code.So "dir" with "CreateFromTemplate" wrapped in one Command undone fine.