public void reset() {
   mySelectedSchema = new CustomActionsSchema();
   mySelectedSchema.copyFrom(CustomActionsSchema.getInstance());
   patchActionsTreeCorrespondingToSchema(
       (DefaultMutableTreeNode) myActionsTree.getModel().getRoot());
   myRestoreAllDefaultButton.setEnabled(mySelectedSchema.isModified(new CustomActionsSchema()));
 }
 private void patchActionsTreeCorrespondingToSchema(DefaultMutableTreeNode root) {
   root.removeAllChildren();
   if (mySelectedSchema != null) {
     mySelectedSchema.fillActionGroups(root);
     for (final ActionUrl actionUrl : mySelectedSchema.getActions()) {
       ActionUrl.changePathInActionsTree(myActionsTree, actionUrl);
     }
   }
   ((DefaultTreeModel) myActionsTree.getModel()).reload();
 }
  protected boolean doSetIcon(
      DefaultMutableTreeNode node, @Nullable String path, Component component) {
    if (StringUtil.isNotEmpty(path) && !new File(path).isFile()) {
      Messages.showErrorDialog(
          component,
          IdeBundle.message("error.file.not.found.message", path),
          IdeBundle.message("title.choose.action.icon"));
      return false;
    }

    String actionId = getActionId(node);
    if (actionId == null) return false;

    final AnAction action = ActionManager.getInstance().getAction(actionId);
    if (action != null && action.getTemplatePresentation() != null) {
      if (StringUtil.isNotEmpty(path)) {
        Image image = null;
        try {
          image =
              ImageLoader.loadFromStream(
                  VfsUtil.convertToURL(VfsUtil.pathToUrl(path.replace(File.separatorChar, '/')))
                      .openStream());
        } catch (IOException e) {
          LOG.debug(e);
        }
        Icon icon = new File(path).exists() ? IconLoader.getIcon(image) : null;
        if (icon != null) {
          if (icon.getIconWidth() > EmptyIcon.ICON_18.getIconWidth()
              || icon.getIconHeight() > EmptyIcon.ICON_18.getIconHeight()) {
            Messages.showErrorDialog(
                component,
                IdeBundle.message("custom.icon.validation.message"),
                IdeBundle.message("title.choose.action.icon"));
            return false;
          }
          node.setUserObject(Pair.create(actionId, icon));
          mySelectedSchema.addIconCustomization(actionId, path);
        }
      } else {
        node.setUserObject(Pair.create(actionId, null));
        mySelectedSchema.removeIconCustomization(actionId);
        final DefaultMutableTreeNode nodeOnToolbar = findNodeOnToolbar(actionId);
        if (nodeOnToolbar != null) {
          editToolbarIcon(actionId, nodeOnToolbar);
          node.setUserObject(nodeOnToolbar.getUserObject());
        }
      }
      return true;
    }
    return false;
  }
 public void apply() throws ConfigurationException {
   final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myActionsTree);
   if (mySelectedSchema != null) {
     CustomizationUtil.optimizeSchema(myActionsTree, mySelectedSchema);
   }
   restorePathsAfterTreeOptimization(treePaths);
   CustomActionsSchema.getInstance().copyFrom(mySelectedSchema);
   setCustomizationSchemaForCurrentProjects();
 }
 private void editToolbarIcon(String actionId, DefaultMutableTreeNode node) {
   final AnAction anAction = ActionManager.getInstance().getAction(actionId);
   if (isToolbarAction(node)
       && anAction.getTemplatePresentation() != null
       && anAction.getTemplatePresentation().getIcon() == null) {
     final int exitCode =
         Messages.showOkCancelDialog(
             IdeBundle.message("error.adding.action.without.icon.to.toolbar"),
             IdeBundle.message("title.unable.to.add.action.without.icon.to.toolbar"),
             Messages.getInformationIcon());
     if (exitCode == Messages.OK) {
       mySelectedSchema.addIconCustomization(actionId, null);
       anAction.getTemplatePresentation().setIcon(AllIcons.Toolbar.Unknown);
       anAction.setDefaultIcon(false);
       node.setUserObject(Pair.create(actionId, AllIcons.Toolbar.Unknown));
       myActionsTree.repaint();
       setCustomizationSchemaForCurrentProjects();
     }
   }
 }
 private List<ActionUrl> findActionsUnderSelection() {
   final ArrayList<ActionUrl> actions = new ArrayList<ActionUrl>();
   final TreePath[] selectionPaths = myActionsTree.getSelectionPaths();
   if (selectionPaths != null) {
     for (TreePath path : selectionPaths) {
       final ActionUrl selectedUrl = CustomizationUtil.getActionUrl(path, ActionUrl.MOVE);
       final ArrayList<String> selectedGroupPath =
           new ArrayList<String>(selectedUrl.getGroupPath());
       final Object component = selectedUrl.getComponent();
       if (component instanceof Group) {
         selectedGroupPath.add(((Group) component).getName());
         for (ActionUrl action : mySelectedSchema.getActions()) {
           final ArrayList<String> groupPath = action.getGroupPath();
           final int idx = Collections.indexOfSubList(groupPath, selectedGroupPath);
           if (idx > -1) {
             actions.add(action);
           }
         }
       }
     }
   }
   return actions;
 }
 public boolean isModified() {
   CustomizationUtil.optimizeSchema(myActionsTree, mySelectedSchema);
   return CustomActionsSchema.getInstance().isModified(mySelectedSchema);
 }
 private void addCustomizedAction(ActionUrl url) {
   mySelectedSchema.addAction(url);
   myRestoreAllDefaultButton.setEnabled(true);
 }