add command to slightly undo
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Thu, 12 May 2011 09:29:24 +0000 (13:29 +0400)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Thu, 12 May 2011 09:29:24 +0000 (13:29 +0400)
java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java
java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java
java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java

index ac814659dcc85f17981b053864a86013f4b30e5b..31ffb0844496049384a850b71789cbd0ff274392 100644 (file)
@@ -549,12 +549,17 @@ public class InplaceIntroduceConstantPopup {
         myReplaceAllCb.addItemListener(new ItemListener() {
           @Override
           public void itemStateChanged(ItemEvent e) {
-            final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
-            if (templateState != null) {
-              templateState.gotoEnd(true);
-              myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences);
-              startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType());
-            }
+            Runnable restartTemplateRunnable = new Runnable() {
+              public void run() {
+                final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
+                if (templateState != null) {
+                  templateState.gotoEnd(true);
+                  myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences);
+                  startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType());
+                }
+              }
+            };
+            CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, IntroduceConstantHandler.REFACTORING_NAME, IntroduceConstantHandler.REFACTORING_NAME);
           }
         });
 
index acf8d5349d7a9db9618764ad1edc1d2d7c67b39a..9c99c07722a44754fdf945ce35c656a02cae0dec 100644 (file)
  */
 package com.intellij.refactoring.introduceField;
 
+import com.intellij.codeInsight.CodeInsightBundle;
 import com.intellij.codeInsight.intention.impl.TypeExpression;
 import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
 import com.intellij.codeInsight.template.impl.TemplateState;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.Result;
 import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.RangeMarker;
 import com.intellij.openapi.editor.ScrollType;
@@ -309,12 +312,21 @@ public class InplaceIntroduceFieldPopup {
         myIntroduceFieldPanel.addOccurrenceListener(new ItemListener() {
           @Override
           public void itemStateChanged(ItemEvent e) {
-            final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
-            if (templateState != null) {
-              templateState.gotoEnd(true);
-              myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences);
-              startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType());
-            }
+            final Runnable restartTemplate = new Runnable() {
+              @Override
+              public void run() {
+                final TemplateState templateState =
+                  TemplateManagerImpl.getTemplateState(myEditor);
+                if (templateState != null) {
+                  templateState.gotoEnd(true);
+                  myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences);
+                  startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType());
+                }
+              }
+            };
+            CommandProcessor.getInstance().executeCommand(myProject, restartTemplate,
+                                                          IntroduceFieldHandler.REFACTORING_NAME,
+                                                          IntroduceFieldHandler.REFACTORING_NAME);
           }
         });
       }
index 9761f74e80b10c91777a7545cb8d497bf19aad49..a5a116df7c1228d16fcff2d7d7fb70d4a18ee97c 100644 (file)
@@ -424,14 +424,19 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI {
   protected void updateControls(JCheckBox[] removeParamsCb) {
     super.updateControls(removeParamsCb);
     if (myParameterIndex < 0) return;
-    final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
-    if (templateState != null) {
-      PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
-      final PsiParameter parameter = getParameter();
-      final boolean hasFinalModifier = parameter.hasModifierProperty(PsiModifier.FINAL);
-      templateState.gotoEnd(true);
-      startIntroduceTemplate(isReplaceAllOccurences(), hasFinalModifier);
-    }
+    Runnable restartTemplateRunnable = new Runnable() {
+      public void run() {
+        final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
+        if (templateState != null) {
+          PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
+          final PsiParameter parameter = getParameter();
+          final boolean hasFinalModifier = parameter.hasModifierProperty(PsiModifier.FINAL);
+          templateState.gotoEnd(true);
+          startIntroduceTemplate(isReplaceAllOccurences(), hasFinalModifier);
+        }
+      }
+    };
+    CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, IntroduceParameterHandler.REFACTORING_NAME, IntroduceParameterHandler.REFACTORING_NAME);
   }