diff --git a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.form b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.form index 5b0b02e62987..9862f7b9142b 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.form +++ b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.form @@ -1,6 +1,6 @@
- + @@ -8,17 +8,17 @@ - + - + - + - + @@ -82,12 +82,20 @@ - + - + + + + + + + + + diff --git a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java index dca05d5c1783..ab28bdf26ec8 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java @@ -29,7 +29,6 @@ import com.intellij.openapi.keymap.impl.ui.Group; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; -import com.intellij.openapi.ui.DetailsComponent; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.TextFieldWithBrowseButton; @@ -60,9 +59,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; -import java.util.HashSet; +import java.util.*; import java.util.List; -import java.util.Set; /** * User: anna @@ -90,10 +88,9 @@ public class CustomizableActionsPanel { - private JPanel myDetailsPanel; + private JButton myRestoreAllDefaultButton; private JButton myRestoreDefaultButton; public static final Icon FULLISH_ICON = IconLoader.getIcon("/toolbar/unknown.png"); - private DetailsComponent myDetailsComponent; public CustomizableActionsPanel() { @@ -144,6 +141,7 @@ public class CustomizableActionsPanel { } myMoveActionUpButton.setEnabled(isMoveSupported(myActionsTree, -1)); myMoveActionDownButton.setEnabled(isMoveSupported(myActionsTree, 1)); + myRestoreDefaultButton.setEnabled(!findActionsUnderSelection().isEmpty()); } }); @@ -178,7 +176,7 @@ public class CustomizableActionsPanel { myEditIconButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - myRestoreDefaultButton.setEnabled(true); + myRestoreAllDefaultButton.setEnabled(true); final List expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree); final TreePath selectionPath = myActionsTree.getLeadSelectionPath(); if (selectionPath != null) { @@ -270,10 +268,25 @@ public class CustomizableActionsPanel { } }); - myRestoreDefaultButton.addActionListener(new ActionListener() { + myRestoreAllDefaultButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mySelectedSchema.copyFrom(new CustomActionsSchema()); patchActionsTreeCorrespondingToSchema(root); + myRestoreAllDefaultButton.setEnabled(false); + } + }); + + myRestoreDefaultButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final List otherActions = new ArrayList(mySelectedSchema.getActions()); + otherActions.removeAll(findActionsUnderSelection()); + mySelectedSchema.copyFrom(new CustomActionsSchema()); + for (ActionUrl otherAction : otherActions) { + mySelectedSchema.addAction(otherAction); + } + final List treePaths = TreeUtil.collectExpandedPaths(myActionsTree); + patchActionsTreeCorrespondingToSchema(root); + restorePathsAfterTreeOptimization(treePaths); myRestoreDefaultButton.setEnabled(false); } }); @@ -283,18 +296,32 @@ public class CustomizableActionsPanel { myTreeExpansionMonitor = TreeExpansionMonitor.install(myActionsTree); } + private List findActionsUnderSelection() { + final ArrayList actions = new ArrayList(); + final TreePath[] selectionPaths = myActionsTree.getSelectionPaths(); + if (selectionPaths != null) { + for (TreePath path : selectionPaths) { + final ActionUrl selectedUrl = CustomizationUtil.getActionUrl(path, ActionUrl.MOVE); + final ArrayList selectedGroupPath = new ArrayList(selectedUrl.getGroupPath()); + final Object component = selectedUrl.getComponent(); + if (component instanceof Group) { + selectedGroupPath.add(((Group)component).getName()); + for (ActionUrl action : mySelectedSchema.getActions()) { + final ArrayList groupPath = action.getGroupPath(); + final int idx = Collections.indexOfSubList(groupPath, selectedGroupPath); + if (idx > -1) { + actions.add(action); + } + } + } + } + } + return actions; + } + private void addCustomizedAction(ActionUrl url) { mySelectedSchema.addAction(url); - myRestoreDefaultButton.setEnabled(true); - } - - public void initUi() { - myDetailsComponent = new DetailsComponent(); - myDetailsComponent.setContent(myDetailsPanel); - } - - public DetailsComponent getDetails() { - return myDetailsComponent; + myRestoreAllDefaultButton.setEnabled(true); } private void editToolbarIcon(String actionId, DefaultMutableTreeNode node) { @@ -401,7 +428,7 @@ public class CustomizableActionsPanel { mySelectedSchema = new CustomActionsSchema(); mySelectedSchema.copyFrom(CustomActionsSchema.getInstance()); patchActionsTreeCorrespondingToSchema((DefaultMutableTreeNode)myActionsTree.getModel().getRoot()); - myRestoreDefaultButton.setEnabled(mySelectedSchema.isModified(new CustomActionsSchema())); + myRestoreAllDefaultButton.setEnabled(mySelectedSchema.isModified(new CustomActionsSchema())); } public boolean isModified() {