use ActionManager#tryToExecute to simplify code (IDEA-CR-9987) clion/146.1132 clion/146.1145 dbe/146.1128 idea/146.1130 phpstorm/146.1131 pycharm/146.1129 pycharm/146.1137 rubymine/146.1134 webstorm/146.1138
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Thu, 7 Apr 2016 21:42:44 +0000 (00:42 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Thu, 7 Apr 2016 21:42:44 +0000 (00:42 +0300)
platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java
platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java

index 761e9e35a83e92641e99c0544ee2bc33c8ca1982..34f0649183ac2f46f812c448f21c247e9b452b24 100644 (file)
@@ -25,7 +25,6 @@ import com.intellij.execution.filters.TextConsoleBuilderFactory;
 import com.intellij.execution.impl.ConsoleViewImpl;
 import com.intellij.execution.ui.*;
 import com.intellij.execution.ui.actions.CloseAction;
-import com.intellij.ide.DataManager;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.actionSystem.ex.ActionUtil;
@@ -39,9 +38,9 @@ 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.openapi.wm.IdeFocusManager;
 import com.intellij.util.ui.JBUI;
 import com.intellij.util.ui.update.UiNotifyConnector;
 import org.jetbrains.annotations.NotNull;
@@ -135,7 +134,7 @@ public class AnalyzeStacktraceUtil {
                                             @NotNull RunContentDescriptor descriptor,
                                             @NotNull ConsoleView consoleView,
                                             @NotNull String stacktrace) {
-    AnAction replaceAction = ActionManager.getInstance().getAction("Replace");
+    AnAction replaceAction = ActionManager.getInstance().getAction(IdeActions.ACTION_REPLACE);
     if (replaceAction == null) {
       return;
     }
@@ -150,7 +149,11 @@ public class AnalyzeStacktraceUtil {
             UiNotifyConnector.doWhenFirstShown(myEditorPanel, new Runnable() {
               @Override
               public void run() {
-                performReplaceAction(project, replaceAction, myEditorPanel);
+                ActionManager.getInstance().tryToExecute(replaceAction,
+                                                         ActionCommand.getInputEvent(IdeActions.ACTION_REPLACE),
+                                                         myEditorPanel,
+                                                         ActionPlaces.UNKNOWN,
+                                                         false);
               }
             });
             return result;
@@ -168,26 +171,6 @@ public class AnalyzeStacktraceUtil {
     }, 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));
-  }
-
   private static final class MyConsolePanel extends JPanel {
     public MyConsolePanel(ExecutionConsole consoleView, ActionGroup toolbarActions) {
       super(new BorderLayout());
index 6a1bc288ffdb3b6c8085219ef670afc940205f44..3cb240e070cac5256c5d7e7b71d48dd2a6c80fca 100644 (file)
@@ -142,6 +142,7 @@ public interface IdeActions {
   @NonNls String ACTION_SELECT_NEXT_OCCURENCE = "SelectNextOccurrence";
   @NonNls String ACTION_SELECT_ALL_OCCURRENCES = "SelectAllOccurrences";
   @NonNls String ACTION_UNSELECT_PREVIOUS_OCCURENCE = "UnselectPreviousOccurrence";
+  @NonNls String ACTION_REPLACE = "Replace";
   @NonNls String ACTION_COMPILE = "Compile";
   @NonNls String ACTION_COMPILE_PROJECT = "CompileProject";
   @NonNls String ACTION_MAKE_MODULE = "MakeModule";