refactoring, cancel custom template by Escape 94.277 94.278
authorEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 9 Feb 2010 18:15:20 +0000 (21:15 +0300)
committerEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 9 Feb 2010 18:15:20 +0000 (21:15 +0300)
15 files changed:
java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorFromCallFix.java
java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorFromThisOrSuperFix.java
java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateLocalVarFromInstanceofAction.java
java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodFromUsageFix.java
java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java
java/java-impl/src/com/intellij/testIntegration/TestIntegrationUtils.java
platform/lang-impl/src/com/intellij/codeInsight/completion/TemplateInsertHandler.java
platform/lang-impl/src/com/intellij/codeInsight/template/CustomTemplateCallback.java
platform/lang-impl/src/com/intellij/codeInsight/template/TemplateEditingAdapter.java
platform/lang-impl/src/com/intellij/codeInsight/template/TemplateEditingListener.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EscapeHandler.java
platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java
xml/impl/src/com/intellij/codeInsight/completion/XmlTagInsertHandler.java
xml/impl/src/com/intellij/xml/refactoring/XmlTagInplaceRenamer.java

index 0527f0b18f7dac0184a091e95e5e9c9388d51d54..e2e669006723a0367a6766f45de22163b10f1723 100644 (file)
@@ -65,7 +65,7 @@ public class CreateConstructorFromCallFix extends CreateFromUsageBaseFix {
       editor.getCaretModel().moveToOffset(textRange.getStartOffset());
 
       startTemplate(editor, template, project, new TemplateEditingAdapter() {
-        public void templateFinished(Template template) {
+        public void templateFinished(Template template, boolean brokenOff) {
           ApplicationManager.getApplication().runWriteAction(new Runnable() {
             public void run() {
               try {
index 5b650ba422ddd7bcb155a794d58551ca8bc814e2..f954e5cefb7accda9dcf6dadb3324d9ec00b4eca 100644 (file)
@@ -108,7 +108,7 @@ public abstract class CreateConstructorFromThisOrSuperFix extends CreateFromUsag
       editor.getCaretModel().moveToOffset(textRange.getStartOffset());
 
       startTemplate(editor, template, project, new TemplateEditingAdapter() {
-        public void templateFinished(Template template) {
+        public void templateFinished(Template template, boolean brokenOff) {
           ApplicationManager.getApplication().runWriteAction(new Runnable() {
             public void run() {
               try {
index 14f04687e1c4bec56d7aa97fb2c6880eb2736e79..9e80437e43a9e8990779fe7a3d790f9cf31619d1 100644 (file)
@@ -166,7 +166,7 @@ public class CreateLocalVarFromInstanceofAction extends BaseIntentionAction {
       newEditor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
 
       CreateFromUsageBaseFix.startTemplate(newEditor, template, project, new TemplateEditingAdapter() {
-        public void templateFinished(Template template) {
+        public void templateFinished(Template template, boolean brokenOff) {
           ApplicationManager.getApplication().runWriteAction(new Runnable() {
             public void run() {
               PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
index bc461090e45c4c57317dd96f32b133f31fbf0668..bc3a15c092e4ed175ec65510688238db9b4115da 100644 (file)
@@ -231,7 +231,7 @@ public class CreateMethodFromUsageFix extends CreateFromUsageBaseFix {
 
     if (!shouldBeAbstract) {
       startTemplate(newEditor, template, project, new TemplateEditingAdapter() {
-        public void templateFinished(Template template) {
+        public void templateFinished(Template template, boolean brokenOff) {
           ApplicationManager.getApplication().runWriteAction(new Runnable() {
             public void run() {
               PsiDocumentManager.getInstance(project).commitDocument(newEditor.getDocument());
index a9755aa83b2d1cafdeb2163b81148863b78238b4..9d9da0b9233844fe40c9185203186918d5b4c338 100644 (file)
@@ -145,7 +145,7 @@ public abstract class GenerateMembersHandlerBase implements CodeInsightActionHan
     editor.getCaretModel().moveToOffset(offset);
     editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
     TemplateManager.getInstance(myProject).startTemplate(editor, template, new TemplateEditingAdapter() {
-      public void templateFinished(Template template) {
+      public void templateFinished(Template template, boolean brokenOff) {
         if (index + 1 < templates.size()){
           ApplicationManager.getApplication().invokeLater(new Runnable() {
             public void run() {
index ab864f3aeece53a4071fa5ad31a6b015e055d047..130e6f58b4d15be01a047006938378c89f4b36c3 100644 (file)
@@ -141,7 +141,7 @@ public class TestIntegrationUtils {
     if (!automatic) {
       adapter = new TemplateEditingAdapter() {
         @Override
-        public void templateFinished(Template template) {
+        public void templateFinished(Template template, boolean brokenOff) {
           ApplicationManager.getApplication().runWriteAction(new Runnable() {
             public void run() {
               PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
index bd7edb0b857c433d81cb15cef6d982a01c95906d..977adac61580c7b7204150738a7a0e673c138a69 100644 (file)
@@ -67,7 +67,7 @@ public abstract class TemplateInsertHandler implements InsertHandler {
     final RangeMarker offsetRangeMarker = document.createRangeMarker(templateStartOffset, templateStartOffset);
 
     TemplateManager.getInstance(editor.getProject()).startTemplate(editor, template, new TemplateEditingAdapter() {
-      public void templateFinished(Template template) {
+      public void templateFinished(Template template, boolean brokenOff) {
         lookupItem.setAttribute(EXPANDED_TEMPLATE_ATTR, Boolean.TRUE);
 
         if (!offsetRangeMarker.isValid()) return;
index a21c5a1bb9d9b154a111b7979ce79d9bf594a82d..d7b4bdeb5f6877fda31b24e14699354fc1401de3 100644 (file)
@@ -93,7 +93,8 @@ public class CustomTemplateCallback {
       }
 
       @Override
-      public void templateFinished(Template template) {
+      public void templateFinished(Template template, boolean brokenOff) {
+        if (brokenOff) return;
         templateFinished[0] = true;
         if (templateEnded[0] && listener != null) {
           listener.finished(true, true);
index cf2f82d599e2b6a6460fbef976617d59ed311444..743f8eb708f76a3b7d6090e3b5fe857f1674b3a9 100644 (file)
@@ -26,7 +26,7 @@ public abstract class TemplateEditingAdapter implements TemplateEditingListener
   public void beforeTemplateFinished(final TemplateState state, final Template template) {
   }
 
-  public void templateFinished(Template template) {
+  public void templateFinished(Template template, boolean brokenOff) {
   }
 
   public void templateCancelled(Template template) {
index 1fc89f4fd39fe3b1af914c3d9e273d1c5c16bbb5..0412c9a0a09725e7abd06e0986c6af6c1c56a93b 100644 (file)
@@ -23,7 +23,7 @@ import com.intellij.codeInsight.template.impl.TemplateState;
  */
 public interface TemplateEditingListener {
   void beforeTemplateFinished(TemplateState state, Template template);
-  void templateFinished(Template template);
+  void templateFinished(Template template, boolean brokenOff);
   void templateCancelled(Template template);
   void currentVariableChanged(TemplateState templateState, Template template, int oldIndex, int newIndex);
   void templateExpanded(Template template); 
index 7d870c0158ca831208da2662652436ed50e49b48..36283f15a0e3282cd5fa11caf013d884ee9f12ef 100644 (file)
@@ -322,7 +322,7 @@ public class TemplateState implements Disposable {
 
         int nextVariableNumber = getNextVariableNumber(-1);
         if (nextVariableNumber == -1) {
-          finishTemplateEditing();
+          finishTemplateEditing(false);
         }
         else {
           setCurrentVariableNumber(nextVariableNumber);
@@ -538,7 +538,7 @@ public class TemplateState implements Disposable {
       final TextResult value = getVariableValue(variableName);
       if (value != null && value.getText().length() > 0) {
         if (!myProcessor.process(variableName, value.getText())) {
-          finishTemplateEditing(); // nextTab(); ?
+          finishTemplateEditing(false); // nextTab(); ?
           return;
         }
       }
@@ -686,7 +686,7 @@ public class TemplateState implements Disposable {
           reformat();
         }
       });
-      finishTemplateEditing();
+      finishTemplateEditing(false);
       return;
     }
     focusCurrentHighlighter(false);
@@ -735,13 +735,17 @@ public class TemplateState implements Disposable {
     };
   }
 
-  public void gotoEnd() {
+  public void gotoEnd(boolean brokenOff) {
     calcResults(false);
     doReformat();
-    finishTemplateEditing();
+    finishTemplateEditing(brokenOff);
+  }
+
+  public void gotoEnd() {
+    gotoEnd(false);
   }
 
-  private void finishTemplateEditing() {
+  private void finishTemplateEditing(boolean brokenOff) {
     if (myTemplate == null) return;
 
     LookupManager.getInstance(myProject).hideActiveLookup();
@@ -774,7 +778,7 @@ public class TemplateState implements Disposable {
     setCurrentVariableNumber(-1);
     currentVariableChanged(oldVar);
     ((TemplateManagerImpl)TemplateManager.getInstance(myProject)).clearTemplateState(editor);
-    fireTemplateFinished();
+    fireTemplateFinished(brokenOff);
     myListeners.clear();
     myProject = null;
   }
@@ -992,12 +996,12 @@ public class TemplateState implements Disposable {
     myListeners.add(listener);
   }
 
-  private void fireTemplateFinished() {
+  private void fireTemplateFinished(boolean brokenOff) {
     if (myFinished) return;
     myFinished = true;
     TemplateEditingListener[] listeners = myListeners.toArray(new TemplateEditingListener[myListeners.size()]);
     for (TemplateEditingListener listener : listeners) {
-      listener.templateFinished(myTemplate);
+      listener.templateFinished(myTemplate, brokenOff);
     }
   }
 
index 2ef75be62b69945fa3d6b9fdb9119e14319c8232..943bb7d7210b34ce20d56aa29bb0bdcc15e79f23 100644 (file)
@@ -36,7 +36,7 @@ public class EscapeHandler extends EditorActionHandler {
       final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
       if (templateState != null && !templateState.isFinished()) {
         CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("finish.template.command"));
-        templateState.gotoEnd();
+        templateState.gotoEnd(true);
         return;
       }
     }
index d5fbe7650153c1f26e559beaac2ca495f0b87395..8b5f4db0883f8a42942ce6fca8ada92ecc69e865 100644 (file)
@@ -202,8 +202,8 @@ public class VariableInplaceRenamer {
               }
 
               @Override
-              public void templateFinished(Template template) {
-                super.templateFinished(template);
+              public void templateFinished(Template template, boolean brokenOff) {
+                super.templateFinished(template, brokenOff);
                 if (myNewName != null) {
                   performAutomaticRename(myNewName, PsiTreeUtil.getParentOfType(containingFile.findElementAt(renameOffset), PsiNameIdentifierOwner.class));
                 }
index 59fd8b5197fc874e632c2d56fd38a2a01d11c4d9..76234e05e4af1ea5abe5f7c0516c9099699ad6de 100644 (file)
@@ -220,7 +220,7 @@ public class XmlTagInsertHandler implements InsertHandler<LookupElement> {
 
     final boolean weInsertedSomeCodeThatCouldBeInvalidated1 = weInsertedSomeCodeThatCouldBeInvalidated;
     templateManager.startTemplate(editor, template, new TemplateEditingAdapter() {
-      public void templateFinished(final Template template) {
+      public void templateFinished(final Template template, boolean brokenOff) {
         final int offset = editor.getCaretModel().getOffset();
 
         if (weInsertedSomeCodeThatCouldBeInvalidated1 &&
index c2184d72068f19c8570e2929567d8a63b8ce1040..9585643b775a7d160624b9a1da17e38d9759d6cf 100644 (file)
@@ -99,7 +99,7 @@ public class XmlTagInplaceRenamer {
 
               final Template t = buildTemplate(tag, pair);
               TemplateManager.getInstance(project).startTemplate(myEditor, t, new TemplateEditingAdapter() {
-                public void templateFinished(final Template template) {
+                public void templateFinished(final Template template, boolean brokenOff) {
                   finish();
                 }