IDEA-25059
authorAlexey Kudravtsev <cdr@intellij.com>
Tue, 11 May 2010 09:15:25 +0000 (13:15 +0400)
committerAlexey Kudravtsev <cdr@intellij.com>
Tue, 11 May 2010 09:19:34 +0000 (13:19 +0400)
java/java-impl/src/com/intellij/usages/impl/rules/MethodGroupingRule.java
platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java
platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java

index 09694b709f7ce942a57ef3f5137c1302414c7072..8846de62d2fb566fc54b622099f50bd1b8ed4003 100644 (file)
@@ -107,7 +107,7 @@ public class MethodGroupingRule implements UsageGroupingRule {
     }
 
     private PsiMethod getMethod() {
-      return (PsiMethod)myMethodPointer.getElement();
+      return myMethodPointer.getElement();
     }
 
     @NotNull
index 64110e91224d4bf0bb66dc3ad12085fae0593db0..f1a3c0e08dcf03ef1fa55da87c6b4b1c7dbd2560 100644 (file)
@@ -54,10 +54,7 @@ import com.intellij.ui.TableScrollingUtil;
 import com.intellij.ui.awt.RelativePoint;
 import com.intellij.usageView.UsageViewBundle;
 import com.intellij.usages.*;
-import com.intellij.usages.impl.GroupNode;
-import com.intellij.usages.impl.NullUsage;
-import com.intellij.usages.impl.UsageNode;
-import com.intellij.usages.impl.UsageViewImpl;
+import com.intellij.usages.impl.*;
 import com.intellij.usages.rules.UsageFilteringRuleProvider;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.Icons;
@@ -110,12 +107,26 @@ public class ShowUsagesAction extends AnAction {
       hideHints();
     }
   };
+  private final UsageViewSettings myUsageViewSettings;
 
   // used from plugin.xml
   @SuppressWarnings({"UnusedDeclaration"})
   public ShowUsagesAction() {
+    this(false);
+  }
+
+  private ShowUsagesAction(boolean showDialogBefore) {
     setInjectedContext(true);
-    showSettingsDialogBefore = false;
+    showSettingsDialogBefore = showDialogBefore;
+
+    final UsageViewSettings usageViewSettings = UsageViewSettings.getInstance();
+    myUsageViewSettings = new UsageViewSettings();
+    myUsageViewSettings.loadState(usageViewSettings);
+    myUsageViewSettings.GROUP_BY_FILE_STRUCTURE = false;
+    myUsageViewSettings.GROUP_BY_MODULE = false;
+    myUsageViewSettings.GROUP_BY_PACKAGE = false;
+    myUsageViewSettings.GROUP_BY_USAGE_TYPE = false;
+    myUsageViewSettings.GROUP_BY_SCOPE = false;
   }
 
   public static class ShowSettings extends ShowUsagesAction {
@@ -124,11 +135,6 @@ public class ShowUsagesAction extends AnAction {
     }
   }
 
