From 4439ea74e97409b836fb39a2ccccde31a1637636 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 18 Jan 2017 08:56:06 +0300 Subject: [PATCH] project structure dialog: added action to flatten modules tree (IDEA-166061) --- .../ModuleStructureConfigurable.java | 82 ++++++++++++------ .../src/objectBrowser/flattenModules.png | Bin 0 -> 366 bytes .../src/objectBrowser/flattenModules@2x.png | Bin 0 -> 667 bytes .../src/messages/ProjectBundle.properties | 2 + .../util/src/com/intellij/icons/AllIcons.java | 1 + 5 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 platform/icons/src/objectBrowser/flattenModules.png create mode 100644 platform/icons/src/objectBrowser/flattenModules@2x.png diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index edf8c45edb29..1197d856b2ce 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -101,6 +101,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple }; private boolean myHideModuleGroups; + private boolean myFlattenModules; private final ModuleManager myModuleManager; @@ -148,6 +149,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple final ArrayList result = super.createActions(fromPopup); if (fromPopup) { result.add(Separator.getInstance()); + result.add(new FlattenModulesAction()); result.add(new HideGroupsAction()); addCollapseExpandActions(result); } @@ -227,7 +229,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple if (nodesAdded) { myTree.setShowsRootHandles(true); } - final List groupPath = myHideModuleGroups ? Collections.emptyList() : moduleGrouper.getGroupPath(module); + final List groupPath = myHideModuleGroups || myFlattenModules ? Collections.emptyList() : moduleGrouper.getGroupPath(module); if (groupPath.isEmpty()) { myRoot.add(moduleNode); } @@ -286,7 +288,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple nodes[i ++] = node; } for (final MyNode moduleNode : nodes) { - List groupPath = myHideModuleGroups + List groupPath = myHideModuleGroups || myFlattenModules ? Collections.emptyList() : group != null ? group.getGroupPathList() : Collections.emptyList(); if (groupPath.isEmpty()) { @@ -638,7 +640,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple @NotNull @Override public String getDisplayName() { - return myGrouper.getPresentableName(getModule()); + return myFlattenModules ? getModule().getName() : myGrouper.getPresentableName(getModule()); } private Module getModule() { @@ -766,6 +768,28 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple } } + private class FlattenModulesAction extends ToggleAction implements DumbAware { + public FlattenModulesAction() { + super(ProjectBundle.message("project.roots.flatten.modules.action.text"), ProjectBundle.message("project.roots.flatten.modules.action.description"), AllIcons.ObjectBrowser.FlattenModules); + } + + @Override + public void update(@NotNull AnActionEvent e) { + super.update(e); + e.getPresentation().setEnabledAndVisible(ModuleGrouperKt.isQualifiedModuleGroupsEnabled() && !myContext.getModulesConfigurator().getModuleModel().hasModuleGroups()); + } + + @Override + public boolean isSelected(AnActionEvent e) { + return myFlattenModules; + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + myFlattenModules = state; + regroupModules(myFlattenModules); + } + } private class HideGroupsAction extends ToggleAction implements DumbAware { @@ -795,33 +819,37 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple @Override public void setSelected(AnActionEvent e, boolean state) { myHideModuleGroups = state; - DefaultMutableTreeNode selection = null; - final TreePath selectionPath = myTree.getSelectionPath(); - if (selectionPath != null){ - selection = (DefaultMutableTreeNode)selectionPath.getLastPathComponent(); - } - ModuleGrouper grouper = getModuleGrouper(); - for (Module module : grouper.getAllModules()) { - final List groupPath = grouper.getGroupPath(module); - updateProjectTree(new Module[]{module}, !groupPath.isEmpty() ? new ModuleGroup(groupPath) : null); - } - if (state) { - removeModuleGroups(); - } - if (selection != null){ - TreeUtil.selectInTree(selection, true, myTree); - } + regroupModules(state); } + } - private void removeModuleGroups() { - for(int i = myRoot.getChildCount() - 1; i >=0; i--){ - final MyNode node = (MyNode)myRoot.getChildAt(i); - if (node.getConfigurable().getEditableObject() instanceof ModuleGroup){ - node.removeFromParent(); - } - } - ((DefaultTreeModel)myTree.getModel()).reload(myRoot); + private void regroupModules(boolean removeGroupNodes) { + DefaultMutableTreeNode selection = null; + final TreePath selectionPath = myTree.getSelectionPath(); + if (selectionPath != null) { + selection = (DefaultMutableTreeNode)selectionPath.getLastPathComponent(); } + ModuleGrouper grouper = getModuleGrouper(); + for (Module module : grouper.getAllModules()) { + final List groupPath = grouper.getGroupPath(module); + updateProjectTree(new Module[]{module}, !groupPath.isEmpty() ? new ModuleGroup(groupPath) : null); + } + if (removeGroupNodes) { + removeModuleGroups(); + } + if (selection != null) { + TreeUtil.selectInTree(selection, true, myTree); + } + } + + private void removeModuleGroups() { + for (int i = myRoot.getChildCount() - 1; i >= 0; i--) { + final MyNode node = (MyNode)myRoot.getChildAt(i); + if (node.getConfigurable().getEditableObject() instanceof ModuleGroup) { + node.removeFromParent(); + } + } + ((DefaultTreeModel)myTree.getModel()).reload(myRoot); } @Override diff --git a/platform/icons/src/objectBrowser/flattenModules.png b/platform/icons/src/objectBrowser/flattenModules.png new file mode 100644 index 0000000000000000000000000000000000000000..07dc5a65fb58604f66d01bd3b72f2050947e60da GIT binary patch literal 366 zcmV-!0g?WRP)h7UQJXh8)NX{n)Y~~j z!PYjJT|9?#ad^)AJLhEpF#o|`R8^G;jFZY~6t8DXsHO!NN33k+d1i!D05?JVE{=Y2 z3zjCLm0v|oj-i?nY|1A*Qf~u)LGMw-x3LX!qdtVCbP5T{yj_!=0w>w7wt+92fJCN; zhhQAv1Xdw|{*#EhvW)UEN09;vIuCIS^iA}%b z`W`edA}}vGR1Qhxof(SfH)h=g4S5ltHyl2cFzBA(Dez?U+Fm340A5Z$Rt9{N-~a#s M07*qoM6N<$f@K7m-2eap literal 0 HcmV?d00001 diff --git a/platform/icons/src/objectBrowser/flattenModules@2x.png b/platform/icons/src/objectBrowser/flattenModules@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..1e0963ac1a99fbc369b4c95dec931bd4b932036e GIT binary patch literal 667 zcmV;M0%ZM(P)o&_#_%CD0V3=Ek-B`?GhT`#c0G!TM}=Gts>I6Ezpa!#o9s@0;w^vv|t2# zRfC}DpY(Gku@5U#+;+QJAHJOI=A4}`XEt+oH2^efqWNzG1VKm=HV7IiM4cU|fxA%w z{6UgH>OmJ)r;H-rOd625(}|d~!=t#sw!a_c2rnWZwj$&01(hQbh&ayGM7BVA(S~2I z$3z^ijN(gd2sy!m4Yvua4~CKBQp?K~ST2MHNW1N*EL#61 zfa7R*3-ZAMd{5dzqbdTQ0+(@+7zT|h3H0OO)evY*-Qy4**RtRh6WCp_U_Z{I7`lYC z$B31?Iu^1an{;w%eyt%Ha~!vagU z+mLXzi-wA4iY_rR4@VDli1Bx`2t(dx=|qu{!J-x5xc$~Y0g}s;8lKe39>>w_Q$0%aq}8*ArVk@2q&KHKQJgb_ zMpX`?%_kg+eiLX^MIiH7hl0-t8l&Sa5XMfhP;MAyJm*mm49HFEkaD#mdi^Aex&-L2 z*_u>=_e3C11a`c7WQhd5W>A+v-86L?HXEq|zX4sAotjSX8Xo`v002ovPDHLkV1m_f BEGPf~ literal 0 HcmV?d00001 diff --git a/platform/projectModel-impl/src/messages/ProjectBundle.properties b/platform/projectModel-impl/src/messages/ProjectBundle.properties index 305748a9c824..a59f54f9823a 100644 --- a/platform/projectModel-impl/src/messages/ProjectBundle.properties +++ b/platform/projectModel-impl/src/messages/ProjectBundle.properties @@ -303,6 +303,8 @@ rename.message.prefix.scope=Scope rename.scope.title=Rename scope. rename.message.prefix.module=Module rename.module.title=Rename module +project.roots.flatten.modules.action.text=Flatten Modules +project.roots.flatten.modules.action.description=Show modules in a flat list project.roots.plain.mode.action.text.disabled=Hide Module Groups project.roots.plain.mode.action.text.enabled=Show Module Groups project.roots.tooltip.library.has.broken.paths=Library ''{0}'' has broken {1, choice, 1#path|2#paths}. diff --git a/platform/util/src/com/intellij/icons/AllIcons.java b/platform/util/src/com/intellij/icons/AllIcons.java index 6351c10ba171..55cfdf45f1e6 100644 --- a/platform/util/src/com/intellij/icons/AllIcons.java +++ b/platform/util/src/com/intellij/icons/AllIcons.java @@ -992,6 +992,7 @@ public class AllIcons { public static class ObjectBrowser { public static final Icon AbbreviatePackageNames = IconLoader.getIcon("/objectBrowser/abbreviatePackageNames.png"); // 16x16 public static final Icon CompactEmptyPackages = IconLoader.getIcon("/objectBrowser/compactEmptyPackages.png"); // 16x16 + public static final Icon FlattenModules = IconLoader.getIcon("/objectBrowser/flattenModules.png"); // 16x16 public static final Icon FlattenPackages = IconLoader.getIcon("/objectBrowser/flattenPackages.png"); // 16x16 public static final Icon ShowEditorHighlighting = IconLoader.getIcon("/objectBrowser/showEditorHighlighting.png"); // 16x16 public static final Icon ShowLibraryContents = IconLoader.getIcon("/objectBrowser/showLibraryContents.png"); // 16x16