private void calcMaxIconSize(final ActionGroup actionGroup) {
      AnAction[] actions = actionGroup.getChildren(createActionEvent(actionGroup));
      for (AnAction action : actions) {
        if (action == null) continue;
        if (action instanceof ActionGroup) {
          final ActionGroup group = (ActionGroup) action;
          if (!group.isPopup()) {
            calcMaxIconSize(group);
            continue;
          }
        }

        Icon icon = action.getTemplatePresentation().getIcon();
        if (icon == null && action instanceof Toggleable) icon = PlatformIcons.CHECK_ICON;
        if (icon != null) {
          final int width = icon.getIconWidth();
          final int height = icon.getIconHeight();
          if (myMaxIconWidth < width) {
            myMaxIconWidth = width;
          }
          if (myMaxIconHeight < height) {
            myMaxIconHeight = height;
          }
        }
      }
    }
Пример #2
0
 public MyActionGroupWrapper(final ActionGroup actionGroup) {
   super(
       actionGroup.getTemplatePresentation().getText(),
       actionGroup.getTemplatePresentation().getDescription(),
       actionGroup.getTemplatePresentation().getIcon());
   myActionGroup = actionGroup;
   registerCustomShortcutSet(actionGroup.getShortcutSet(), myTree);
 }
 public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) {
   ActionGroup group =
       ((ActionGroup)
           ActionManager.getInstance()
               .getAction("jetbrains.mps.ide.editor.actions.GenerationActions_ActionGroup"));
   group.update(event);
   return group.getChildren(event).length != 0;
 }
Пример #4
0
  protected void addExtraPopupMenuActions(DefaultActionGroup group) {
    group.add(new ExcludeFromCompileAction(myProject, this));

    ActionGroup popupGroup =
        (ActionGroup)
            ActionManager.getInstance().getAction(IdeActions.GROUP_COMPILER_ERROR_VIEW_POPUP);
    if (popupGroup != null) {
      for (AnAction action : popupGroup.getChildren(null)) {
        group.add(action);
      }
    }
  }
  protected void buildToolbar(@Nullable List<AnAction> viewerActions) {
    ActionGroup group = collectToolbarActions(viewerActions);
    ActionToolbar toolbar =
        ActionManager.getInstance().createActionToolbar(ActionPlaces.DIFF_TOOLBAR, group, true);

    DataManager.registerDataProvider(toolbar.getComponent(), myMainPanel);
    toolbar.setTargetComponent(toolbar.getComponent());

    myToolbarPanel.setContent(toolbar.getComponent());
    for (AnAction action : group.getChildren(null)) {
      DiffUtil.registerAction(action, myMainPanel);
    }
  }
 public IconsFreeActionGroup(ActionGroup group) {
   super(
       group.getTemplatePresentation().getText(),
       group.getTemplatePresentation().getDescription(),
       null);
   myGroup = group;
 }
 public void update(AnActionEvent e) {
   super.update(e);
   if (e != null) {
     if (e.getPresentation().isVisible() && findActions(e).length == 0) {
       e.getPresentation().setVisible(false);
     }
   }
 }
 public boolean isGroupContainsInPath(ActionGroup group) {
   for (String s : myGroupPath) {
     if (s.equals(group.getTemplatePresentation().getText())) {
       return true;
     }
   }
   return false;
 }
 private void collectAllActions(DefaultActionGroup group, ActionGroup actionGroup) {
   for (AnAction action : actionGroup.getChildren(null)) {
     if (action instanceof ActionGroup && !((ActionGroup) action).isPopup()) {
       collectAllActions(group, (ActionGroup) action);
     } else {
       group.add(action);
     }
   }
 }
Пример #10
0
 @Override
 public void update(AnActionEvent e) {
   super.update(e);
   e.getPresentation()
       .setVisible(
           SendToFavoritesAction.isEnabled(e)
               && FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(e.getDataContext())
                   != null);
 }
Пример #11
0
 private void collectActionIds(Collection<String> result, ActionGroup group) {
   final AnAction[] actions = group.getChildren(null);
   for (AnAction action : actions) {
     if (action instanceof ActionGroup) {
       collectActionIds(result, (ActionGroup) action);
     } else if (action != null) {
       result.add(getActionId(action));
     }
   }
 }
 @NotNull
 @Override
 public AnAction[] getChildren(@Nullable AnActionEvent e) {
   AnAction[] children = myGroup.getChildren(e);
   AnAction[] patched = new AnAction[children.length];
   for (int i = 0; i < children.length; i++) {
     patched[i] = patch(children[i]);
   }
   return patched;
 }
