inspection view: make apply fix toolbar and popup actions consistent IDEA-158795
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Tue, 26 Jul 2016 09:46:56 +0000 (12:46 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Tue, 26 Jul 2016 09:46:56 +0000 (12:46 +0300)
platform/lang-impl/src/com/intellij/codeInspection/ui/actions/InvokeQuickFixAction.java
platform/lang-impl/src/com/intellij/codeInspection/ui/actions/QuickFixesViewActionGroup.java

index 6fe216e6f1e52ee838c7ff3adf855c3b5dbfe3d3..55960664fd8c5dfc41012382ec4b225495e5f286 100644 (file)
@@ -19,18 +19,12 @@ package com.intellij.codeInspection.ui.actions;
 import com.intellij.codeInspection.InspectionsBundle;
 import com.intellij.codeInspection.ex.InspectionRVContentProvider;
 import com.intellij.codeInspection.ex.InspectionToolWrapper;
-import com.intellij.codeInspection.ex.QuickFixAction;
 import com.intellij.codeInspection.ui.InspectionResultsView;
 import com.intellij.icons.AllIcons;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.ui.popup.ListPopup;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.ArrayList;
-import java.util.List;
 
 /**
  * User: anna
@@ -52,51 +46,30 @@ public class InvokeQuickFixAction extends AnAction {
     final Presentation presentation = e.getPresentation();
     InspectionToolWrapper toolWrapper = myView.getTree().getSelectedToolWrapper(true);
     final InspectionRVContentProvider provider = myView.getProvider();
-    if (myView.isUpdating() && !myView.getTree().areDescriptorNodesSelected()) {
+    if (toolWrapper == null || cantApplyFixes(myView)) {
       presentation.setEnabled(false);
       return;
     }
-    if (toolWrapper != null && provider.isContentLoaded()) {
-      presentation.setEnabled(provider.hasQuickFixes(myView.getTree()));
-    }
-    else {
-      presentation.setEnabled(false);
-    }
-  }
-
-  private static ActionGroup getFixes(final QuickFixAction[] quickFixes) {
-    return new ActionGroup() {
-      @Override
-      @NotNull
-      public AnAction[] getChildren(@Nullable AnActionEvent e) {
-        List<QuickFixAction> children = new ArrayList<QuickFixAction>();
-        for (QuickFixAction fix : quickFixes) {
-          if (fix != null) {
-            children.add(fix);
-          }
-        }
-        return children.toArray(new AnAction[children.size()]);
-      }
-    };
+    presentation.setEnabled(provider.hasQuickFixes(myView.getTree()));
   }
 
   @Override
   public void actionPerformed(AnActionEvent e) {
-    InspectionToolWrapper toolWrapper = myView.getTree().getSelectedToolWrapper(true);
-    assert toolWrapper != null;
-    final QuickFixAction[] quickFixes = myView.getProvider().getQuickFixes(toolWrapper, myView.getTree());
-    if (quickFixes == null || quickFixes.length == 0) {
-      Messages.showInfoMessage(myView, "There are no applicable quickfixes", "Nothing found to fix");
+    final ActionGroup fixes = (ActionGroup)ActionManager.getInstance().getAction("QuickFixes");
+    if (fixes.getChildren(e).length == 0) {
+      Messages.showInfoMessage(myView, "There are no applicable quick fixes", "Nothing Found to Fix");
       return;
     }
-    ActionGroup fixes = getFixes(quickFixes);
     DataContext dataContext = e.getDataContext();
-    final ListPopup popup = JBPopupFactory.getInstance()
-      .createActionGroupPopup(InspectionsBundle.message("inspection.tree.popup.title"),
+    final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(InspectionsBundle.message("inspection.tree.popup.title"),
                               fixes,
                               dataContext,
                               JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                               false);
     InspectionResultsView.showPopup(e, popup);
   }
+
+  static boolean cantApplyFixes(InspectionResultsView view) {
+    return view.isUpdating() && !view.getTree().areDescriptorNodesSelected();
+  }
 }
index c76357cd60e5b0eeedaf76d37a11c66e0d73e2d4..05b4a760c50e2f93e4818b9100ab226eb7d97e38 100644 (file)
@@ -34,13 +34,15 @@ public class QuickFixesViewActionGroup extends ActionGroup {
   @Override
   public AnAction[] getChildren(@Nullable AnActionEvent e) {
     final InspectionResultsView view = getView(e);
-    if (view == null) {
+    if (view == null || InvokeQuickFixAction.cantApplyFixes(view)) {
       return AnAction.EMPTY_ARRAY;
     }
-    final InspectionToolWrapper wrapper = view.getTree().getSelectedToolWrapper(true);
-    if (wrapper == null) return AnAction.EMPTY_ARRAY;
-
-    final QuickFixAction[] fixes = view.getProvider().getQuickFixes(wrapper, view.getTree());
-    return fixes == null ? AnAction.EMPTY_ARRAY : fixes;
+    InspectionToolWrapper toolWrapper = view.getTree().getSelectedToolWrapper(true);
+    if (toolWrapper == null) return AnAction.EMPTY_ARRAY;
+    final QuickFixAction[] quickFixes = view.getProvider().getQuickFixes(toolWrapper, view.getTree());
+    if (quickFixes == null || quickFixes.length == 0) {
+      return AnAction.EMPTY_ARRAY;
+    }
+    return quickFixes;
   }
 }