diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructureDialog.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructureDialog.java index f5af13c4b2ef..71348ce78e38 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructureDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructureDialog.java @@ -97,6 +97,7 @@ public class FileStructureDialog extends DialogWrapper { if (applySortAndFilter) { myTreeActionsOwner = new TreeStructureActionsOwner(myBaseTreeModel); myTreeModel = new TreeModelWrapper(structureViewModel, myTreeActionsOwner); + myTreeActionsOwner.setActionIncluded(Sorter.ALPHA_SORTER, true); } else { myTreeActionsOwner = null; diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java index 5d8065567632..ecd127977fb8 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java @@ -24,6 +24,7 @@ import com.intellij.ide.structureView.ModelListener; import com.intellij.ide.structureView.StructureView; import com.intellij.ide.structureView.StructureViewModel; import com.intellij.ide.structureView.impl.common.PsiTreeElementBase; +import com.intellij.ide.structureView.newStructureView.TreeActionWrapper; import com.intellij.ide.structureView.newStructureView.TreeActionsOwner; import com.intellij.ide.structureView.newStructureView.TreeModelWrapper; import com.intellij.ide.util.treeView.AbstractTreeNode; @@ -166,6 +167,7 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { IdeFocusManager.getInstance(myProject).typeAheadUntil(myTreeHasBuilt, "FileStructurePopup"); myTreeActionsOwner = new TreeStructureActionsOwner(myTreeModel); + myTreeActionsOwner.setActionIncluded(Sorter.ALPHA_SORTER, true); myTreeModelWrapper = new TreeModelWrapper(myTreeModel, myTreeActionsOwner); myTreeStructure = new SmartTreeStructure(project, myTreeModelWrapper) { @@ -688,11 +690,16 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { label.setBorder(JBUI.Borders.empty(0, 2)); label.setHorizontalAlignment(SwingConstants.RIGHT); label.setVerticalAlignment(SwingConstants.CENTER); + + List sorters = createSorters(); new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent event, int clickCount) { DefaultActionGroup group = new DefaultActionGroup(); - //addSorters(group); + if (!sorters.isEmpty()) { + group.addAll(sorters); + group.addSeparator(); + } //addGroupers(group); //addFilters(group); @@ -728,6 +735,44 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { return label; } + protected List createSorters() { + List actions = new ArrayList<>(); + for (Sorter sorter : myTreeModel.getSorters()) { + if (sorter.isVisible()) { + actions.add(new MyTreeActionWrapper(sorter)); + } + } + return actions; + } + + private class MyTreeActionWrapper extends TreeActionWrapper { + private final TreeAction myAction; + + public MyTreeActionWrapper(TreeAction action) { + super(action, myTreeActionsOwner); + myAction = action; + myTreeActionsOwner.setActionIncluded(action, getDefaultValue(action)); + } + + @Override + public void update(AnActionEvent e) { + super.update(e); + e.getPresentation().setIcon(null); + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + boolean actionState = TreeModelWrapper.shouldRevert(myAction) ? !state : state; + myTreeActionsOwner.setActionIncluded(myAction, actionState); + saveState(myAction, state); + rebuild(false).processed(ignore -> { + if (mySpeedSearch.isPopupActive()) { + mySpeedSearch.refreshSelection(); + } + }); + } + } + @Nullable private AbstractTreeNode getSelectedNode() { TreePath path = myTree.getSelectionPath(); @@ -866,19 +911,13 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { } private static boolean getDefaultValue(TreeAction action) { - if (action instanceof PropertyOwner) { - String propertyName = ((PropertyOwner)action).getPropertyName(); - return PropertiesComponent.getInstance().getBoolean(TreeStructureUtil.getPropertyName(propertyName)); - } - - return false; + String propertyName = action instanceof PropertyOwner ? ((PropertyOwner)action).getPropertyName() : action.getName(); + return PropertiesComponent.getInstance().getBoolean(TreeStructureUtil.getPropertyName(propertyName)); } private static void saveState(TreeAction action, boolean state) { - if (action instanceof PropertyOwner) { - String propertyName = ((PropertyOwner)action).getPropertyName(); - PropertiesComponent.getInstance().setValue(TreeStructureUtil.getPropertyName(propertyName), state); - } + String propertyName = action instanceof PropertyOwner ? ((PropertyOwner)action).getPropertyName() : action.getName(); + PropertiesComponent.getInstance().setValue(TreeStructureUtil.getPropertyName(propertyName), state); } public void setTitle(String title) { diff --git a/platform/lang-impl/src/com/intellij/ide/util/TreeStructureActionsOwner.java b/platform/lang-impl/src/com/intellij/ide/util/TreeStructureActionsOwner.java index 2dc9288d9a94..34513c630f3f 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/TreeStructureActionsOwner.java +++ b/platform/lang-impl/src/com/intellij/ide/util/TreeStructureActionsOwner.java @@ -48,7 +48,7 @@ class TreeStructureActionsOwner implements TreeActionsOwner { for(TreeAction action: myActions) { if (action.getName().equals(name)) return true; } - return Sorter.ALPHA_SORTER_ID.equals(name); + return false; } public void setActionIncluded(final TreeAction filter, final boolean selected) {