RenameRefactoring undo/redo-history name

Is there any way to change the name of the standard RenameRefactoring in history?

For example, in my plugin (for batch variables renaming) I invoke it in such way:

RefactoringFactory refactoringFactory = RefactoringFactory.getInstance(project);
renameRefactoring = refactoringFactory.createRename(psiElement, replacement);
renameRefactoring.addElement(newElement1, newReplacement1);
renameRefactoring.addElement(newElement2, newReplacement2);

Here newElement1 and newElement2 (and psiElement) are different PsiElements(completely different variables).

Then I try to invoke this in Idea, and it works fine usually. But when I press "Undo" button, I got a popup window, and a question there is quite confusing: "Undo renaming variable psiElement to replacement?" ("OK"/"Cancel") instead of something like ""Undo renaming many variables?" Is there any way to replace this message? I know about UndoConfirmationPolicy and CommandProcessor classes, but it seems that I can't use them, because RenameRefactoring seems to put itself in undo/redo history(or maybe I don't understand what should I put in CommandProcessor.executeCommand-method as a groupId). Is there something I am missing?

P.S. Excuse my French :)

3 comments
Comment actions Permalink

Hello harryhoppel,

As far as I understand, you only need to wrap all your rename operations
in a single command executed through CommandProcessor. The groupId does not
matter in this case. You can specify your own name and undo confirmation
policy for the command.

h> Is there any way to change the name of the standard RenameRefactoring
h> in history?
h>
h> For example, in my plugin (for batch variables renaming) I invoke it
h> in such way:
h>
h> RefactoringFactory refactoringFactory =
h> RefactoringFactory.getInstance(project); renameRefactoring =
h> refactoringFactory.createRename(psiElement, replacement);
h> renameRefactoring.addElement(newElement1, newReplacement1);
h> renameRefactoring.addElement(newElement2, newReplacement2);
h>
h> Here newElement1 and newElement2 (and psiElement) are different
h> PsiElements(completely different variables).
h>
h> Then I try to invoke this in Idea, and it works fine usually. But
h> when I press "Undo" button, I got a popup window, and a question
h> there is quite confusing: "Undo renaming variable psiElement to
h> replacement?" ("OK"/"Cancel") instead of something like ""Undo
h> renaming many variables?" Is there any way to replace this message? I
h> know about UndoConfirmationPolicy and CommandProcessor classes, but
h> it seems that I can't use them, because RenameRefactoring seems to
h> put itself in undo/redo history(or maybe I don't understand what
h> should I put in CommandProcessor.executeCommand-method as a groupId).
h> Is there something I am missing?
h>
h> P.S. Excuse my French :)
h>
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

I see I wasn't quite clear yesterday :(

Yes, this is a good solution, but it works only partially, because when I invoke renameRefactoring.run(), it shows me all usages of my PsiElement[] psiElements. But if I invoke it in that way:

final UsageInfo[] usageInfos = renameRefactoring.findUsages();
CommandProcessor commandProcessor = CommandProcessor.getInstance();
commandProcessor.executeCommand(project, new Runnable() {
public void run() {
renameRefactoring.doRefactoring(usageInfos);
}
}, "MyRefactoring", null, UndoConfirmationPolicy.REQUEST_CONFIRMATION);

then I didn't see any usages-dialog(I mean, Idea just silently renames all variables - yes, in comments & non-java files too - although is should display "Do-Refactor"-dialog).Even if I add a following code, it doesn't show usages:

renameRefactoring.setPreviewUsages(true); //this line was added
final UsageInfo[] usageInfos = renameRefactoring.findUsages();
CommandProcessor commandProcessor = CommandProcessor.getInstance();
commandProcessor.executeCommand(project, new Runnable() {
public void run() {
renameRefactoring.setPreviewUsages(true); //this line was added
renameRefactoring.doRefactoring(usageInfos);
}
}, "MyRefactoring", null, UndoConfirmationPolicy.REQUEST_CONFIRMATION);


So, here is my question actually: Is there any comparatively easy way to put MY string for RenameRefactoring in undo-redo-history? Or should I dig in "com.intellij.usages"-package and try to show something like a confirmation-"Do Refactor"-dialog for refactoring?

Pardon my French once again :)

0
Comment actions Permalink

Hello harryhoppel,

h> So, here is my question actually: Is there any comparatively easy way
h> to put MY string for RenameRefactoring in undo-redo-history? Or
h> should I dig in "com.intellij.usages"-package and try to show
h> something like a confirmation-"Do Refactor"-dialog for refactoring?

No, there is no API to modify the command name used by RenameRefactoring.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.