enable in-place replace action for Analyze Stacktrace (IDEA-CR-9987) appcode/146.1158
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 8 Apr 2016 21:12:13 +0000 (00:12 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 8 Apr 2016 21:12:13 +0000 (00:12 +0300)
platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java
platform/lang-impl/src/com/intellij/openapi/editor/actions/IncrementalFindAction.java
platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java
platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java

index a5570e0450270ace339aa5171b83777925925137..f46811c0a2d162907f95c75bfb6f27c227b4dec1 100644 (file)
@@ -992,7 +992,13 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
         }
       }
       else {
-        LOG.warn("unhandled external change: " + event);
+        if (ConsoleViewUtil.isReplaceActionEnabledForConsoleViewEditor(myEditor)) {
+          clearHyperlinkAndFoldings();
+          highlightHyperlinksAndFoldings(event.getDocument().createRangeMarker(0, 0));
+        }
+        else {
+          LOG.warn("unhandled external change: " + event);
+        }
       }
     }
   }
index a5bf21e817a4ae16a0c39634af5b61f3b6599f0b..347cb9e52d408d714eb1ef2ca20af114e38c1e10 100644 (file)
@@ -66,7 +66,8 @@ public class IncrementalFindAction extends EditorAction {
 
     @Override
     public boolean isEnabled(Editor editor, DataContext dataContext) {
-      if (myReplace && ConsoleViewUtil.isConsoleViewEditor(editor)) {
+      if (myReplace && ConsoleViewUtil.isConsoleViewEditor(editor) &&
+          !ConsoleViewUtil.isReplaceActionEnabledForConsoleViewEditor(editor)) {
         return false;
       }
       Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getComponent()));
index 34f0649183ac2f46f812c448f21c247e9b452b24..edc2b6156d799f1eab5894a2b0b7d91ddbe3da56 100644 (file)
@@ -23,11 +23,14 @@ import com.intellij.execution.filters.Filter;
 import com.intellij.execution.filters.TextConsoleBuilder;
 import com.intellij.execution.filters.TextConsoleBuilderFactory;
 import com.intellij.execution.impl.ConsoleViewImpl;
-import com.intellij.execution.ui.*;
+import com.intellij.execution.impl.ConsoleViewUtil;
+import com.intellij.execution.ui.ConsoleView;
+import com.intellij.execution.ui.ConsoleViewContentType;
+import com.intellij.execution.ui.ExecutionConsole;
+import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.execution.ui.actions.CloseAction;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.*;
-import com.intellij.openapi.actionSystem.ex.ActionUtil;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.editor.Document;
@@ -38,19 +41,15 @@ import com.intellij.openapi.extensions.ExtensionPointName;
 import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.ide.CopyPasteManager;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.playback.commands.ActionCommand;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.ui.JBUI;
-import com.intellij.util.ui.update.UiNotifyConnector;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
 import java.awt.datatransfer.DataFlavor;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 
 /**
  * @author yole
@@ -105,13 +104,13 @@ public class AnalyzeStacktraceUtil {
         return true;
       }
     };
-    registerReplaceAction(project, descriptor, consoleView, text);
 
     final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
     for (AnAction action: consoleView.createConsoleActions()) {
       toolbarActions.add(action);
     }
     final ConsoleViewImpl console = (ConsoleViewImpl)consoleView;
+    ConsoleViewUtil.enableReplaceActionForConsoleViewEditor(console.getEditor());
     console.getEditor().getSettings().setCaretRowShown(true);
     toolbarActions.add(new AnnotateStackTraceAction(console.getEditor(), console.getHyperlinks()));
     toolbarActions.add(new CloseAction(executor, descriptor, project));
@@ -123,54 +122,6 @@ public class AnalyzeStacktraceUtil {
     return descriptor;
   }
 
-  /**
-   * Regular "Replace" editor action is unavailable for console editors (see com.intellij.openapi.editor.actions.IncrementalFindAction.Handler#isEnabled).
-   * However, it can be convenient to be able to replace user-specific paths with local paths
-   * if stacktrace links involves absolute paths (e.g. Node.js stack-traces contain absolute paths).
-   *
-   * @param consoleView
-   */
-  private static void registerReplaceAction(@NotNull Project project,
-                                            @NotNull RunContentDescriptor descriptor,
-                                            @NotNull ConsoleView consoleView,
-                                            @NotNull String stacktrace) {
-    AnAction replaceAction = ActionManager.getInstance().getAction(IdeActions.ACTION_REPLACE);
-    if (replaceAction == null) {
-      return;
-    }
-    ActionUtil.registerForEveryKeyboardShortcut(consoleView.getComponent(), new ActionListener() {
-      @Override
-      public void actionPerformed(ActionEvent e) {
-        AnalyzeStacktraceDialog dialog = new AnalyzeStacktraceDialog(project) {
-          @Override
-          protected JComponent createCenterPanel() {
-            JComponent result = super.createCenterPanel();
-            myEditorPanel.setText(stacktrace);
-            UiNotifyConnector.doWhenFirstShown(myEditorPanel, new Runnable() {
-              @Override
-              public void run() {
-                ActionManager.getInstance().tryToExecute(replaceAction,
-                                                         ActionCommand.getInputEvent(IdeActions.ACTION_REPLACE),
-                                                         myEditorPanel,
-                                                         ActionPlaces.UNKNOWN,
-                                                         false);
-              }
-            });
-            return result;
-          }
-
-          @Override
-          protected void doOKAction() {
-            super.doOKAction();
-            RunContentManager contentManager = ExecutionManager.getInstance(project).getContentManager();
-            contentManager.removeRunContent(DefaultRunExecutor.getRunExecutorInstance(), descriptor);
-          }
-        };
-        dialog.show();
-      }
-    }, replaceAction.getShortcutSet());
-  }
-
   private static final class MyConsolePanel extends JPanel {
     public MyConsolePanel(ExecutionConsole consoleView, ActionGroup toolbarActions) {
       super(new BorderLayout());
index 5453bc1e579212246cbab6fb42cabd758e573e06..00020f5ada4736de6166a47fb9912dd263da303a 100644 (file)
@@ -54,7 +54,7 @@ import static com.intellij.execution.ui.ConsoleViewContentType.registerNewConsol
 public class ConsoleViewUtil {
 
   public static final Key<Boolean> EDITOR_IS_CONSOLE_VIEW = Key.create("EDITOR_IS_CONSOLE_VIEW");
-
+  private static final Key<Boolean> REPLACE_ACTION_ENABLED = Key.create("REPLACE_ACTION_ENABLED");
 
   public static EditorEx setupConsoleEditor(Project project, final boolean foldingOutlineShown, final boolean lineMarkerAreaShown) {
     EditorFactory editorFactory = EditorFactory.getInstance();
@@ -141,6 +141,14 @@ public class ConsoleViewUtil {
     return editor.getUserData(EDITOR_IS_CONSOLE_VIEW) == Boolean.TRUE;
   }
 
+  public static boolean isReplaceActionEnabledForConsoleViewEditor(@NotNull Editor editor) {
+    return editor.getUserData(REPLACE_ACTION_ENABLED) == Boolean.TRUE;
+  }
+
+  public static void enableReplaceActionForConsoleViewEditor(@NotNull Editor editor) {
+    editor.putUserData(REPLACE_ACTION_ENABLED, true);
+  }
+
   @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
   private static class ColorCache {
     static {