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; } } } }
private AnAction patch(final AnAction child) { if (child instanceof ActionGroup) { return new IconsFreeActionGroup((ActionGroup) child); } Presentation presentation = child.getTemplatePresentation(); return new AnAction(presentation.getText(), presentation.getDescription(), null) { @Override public void actionPerformed(@NotNull AnActionEvent e) { child.actionPerformed(e); UsageTrigger.trigger("welcome.screen." + e.getActionManager().getId(child)); } @Override public void update(@NotNull AnActionEvent e) { child.update(e); e.getPresentation().setIcon(null); } @Override public boolean isDumbAware() { return child.isDumbAware(); } }; }
private Presentation getPresentation(@NotNull AnAction action) { Presentation presentation = myAction2presentation.get(action); if (presentation == null) { presentation = action.getTemplatePresentation().clone(); myAction2presentation.put(action, presentation); } return presentation; }
public boolean matches(@NotNull final String name, @NotNull final String pattern) { final AnAction anAction = myActionManager.getAction(name); if (!(anAction instanceof ActionGroup)) { final Presentation presentation = anAction.getTemplatePresentation(); final String text = presentation.getText(); final String description = presentation.getDescription(); final Pattern compiledPattern = getPattern(pattern); if ((text != null && myMatcher.matches(text, compiledPattern)) || (description != null && myMatcher.matches(description, compiledPattern))) { return true; } } return false; }
private void executeAction(final String watch) { AnAction action = ActionManager.getInstance().getAction(watch); Presentation presentation = action.getTemplatePresentation().clone(); DataContext context = DataManager.getInstance().getDataContext(myTreePanel.getTree()); AnActionEvent actionEvent = new AnActionEvent( null, context, ActionPlaces.DEBUGGER_TOOLBAR, presentation, ActionManager.getInstance(), 0); action.actionPerformed(actionEvent); }
private void appendAction(@NotNull AnAction action) { Presentation presentation = getPresentation(action); AnActionEvent event = createActionEvent(action); ActionUtil.performDumbAwareUpdate(action, event, true); if ((myShowDisabled || presentation.isEnabled()) && presentation.isVisible()) { String text = presentation.getText(); if (myShowNumbers) { if (myCurrentNumber < 9) { text = "&" + (myCurrentNumber + 1) + ". " + text; } else if (myCurrentNumber == 9) { text = "&" + 0 + ". " + text; } else if (myUseAlphaAsNumbers) { text = "&" + (char) ('A' + myCurrentNumber - 10) + ". " + text; } myCurrentNumber++; } else if (myHonorActionMnemonics) { text = Presentation.restoreTextWithMnemonic( text, action.getTemplatePresentation().getMnemonic()); } Icon icon = presentation.getIcon(); if (icon == null) { @NonNls final String actionId = ActionManager.getInstance().getId(action); if (actionId != null && actionId.startsWith("QuickList.")) { icon = AllIcons.Actions.QuickList; } else if (action instanceof Toggleable) { boolean toggled = Boolean.TRUE.equals(presentation.getClientProperty(Toggleable.SELECTED_PROPERTY)); icon = toggled ? new IconWrapper(PlatformIcons.CHECK_ICON) : myEmptyIcon; } else { icon = myEmptyIcon; } } else { icon = new IconWrapper(icon); } boolean prependSeparator = (!myListModel.isEmpty() || mySeparatorText != null) && myPrependWithSeparator; assert text != null : action + " has no presentation"; myListModel.add( new ActionItem( action, text, presentation.isEnabled(), icon, prependSeparator, mySeparatorText)); myPrependWithSeparator = false; mySeparatorText = null; } }
private AnAction wrapGroups(AnAction action) { if (action instanceof ActionGroup && ((ActionGroup) action).isPopup()) { final Pair<JPanel, JBList> panel = createActionGroupPanel( (ActionGroup) action, mySlidingPanel, new Runnable() { @Override public void run() { goBack(); } }); final Runnable onDone = new Runnable() { @Override public void run() { final JBList list = panel.second; ScrollingUtil.ensureSelectionExists(list); final ListSelectionListener[] listeners = ((DefaultListSelectionModel) list.getSelectionModel()) .getListeners(ListSelectionListener.class); // avoid component cashing. This helps in case of LaF change for (ListSelectionListener listener : listeners) { listener.valueChanged( new ListSelectionEvent( list, list.getSelectedIndex(), list.getSelectedIndex(), true)); } list.requestFocus(); } }; final String name = action.getClass().getName(); mySlidingPanel.add(name, panel.first); final Presentation p = action.getTemplatePresentation(); return new DumbAwareAction(p.getText(), p.getDescription(), p.getIcon()) { @Override public void actionPerformed(@NotNull AnActionEvent e) { mySlidingPanel .getLayout() .swipe(mySlidingPanel, name, JBCardLayout.SwipeDirection.FORWARD, onDone); } }; } return action; }
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; }
// Make sure that the text rendered by this method is 'searchable' via // com.intellij.openapi.keymap.impl.ui.ActionsTree.filter method. public void customizeCellRenderer( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { final boolean showIcons = UISettings.getInstance().SHOW_ICONS_IN_MENUS; Keymap originalKeymap = myKeymap != null ? myKeymap.getParent() : null; Icon icon = null; String text; boolean bound = false; setToolTipText(null); if (value instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); boolean changed; if (userObject instanceof Group) { Group group = (Group) userObject; text = group.getName(); changed = originalKeymap != null && isGroupChanged(group, originalKeymap, myKeymap); icon = group.getIcon(); if (icon == null) { icon = CLOSE_ICON; } } else if (userObject instanceof String) { String actionId = (String) userObject; bound = myShowBoundActions && ((KeymapImpl) myKeymap).isActionBound(actionId); AnAction action = ActionManager.getInstance().getAction(actionId); if (action != null) { text = action.getTemplatePresentation().getText(); if (text == null || text.length() == 0) { // fill dynamic presentation gaps text = actionId; } Icon actionIcon = action.getTemplatePresentation().getIcon(); if (actionIcon != null) { icon = actionIcon; } setToolTipText(action.getTemplatePresentation().getDescription()); } else { text = actionId; } changed = originalKeymap != null && isActionChanged(actionId, originalKeymap, myKeymap); } else if (userObject instanceof QuickList) { QuickList list = (QuickList) userObject; icon = AllIcons.Actions.QuickList; text = list.getDisplayName(); changed = originalKeymap != null && isActionChanged(list.getActionId(), originalKeymap, myKeymap); } else if (userObject instanceof Separator) { // TODO[vova,anton]: beautify changed = false; text = "-------------"; } else { throw new IllegalArgumentException("unknown userObject: " + userObject); } if (showIcons) { setIcon(ActionsTree.getEvenIcon(icon)); } Color foreground; if (selected) { foreground = UIUtil.getTreeSelectionForeground(); } else { if (changed) { foreground = PlatformColors.BLUE; } else { foreground = UIUtil.getTreeForeground(); } if (bound) { foreground = JBColor.MAGENTA; } } SearchUtil.appendFragments( myFilter, text, Font.PLAIN, foreground, selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground(), this); } }