Revert in intellij

Answered

There are many actions that has been done by plug-in or user. I want to revert them, How to revert them programmatically.

0
10 comments

It depends on the specific actions.

0

There are many changes to the content of files. Like there are some steps, in those steps the content of files or files can be changed completely.  I want to revert either all the steps or the latest one and may be some particular steps. How to revert them?

0

To be revertible changes mush be wrapped in com.intellij.openapi.command.CommandProcessor#executeCommand or com.intellij.openapi.command.WriteCommandAction. The changes will be recorder automatically and when user invokes Undo, reverted. 

Additionally, if you have custom work to undo (not file changes, e.g. in environment), you should use com.intellij.openapi.command.undo.UndoManager#undoableActionPerformed and provide undo/redo implementations

 

0

So in my use case, I need to revert the changes which are not necessarily on the top of the stack and there are lot of such changes. Is this possible?

0

Please any one tell me the solution.

0

Aarti, could you please describe exactly, what are these action you want to revert and in which case?

0

Actions are like adding the classes, adding the methods.. You can understand like, there are some steps, in each and every steps you are adding some files or changing the content of some files, or adding some extra methods to some files. All steps are not dependent, some are dependent. So like i am at step 4 and i want to revert step-1 and step-3 is dependent on step-1 means if i want to revert step-1 then step-3 should also be reverted. So some how i wanted to know what contained has been added in step-1 and step-3 So that i can revert them. How to revert that also i wanted to know.

0

Then the generic command-based mechanics should work for you: simply wrap the sequence of your action into WriteCommandAction. Have you tried this approach?

 

1

AFAIU, it's impossible to implement, because we can't decide whether "step-3 is dependent on step-1" or not in general case.

UndoManager treats changes in different files in different commands as independent. But if there are multiple consequent modifications in a single file, we can't revert anything but the last of them.

It's possible to consider each change in a document as independent "patch" and allow to revert some of them (with a possible conflict). It, probably, can be done via "Local History" API.

1

Nope, it's not possible if the existing API. You can only revert stack-wise. I'm afraid I don't understand the use case to be more specific here, but consider postponing all actions until the whole sequence is known and the apply them all together (so they are recorder as one step in undo history and 

1

Please sign in to leave a comment.