-  private ShowUsagesAction(boolean showDialogBefore) {
-    setInjectedContext(true);
-    showSettingsDialogBefore = showDialogBefore;
-  }
-
   public void actionPerformed(AnActionEvent e) {
     final Project project = e.getData(PlatformDataKeys.PROJECT);
     if (project == null) return;
@@ -177,25 +183,18 @@ public class ShowUsagesAction extends AnAction {
     presentation.setDetachedMode(true);
 
     final UsageViewSettings usageViewSettings = UsageViewSettings.getInstance();
-    final UsageViewSettings save = new UsageViewSettings();
+    final UsageViewSettings savedGlobalSettings = new UsageViewSettings();
 
-    save.loadState(usageViewSettings);
-    usageViewSettings.GROUP_BY_FILE_STRUCTURE = false;
-    usageViewSettings.GROUP_BY_MODULE = false;
-    usageViewSettings.GROUP_BY_PACKAGE = false;
-    usageViewSettings.GROUP_BY_USAGE_TYPE = false;
-    usageViewSettings.GROUP_BY_SCOPE = false;
+    savedGlobalSettings.loadState(usageViewSettings);
+    usageViewSettings.loadState(myUsageViewSettings);
 
     UsageViewManager manager = UsageViewManager.getInstance(handler.getProject());
     final UsageViewImpl usageView = (UsageViewImpl)manager.createUsageView(UsageTarget.EMPTY_ARRAY, Usage.EMPTY_ARRAY, presentation, null);
 
     Disposer.register(usageView, new Disposable() {
       public void dispose() {
-        usageViewSettings.GROUP_BY_FILE_STRUCTURE = save.GROUP_BY_FILE_STRUCTURE;
-        usageViewSettings.GROUP_BY_MODULE = save.GROUP_BY_MODULE;
-        usageViewSettings.GROUP_BY_PACKAGE = save.GROUP_BY_PACKAGE;
-        usageViewSettings.GROUP_BY_USAGE_TYPE = save.GROUP_BY_USAGE_TYPE;
-        usageViewSettings.GROUP_BY_SCOPE = save.GROUP_BY_SCOPE;
+        myUsageViewSettings.loadState(usageViewSettings);
+        usageViewSettings.loadState(savedGlobalSettings);
       }
     });
 
@@ -431,10 +430,11 @@ public class ShowUsagesAction extends AnAction {
     });
     builder.setCommandButton(button);
 
-    DefaultActionGroup filters = new DefaultActionGroup();
-    usageView.addFilteringActions(filters);
+    DefaultActionGroup toolbar = new DefaultActionGroup();
+    usageView.addFilteringActions(toolbar);
 
-    filters.add(new AnAction("Open Find Usages Toolwindow", "Show all usages in a separate toolwindow", IconLoader.getIcon("/general/toolWindowFind.png")) {
+    toolbar.add(UsageGroupingRuleProviderImpl.createGroupByFileStructureAction(usageView));
+    toolbar.add(new AnAction("Open Find Usages Toolwindow", "Show all usages in a separate toolwindow", IconLoader.getIcon("/general/toolWindowFind.png")) {
       {
         AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_USAGES);
         setShortcutSet(action.getShortcutSet());
@@ -453,14 +453,14 @@ public class ShowUsagesAction extends AnAction {
       }
     });
 
-    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, filters, true);
+    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, toolbar, true);
     actionToolbar.setReservePlaceAutoPopupIcon(false);
     final JComponent toolBar = actionToolbar.getComponent();
     toolBar.setOpaque(false);
     builder.setSettingButton(toolBar);
 
     popup[0] = builder.createPopup();
-    for (AnAction action : filters.getChildren(null)) {
+    for (AnAction action : toolbar.getChildren(null)) {
       action.unregisterCustomShortcutSet(usageView.getComponent());
       action.registerCustomShortcutSet(action.getShortcutSet(), popup[0].getContent());
     }
index 4bdf2de706b3f7ecffce308054f9e189a83005fb..840c905822fa906262cc5bd38297421a2dbcbc1b 100644 (file)
@@ -80,14 +80,10 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider
     final GroupByModuleTypeAction groupByModuleTypeAction = new GroupByModuleTypeAction(impl);
     groupByModuleTypeAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK)), component);
 
-    final GroupByFileStructureAction groupByFileStructureAction = new GroupByFileStructureAction(impl);
-    groupByFileStructureAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_M,
-                                                                                                      InputEvent.CTRL_DOWN_MASK)), component);
-
+    final GroupByFileStructureAction groupByFileStructureAction = createGroupByFileStructureAction(impl);
     impl.scheduleDisposeOnClose(new Disposable() {
       public void dispose() {
         groupByModuleTypeAction.unregisterCustomShortcutSet(component);
-        groupByFileStructureAction.unregisterCustomShortcutSet(component);
       }
     });
 
@@ -123,6 +119,20 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider
     }
   }
 
+  public static GroupByFileStructureAction createGroupByFileStructureAction(UsageViewImpl impl) {
+    final JComponent component = impl.getComponent();
+    final GroupByFileStructureAction groupByFileStructureAction = new GroupByFileStructureAction(impl);
+    groupByFileStructureAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_M,
+                                                                                                      InputEvent.CTRL_DOWN_MASK)), component);
+
+    impl.scheduleDisposeOnClose(new Disposable() {
+      public void dispose() {
+        groupByFileStructureAction.unregisterCustomShortcutSet(component);
+      }
+    });
+    return groupByFileStructureAction;
+  }
+
   private static class GroupByUsageTypeAction extends RuleAction {
     private GroupByUsageTypeAction(UsageViewImpl view) {
       super(view, UsageViewBundle.message("action.group.by.usage.type"), IconLoader.getIcon("/ant/filter.png")); //TODO: special icon