Пример #13
0
 public Object[] getElementsByName(
     final String id, final boolean checkBoxState, final String pattern) {
   final HashMap<AnAction, String> map = new HashMap<AnAction, String>();
   final ActionGroup mainMenu =
       (ActionGroup) myActionManager.getActionOrStub(IdeActions.GROUP_MAIN_MENU);
   collectActions(id, map, mainMenu, mainMenu.getTemplatePresentation().getText());
   if (checkBoxState) {
     final Set<String> ids = ((ActionManagerImpl) myActionManager).getActionIds();
     for (AnAction action : map.keySet()) { // do not add already included actions
       ids.remove(getActionId(action));
     }
     if (ids.contains(id)) {
       final AnAction anAction = myActionManager.getAction(id);
       if (!(anAction instanceof ActionGroup)) {
         map.put(anAction, null);
       }
     }
   }
   return map.entrySet().toArray(new Map.Entry[map.size()]);
 }
Пример #14
0
 @Override
 public void update(AnActionEvent event) {
   super.update(event);
   Presentation presentation = event.getPresentation();
   FileTemplate[] allTemplates = FileTemplateManager.getInstance().getAllTemplates();
   for (FileTemplate template : allTemplates) {
     if (canCreateFromTemplate(event, template)) {
       presentation.setEnabled(true);
       return;
     }
   }
   presentation.setEnabled(false);
 }
Пример #15
0
 private void collectActions(
     String id,
     Map<AnAction, String> result,
     ActionGroup group,
     final String containingGroupName) {
   final AnAction[] actions = group.getChildren(null);
   for (AnAction action : actions) {
     if (action != null) {
       if (action instanceof ActionGroup) {
         final ActionGroup actionGroup = (ActionGroup) action;
         final String groupName = actionGroup.getTemplatePresentation().getText();
         collectActions(
             id, result, actionGroup, groupName != null ? groupName : containingGroupName);
       } else if (getActionId(action) == id) {
         final String groupName = group.getTemplatePresentation().getText();
         result.put(
             action,
             groupName != null && groupName.length() > 0 ? groupName : containingGroupName);
       }
     }
   }
 }
 private static void addSorted(DefaultActionGroup main, ActionGroup group) {
   final AnAction[] children = group.getChildren(null);
   boolean hadSecondary = false;
   for (AnAction action : children) {
     if (group.isPrimary(action)) {
       main.add(action);
     } else {
       hadSecondary = true;
     }
   }
   if (hadSecondary) {
     main.addSeparator();
     for (AnAction action : children) {
       if (!group.isPrimary(action)) {
         main.addAction(action).setAsSecondary(true);
       }
     }
   }
   String separatorText = group.getTemplatePresentation().getText();
   if (children.length > 0 && !StringUtil.isEmpty(separatorText)) {
     main.addAction(new Separator(separatorText), Constraints.FIRST);
   }
 }
Пример #17
0
  private List<Button> buildButtons(ActionGroup group, String parentId) {
    AnAction[] actions = group.getChildren(null);

    List<Button> buttons = new ArrayList<Button>();

    for (AnAction action : actions) {
      Presentation presentation = action.getTemplatePresentation();
      if (!USE_ICONS) {
        presentation.setIcon(null);
      }
      if (action instanceof ActionGroup) {
        ActionGroup childGroup = (ActionGroup) action;
        if (childGroup.isPopup()) {
          final String id = String.valueOf(++nCards);
          createCardForGroup(childGroup, id, parentId);

          buttons.add(new Button(new ActivateCard(id), presentation));
        } else {
          buttons.addAll(buildButtons(childGroup, parentId));
        }
      } else {
        action.update(
            new AnActionEvent(
                null,
                DataManager.getInstance().getDataContext(this),
                ActionPlaces.WELCOME_SCREEN,
                presentation,
                ActionManager.getInstance(),
                0));
        if (presentation.isVisible()) {
          buttons.add(new Button(action, presentation));
        }
      }
    }
    return buttons;
  }
 private void appendActionsFromGroup(@NotNull ActionGroup actionGroup) {
   AnAction[] actions = actionGroup.getChildren(createActionEvent(actionGroup));
   for (AnAction action : actions) {
     if (action == null) {
       LOG.error("null action in group " + actionGroup);
       continue;
     }
     if (action instanceof Separator) {
       myPrependWithSeparator = true;
       mySeparatorText = ((Separator) action).getText();
     } else {
       if (action instanceof ActionGroup) {
         ActionGroup group = (ActionGroup) action;
         if (group.isPopup()) {
           appendAction(group);
         } else {
           appendActionsFromGroup(group);
         }
       } else {
         appendAction(action);
       }
     }
   }
 }
