Detect actions on save
Answered
Use case:
My plugin handles external file write and undo operations (acting as rest server - not in scope of this issue). File write adds undo “My Plugin - File Write” labeled operation to stack. After some time when user want to undo I can detect if “My Plugin - File Write” is still on top of stack, and perform undo if it is.
Problem is when actions on save are performed - they add extra operations to undo stack so user cannot undo via my plugin.
I thought I could detect those registered actions, run them manually and group inside single undo group - but I don't think it's possible.
Is there any other solution I can do?
Please sign in to leave a comment.
Hi Marcin,
It's unclear what the issue is. How are you performing write and undo operations? Via
UndoManager
andUndoableAction
? If yes, I don't understand why actions on save cause problems. Please describe the use case and what is happening in the code in more details.Thank you for reply. Write operation is done using `WriteCommandAction.runWriteCommandAction` inside `CommandProcessor.getInstance().executeCommand` to have custom undo label and Undo is performed using `UndoManager`.
Scenario:
1. Plugin execute file write with custom undo label (undo = My File Write)
2. IntelliJ runs actions on save (undo = Rearrange code)
3. Plugin wants to undo My File Write so it checks available undo name - it does not match
Is it possible to detect that Rearrange code (or other auto actions) have been by IntelliJ and not by the user directly?
Thanks for clarification.
Unfortunately, I don't see a way to achieve what you want. Actions can be grouped under a single undo item by executing them as a single executeCommand, or setting the same groupId, but there is no control over particular on save actions. Particular on save actions are responsible for executing their own commands.