From 826918b04d20dde8eb1022b34d098b009c8ae7b8 Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Fri, 8 Mar 2019 00:26:53 +0300 Subject: [PATCH] IDEA-182876 Remove group rarely used icons from Find Usages tool window toolbar --- .../impl/UsageViewContentManagerImpl.java | 49 ++++++++-- .../src/messages/UsageView.properties | 12 ++- .../src/idea/LangActions.xml | 2 + .../impl/SortMembersAlphabeticallyAction.java | 27 ------ .../impl/UsageGroupingRuleProviderImpl.java | 2 +- .../intellij/usages/impl/UsageViewImpl.java | 93 ++++++++----------- 6 files changed, 91 insertions(+), 94 deletions(-) delete mode 100644 platform/usageView/src/com/intellij/usages/impl/SortMembersAlphabeticallyAction.java diff --git a/platform/lang-impl/src/com/intellij/usageView/impl/UsageViewContentManagerImpl.java b/platform/lang-impl/src/com/intellij/usageView/impl/UsageViewContentManagerImpl.java index c3205f7cdc32..9b2c9007d0f3 100644 --- a/platform/lang-impl/src/com/intellij/usageView/impl/UsageViewContentManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/usageView/impl/UsageViewContentManagerImpl.java @@ -5,6 +5,7 @@ package com.intellij.usageView.impl; import com.intellij.find.FindBundle; import com.intellij.find.FindSettings; import com.intellij.icons.AllIcons; +import com.intellij.ide.IdeBundle; import com.intellij.ide.impl.ContentManagerWatcher; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; @@ -16,10 +17,14 @@ import com.intellij.openapi.wm.ToolWindowAnchor; import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.openapi.wm.ex.ToolWindowEx; +import com.intellij.ui.UIBundle; import com.intellij.ui.content.*; +import com.intellij.usageView.UsageViewBundle; import com.intellij.usageView.UsageViewContentManager; import com.intellij.usages.UsageView; +import com.intellij.usages.UsageViewSettings; import com.intellij.usages.impl.UsageViewImpl; +import com.intellij.usages.rules.UsageFilteringRuleProvider; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -33,23 +38,55 @@ public class UsageViewContentManagerImpl extends UsageViewContentManager { private final Key NEW_USAGE_VIEW_KEY = Key.create("NEW_USAGE_VIEW_KEY"); private final ContentManager myFindContentManager; - public UsageViewContentManagerImpl(final Project project, final ToolWindowManager toolWindowManager) { + public UsageViewContentManagerImpl(@NotNull final Project project, final ToolWindowManager toolWindowManager) { ToolWindow toolWindow = toolWindowManager.registerToolWindow(ToolWindowId.FIND, true, ToolWindowAnchor.BOTTOM, project, true); toolWindow.setHelpId(UsageViewImpl.HELP_ID); toolWindow.setToHideOnEmptyContent(true); toolWindow.setIcon(AllIcons.Toolwindows.ToolWindowFind); - ((ToolWindowEx)toolWindow) - .setAdditionalGearActions(new DefaultActionGroup(new DumbAwareToggleAction(FindBundle.message("find.open.in.new.tab.title.action")) { + + DumbAwareToggleAction toggleNewTabAction = new DumbAwareToggleAction(FindBundle.message("find.open.in.new.tab.title.action")) { + @Override + public boolean isSelected(@NotNull AnActionEvent e) { + return FindSettings.getInstance().isShowResultsInSeparateView(); + } + + @Override + public void setSelected(@NotNull AnActionEvent e, boolean state) { + FindSettings.getInstance().setShowResultsInSeparateView(state); + } + }; + + DumbAwareToggleAction toggleSortAction = + new DumbAwareToggleAction(UsageViewBundle.message("sort.alphabetically.action.text"), null, AllIcons.ObjectBrowser.Sorted) { @Override public boolean isSelected(@NotNull AnActionEvent e) { - return FindSettings.getInstance().isShowResultsInSeparateView(); + return UsageViewSettings.getInstance().isSortAlphabetically(); } @Override public void setSelected(@NotNull AnActionEvent e, boolean state) { - FindSettings.getInstance().setShowResultsInSeparateView(state); + UsageViewSettings.getInstance().setSortAlphabetically(state); + project.getMessageBus().syncPublisher(UsageFilteringRuleProvider.RULES_CHANGED).run(); } - })); + }; + + DumbAwareToggleAction toggleAutoscrollAction = new DumbAwareToggleAction(UIBundle.message("autoscroll.to.source.action.name"), + UIBundle.message("autoscroll.to.source.action.description"), + AllIcons.General.AutoscrollToSource) { + @Override + public boolean isSelected(@NotNull AnActionEvent e) { + return UsageViewSettings.getInstance().isAutoScrollToSource(); + } + + @Override + public void setSelected(@NotNull AnActionEvent e, boolean state) { + UsageViewSettings.getInstance().setAutoScrollToSource(state); + } + }; + + DefaultActionGroup gearActions = new DefaultActionGroup(IdeBundle.message("group.view.options"), true); + gearActions.addAll(toggleAutoscrollAction, toggleSortAction, toggleNewTabAction); + ((ToolWindowEx)toolWindow).setAdditionalGearActions(gearActions); myFindContentManager = toolWindow.getContentManager(); myFindContentManager.addContentManagerListener(new ContentManagerAdapter() { diff --git a/platform/platform-resources-en/src/messages/UsageView.properties b/platform/platform-resources-en/src/messages/UsageView.properties index 07fe1ed97cb8..37957cb9b376 100644 --- a/platform/platform-resources-en/src/messages/UsageView.properties +++ b/platform/platform-resources-en/src/messages/UsageView.properties @@ -8,11 +8,13 @@ usages.n={0,choice, 0#no usages|1#1 usage|2#{0,number} usages} found action.show.import.statements=Show import statements action.show.read.access=Show read access action.show.write.access=Show write access -action.group.by.file.structure=Group by file structure -action.group.by.usage.type=Group by usage type -action.group.by.module=Group by module -action.flatten.modules=Flatten modules -action.group.by.package=Group by package +action.group.by.prefix=Group by +action.group.by.file.structure=File Structure +action.group.by.usage.type=Usage Type +action.group.by.module=Module +action.group.by.test.production=Test/Production +action.flatten.modules=Flatten Modules +action.group.by.package=Package action.close=Close usage.view.cancel.button=&Cancel action.merge.same.line=Merge usages from the same line diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index 354b805abd09..de424fd5df5d 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -686,6 +686,8 @@ + + diff --git a/platform/usageView/src/com/intellij/usages/impl/SortMembersAlphabeticallyAction.java b/platform/usageView/src/com/intellij/usages/impl/SortMembersAlphabeticallyAction.java deleted file mode 100644 index 9cb8854e9c00..000000000000 --- a/platform/usageView/src/com/intellij/usages/impl/SortMembersAlphabeticallyAction.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ -package com.intellij.usages.impl; - -import com.intellij.icons.AllIcons; -import com.intellij.usageView.UsageViewBundle; -import org.jetbrains.annotations.NotNull; - -/** -* @author cdr -*/ -class SortMembersAlphabeticallyAction extends RuleAction { - SortMembersAlphabeticallyAction(@NotNull UsageViewImpl usageView) { - super(usageView, UsageViewBundle.message("sort.alphabetically.action.text"), AllIcons.ObjectBrowser.Sorted); - } - - @Override - protected boolean getOptionValue() { - return myView.getUsageViewSettings().isSortAlphabetically(); - } - - @Override - protected void setOptionValue(final boolean value) { - myView.getUsageViewSettings().setSortAlphabetically(value); - } -} diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java index 31faf40ac8ec..229756b6bd55 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageGroupingRuleProviderImpl.java @@ -142,7 +142,7 @@ public class UsageGroupingRuleProviderImpl implements UsageGroupingRuleProvider private static class GroupByScopeAction extends RuleAction { private GroupByScopeAction(UsageViewImpl view) { - super(view, "Group by test/production", AllIcons.Actions.GroupByTestProduction); + super(view, UsageViewBundle.message("action.group.by.test.production"), AllIcons.Actions.GroupByTestProduction); } @Override protected boolean getOptionValue() { diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index e77e89b5e1e8..9629678a9aaf 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -232,10 +232,7 @@ public class UsageViewImpl implements UsageViewEx { SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(false, true); myRootPanel.add(toolWindowPanel, BorderLayout.CENTER); - JPanel toolbarPanel = new JPanel(new BorderLayout()); - toolbarPanel.add(createActionsToolbar(), BorderLayout.WEST); - toolbarPanel.add(createFiltersToolbar(), BorderLayout.CENTER); - toolWindowPanel.setToolbar(toolbarPanel); + toolWindowPanel.setToolbar(createActionsToolbar()); myCentralPanel = new JPanel(new BorderLayout()); setupCentralPanel(); @@ -756,27 +753,12 @@ public class UsageViewImpl implements UsageViewEx { return true; } - @NotNull - private JComponent createFiltersToolbar() { - ApplicationManager.getApplication().assertIsDispatchThread(); - final DefaultActionGroup group = new DefaultActionGroup(); - - final AnAction[] groupingActions = createGroupingActions(); - for (AnAction groupingAction : groupingActions) { - group.add(groupingAction); - } - - addFilteringActions(group); - if (isPreviewUsageActionEnabled()) { - group.add(new PreviewUsageAction(this)); - } - - group.add(new SortMembersAlphabeticallyAction(this)); - return toUsageViewToolbar(group); - } - public void addFilteringActions(@NotNull DefaultActionGroup group) { ApplicationManager.getApplication().assertIsDispatchThread(); + addFilteringActions(group, true); + } + + private void addFilteringActions(@NotNull DefaultActionGroup group, boolean includeExtensionPoints) { if (getPresentation().isMergeDupLinesAvailable()) { final MergeDupLines mergeDupLines = new MergeDupLines(); final JComponent component = myRootPanel; @@ -785,7 +767,12 @@ public class UsageViewImpl implements UsageViewEx { } group.add(mergeDupLines); } + if (includeExtensionPoints) { + addFilteringFromExtensionPoints(group); + } + } + private void addFilteringFromExtensionPoints(@NotNull DefaultActionGroup group) { for (UsageFilteringRuleProvider provider : UsageFilteringRuleProvider.EP_NAME.getExtensionList()) { AnAction[] actions = provider.createFilteringActions(this); for (AnAction action : actions) { @@ -833,18 +820,33 @@ public class UsageViewImpl implements UsageViewEx { collapseAllAction.unregisterCustomShortcutSet(component); }); + DefaultActionGroup group = new DefaultActionGroup(); + group.setPopup(true); + group.getTemplatePresentation().setIcon(AllIcons.Actions.GroupBy); + final AnAction[] groupingActions = createGroupingActions(); + if (groupingActions.length > 0) { + group.add(new Separator(UsageViewBundle.message("action.group.by.prefix")));//todo use message bundle instead + group.addAll(groupingActions); + group.add(new Separator()); + } + + addFilteringActions(group, false); + DefaultActionGroup filteringSubgroup = new DefaultActionGroup(); + addFilteringFromExtensionPoints(filteringSubgroup); return new AnAction[] { - canShowSettings() ? showSettings() : null, ActionManager.getInstance().getAction("UsageView.Rerun"), - ActionManager.getInstance().getAction(IdeActions.ACTION_PIN_ACTIVE_TAB), - createRecentFindUsagesAction(), - expandAllAction, - collapseAllAction, actionsManager.createPrevOccurenceAction(myRootPanel), actionsManager.createNextOccurenceAction(myRootPanel), - actionsManager.installAutoscrollToSourceHandler(myProject, myTree, new MyAutoScrollToSourceOptionProvider(getUsageViewSettings())), - actionsManager.createExportToTextFileAction(myTextFileExporter) + new Separator(), + group, + filteringSubgroup, + expandAllAction, + collapseAllAction, + new Separator(), + isPreviewUsageActionEnabled() ? new PreviewUsageAction(this) : null, + new Separator(), + canShowSettings() ? showSettings() : null, }; } @@ -902,13 +904,6 @@ public class UsageViewImpl implements UsageViewEx { return configurableUsageTarget; } - @NotNull - private AnAction createRecentFindUsagesAction() { - AnAction action = ActionManager.getInstance().getAction(SHOW_RECENT_FIND_USAGES_ACTION_ID); - action.registerCustomShortcutSet(action.getShortcutSet(), getComponent()); - return action; - } - @NotNull private AnAction[] createGroupingActions() { final List providers = UsageGroupingRuleProvider.EP_NAME.getExtensionList(); @@ -916,6 +911,12 @@ public class UsageViewImpl implements UsageViewEx { for (UsageGroupingRuleProvider provider : providers) { ContainerUtil.addAll(list, provider.createGroupingActions(this)); } + list.sort(new Comparator() { + @Override + public int compare(AnAction o1, AnAction o2) { + return Comparing.compare(o1.getTemplateText(), o2.getTemplateText()); + } + }); return list.toArray(AnAction.EMPTY_ARRAY); } @@ -1961,24 +1962,6 @@ public class UsageViewImpl implements UsageViewEx { } } - private static class MyAutoScrollToSourceOptionProvider implements AutoScrollToSourceOptionProvider { - @NotNull private final UsageViewSettings myUsageViewSettings; - - MyAutoScrollToSourceOptionProvider(@NotNull UsageViewSettings usageViewSettings) { - myUsageViewSettings = usageViewSettings; - } - - @Override - public boolean isAutoScrollMode() { - return myUsageViewSettings.isAutoScrollToSource(); - } - - @Override - public void setAutoScrollMode(boolean state) { - myUsageViewSettings.setAutoScrollToSource(state); - } - } - private final class ButtonPanel extends JPanel { private ButtonPanel() { setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0));