Пример #19
0
 public void actionPerformed(AnActionEvent e) {
   final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
   final ListPopupStep step =
       popupFactory.createActionsStep(
           myActionGroup,
           e.getDataContext(),
           false,
           false,
           myActionGroup.getTemplatePresentation().getText(),
           myTree,
           true,
           myPreselection != null ? myPreselection.getDefaultIndex() : 0,
           true);
   final ListPopup listPopup = popupFactory.createListPopup(step);
   listPopup.setHandleAutoSelectionBeforeShow(true);
   if (e instanceof AnActionButton.AnActionEventWrapper) {
     ((AnActionButton.AnActionEventWrapper) e).showPopup(listPopup);
   } else {
     listPopup.showUnderneathOf(myNorthPanel);
   }
 }
  public static Pair<JPanel, JBList> createActionGroupPanel(
      ActionGroup action, final JComponent parent, final Runnable backAction) {
    JPanel actionsListPanel = new JPanel(new BorderLayout());
    actionsListPanel.setBackground(getProjectsBackground());
    final JBList list = new JBList(action.getChildren(null));
    list.setBackground(getProjectsBackground());
    list.installCellRenderer(
        new NotNullFunction<AnAction, JComponent>() {
          final JLabel label = new JLabel();

          {
            label.setBorder(JBUI.Borders.empty(3, 7));
          }

          @NotNull
          @Override
          public JComponent fun(AnAction action) {
            label.setText(action.getTemplatePresentation().getText());
            Icon icon = action.getTemplatePresentation().getIcon();
            label.setIcon(icon);
            return label;
          }
        });
    JScrollPane pane = ScrollPaneFactory.createScrollPane(list, true);
    pane.setBackground(getProjectsBackground());
    actionsListPanel.add(pane, BorderLayout.CENTER);
    if (backAction != null) {
      final JLabel back = new JLabel(AllIcons.Actions.Back);
      back.setBorder(JBUI.Borders.empty(3, 7, 10, 7));
      back.setHorizontalAlignment(SwingConstants.LEFT);
      new ClickListener() {
        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
          backAction.run();
          return true;
        }
      }.installOn(back);
      actionsListPanel.add(back, BorderLayout.SOUTH);
    }
    final Ref<Component> selected = Ref.create();
    final JPanel main = new JPanel(new BorderLayout());
    main.add(actionsListPanel, BorderLayout.WEST);

    ListSelectionListener selectionListener =
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
              // Update when a change has been finalized.
              // For instance, selecting an element with mouse fires two consecutive
              // ListSelectionEvent events.
              return;
            }
            if (!selected.isNull()) {
              main.remove(selected.get());
            }
            Object value = list.getSelectedValue();
            if (value instanceof AbstractActionWithPanel) {
              JPanel panel = ((AbstractActionWithPanel) value).createPanel();
              panel.setBorder(JBUI.Borders.empty(7, 10));
              selected.set(panel);
              main.add(selected.get());

              for (JButton button : UIUtil.findComponentsOfType(main, JButton.class)) {
                if (button.getClientProperty(DialogWrapper.DEFAULT_ACTION) == Boolean.TRUE) {
                  parent.getRootPane().setDefaultButton(button);
                  break;
                }
              }

              main.revalidate();
              main.repaint();
            }
          }
        };
    list.addListSelectionListener(selectionListener);
    if (backAction != null) {
      new AnAction() {
        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
          backAction.run();
        }
      }.registerCustomShortcutSet(KeyEvent.VK_ESCAPE, 0, main);
    }
    return Pair.create(main, list);
  }
 @Override
 public boolean isPopup() {
   return myGroup.isPopup();
 }
 @NotNull
 @Override
 public AnAction[] getChildren(@Nullable AnActionEvent e) {
   return myGroup.getChildren(e);
 }
 public void update(AnActionEvent e) {
   //    myAction.getChildren(e).length
   getTemplatePresentation().setText(myAction.getTemplatePresentation().getText());
   super.update(e);
 }