+ /**
+ * 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("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() {
+ performReplaceAction(project, replaceAction, myEditorPanel);
+ }
+ });
+ 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 void performReplaceAction(@NotNull Project project, @NotNull AnAction replaceAction,
+ @NotNull JComponent contextComponent) {
+ IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
+ @Override
+ public void run() {
+ DataContext context = DataManager.getInstance().getDataContext(contextComponent);
+ AnActionEvent actionEvent = AnActionEvent.createFromAnAction(replaceAction, null, ActionPlaces.UNKNOWN, context);
+ replaceAction.update(actionEvent);
+ if (actionEvent.getPresentation().isEnabledAndVisible()) {
+ ActionUtil.performActionDumbAware(replaceAction, actionEvent);
+ }
+ }
+ });
+ //ApplicationManager.getApplication().invokeLater(new Runnable() {
+ // @Override
+ // public void run() {
+ // }
+ //}, ModalityState.stateForComponent(contextComponent));
+ }
+