To undo or not to undo?
Ladies and Gents,
my code has an action that executes a Document.insertString inside a runWriteAction.
Furthermore, it uses executeCommand to declare an undoableActionPerformed for undoing/redoing the insert.
Both the insert and undo/redo work like a charm.
The unfortunate part of the process is that any changes made before the insert cannot be undone.
I get the "Cannot Undo" message box, that stops me in my tracks.
How is it possible to get around that?
Thanks,
Mike.
Please sign in to leave a comment.
Hello Mike,
You don't need to call undoableActionPerformed(). Performing insertString()
inside the command is completely sufficient to have undo/redo working.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hi Dmitry, thank you for the prompt reply.
Before I posted the question I read the forum and got every possible detail about the undo.
It states what you have stated in your reply and I tried all that before posting.
It didn't work for me (IDEA 9.0.3). I tried various ways, inside the command, inside the runWrite, both.
I could only get it to work with the undoableAction.
There must be something stupidly simple that I am missing, but I can't see it.
Do I need to do something else after the insert ?
Regards,
Mike.
Hello Mike,
To make sure you're using the write action and command correctly, you can
use the WriteCommandAction helper class. Please try it, and if it doesn't
work, please attach a code snippet showing what you're trying to do.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Dmitry, it works like a charm!
I eventually got it working, after realising that the WriteCommandAction needs to be inside the runWriteAction.
Not the other way around as I originally had it.
Thank you for the help Dmitry. It is well appreciated.
Regards,
Mike.
Hello Mike,
WriteCommandAction does both a write action and a command in the correct
order. You don't need to wrap it in an extra runWriteAction().
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Thanks Dmitry. Got it!