inspection toolwindow: add ability to rerun inspection from its settings
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Mon, 6 Jun 2016 11:47:26 +0000 (14:47 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Mon, 6 Jun 2016 11:47:26 +0000 (14:47 +0300)
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java
platform/lang-impl/src/com/intellij/codeInspection/ui/actions/EditSettingsAction.java

index d06d1dcc19358b9e95d19fa0722bbc06f541d068..37551da827a4976f6df03949a2edb357ae115026 100644 (file)
@@ -1032,7 +1032,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
 
     @Override
     public void update(AnActionEvent e) {
-      e.getPresentation().setEnabled(!(myProvider instanceof OfflineInspectionRVContentProvider) && myScope.isValid());
+      e.getPresentation().setEnabled(isRerunAvailable());
     }
 
     @Override
@@ -1041,12 +1041,20 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
     }
 
     private void rerun() {
-      myRerun = true;
-      if (myScope.isValid()) {
-        AnalysisUIOptions.getInstance(myProject).save(myGlobalInspectionContext.getUIOptions());
-        myGlobalInspectionContext.setTreeState(getTree().getTreeState());
-        myGlobalInspectionContext.doInspections(myScope);
-      }
+      InspectionResultsView.this.rerun();
+    }
+  }
+
+  public boolean isRerunAvailable() {
+    return !(myProvider instanceof OfflineInspectionRVContentProvider) && myScope.isValid();
+  }
+
+  public void rerun() {
+    myRerun = true;
+    if (myScope.isValid()) {
+      AnalysisUIOptions.getInstance(myProject).save(myGlobalInspectionContext.getUIOptions());
+      myGlobalInspectionContext.setTreeState(getTree().getTreeState());
+      myGlobalInspectionContext.doInspections(myScope);
     }
   }
 }
index 25acc529424d3c2eca291f2131d6470678a34ed7..87e459aae522f62a91551c5a645ea25fd124879b 100644 (file)
@@ -24,14 +24,12 @@ import com.intellij.codeInspection.ex.InspectionToolWrapper;
 import com.intellij.codeInspection.ui.InspectionResultsView;
 import com.intellij.icons.AllIcons;
 import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.ui.DialogBuilder;
+import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
-import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
-import com.intellij.ui.docking.DockContainer;
-import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
+import java.awt.event.ActionEvent;
 
 /**
  * @author Dmitry Batkovich
@@ -52,10 +50,26 @@ public class EditSettingsAction extends InspectionViewActionBase {
       InspectionToolWrapper tool = inspectionProfile.getInspectionTool(inspectionProfile.getSingleTool(), view.getProject());
       JComponent panel = tool.getTool().createOptionsPanel();
       if (panel != null) {
-        new DialogBuilder()
+        final DialogBuilder builder = new DialogBuilder()
           .title(InspectionsBundle.message("inspection.tool.window.inspection.dialog.title", tool.getDisplayName()))
-          .centerPanel(panel)
-          .show();
+          .centerPanel(panel);
+        builder.removeAllActions();
+        builder.addOkAction();
+        if (view.isRerunAvailable()) {
+          builder.addActionDescriptor(new DialogBuilder.DialogActionDescriptor(InspectionsBundle.message("inspection.action.rerun"), 'R') {
+            @Override
+            protected Action createAction(DialogWrapper dialogWrapper) {
+              return new AbstractAction() {
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                  view.rerun();
+                  dialogWrapper.close(DialogWrapper.OK_EXIT_CODE);
+                }
+              };
+            }
+          });
+        }
+        builder.show();
       } else {
         Messages.showInfoMessage(view.getProject(),
                                  InspectionsBundle.message("inspection.tool.window.dialog.no.options", tool.getDisplayName()),