protected Color defaultActionForeground(boolean isSelected, Presentation presentation) { return isSelected ? UIUtil.getListSelectionForeground() : presentation.isEnabled() && presentation.isVisible() ? UIUtil.getListForeground() : UIUtil.getInactiveTextColor(); }
private JComponent createActionPanel() { JPanel actions = new NonOpaquePanel(); actions.setBorder(JBUI.Borders.emptyLeft(10)); actions.setLayout(new BoxLayout(actions, BoxLayout.Y_AXIS)); ActionManager actionManager = ActionManager.getInstance(); ActionGroup quickStart = (ActionGroup) actionManager.getAction(IdeActions.GROUP_WELCOME_SCREEN_QUICKSTART); DefaultActionGroup group = new DefaultActionGroup(); collectAllActions(group, quickStart); for (AnAction action : group.getChildren(null)) { JPanel button = new JPanel(new BorderLayout()); button.setOpaque(false); button.setBorder(JBUI.Borders.empty(8, 20)); AnActionEvent e = AnActionEvent.createFromAnAction( action, null, ActionPlaces.WELCOME_SCREEN, DataManager.getInstance().getDataContext(this)); action.update(e); Presentation presentation = e.getPresentation(); if (presentation.isVisible()) { String text = presentation.getText(); if (text != null && text.endsWith("...")) { text = text.substring(0, text.length() - 3); } Icon icon = presentation.getIcon(); if (icon.getIconHeight() != JBUI.scale(16) || icon.getIconWidth() != JBUI.scale(16)) { icon = JBUI.emptyIcon(16); } action = wrapGroups(action); ActionLink link = new ActionLink(text, icon, action, createUsageTracker(action)); link.setPaintUnderline(false); link.setNormalColor(getLinkNormalColor()); button.add(link); if (action instanceof WelcomePopupAction) { button.add(createArrow(link), BorderLayout.EAST); } installFocusable(button, action, KeyEvent.VK_UP, KeyEvent.VK_DOWN, true); actions.add(button); } } WelcomeScreenActionsPanel panel = new WelcomeScreenActionsPanel(); panel.actions.add(actions); return panel.root; }
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 void init() { setVisible(myPresentation.isVisible()); setEnabled(myPresentation.isEnabled()); setMnemonic(myEnableMnemonics ? myPresentation.getMnemonic() : 0); setText(myPresentation.getText()); final int mnemonicIndex = myEnableMnemonics ? myPresentation.getDisplayedMnemonicIndex() : -1; if (getText() != null && mnemonicIndex >= 0 && mnemonicIndex < getText().length()) { setDisplayedMnemonicIndex(mnemonicIndex); } AnAction action = myAction.getAction(); updateIcon(action); String id = ActionManager.getInstance().getId(action); if (id != null) { setAcceleratorFromShortcuts(KeymapManager.getInstance().getActiveKeymap().getShortcuts(id)); } else { final ShortcutSet shortcutSet = action.getShortcutSet(); if (shortcutSet != null) { setAcceleratorFromShortcuts(shortcutSet.getShortcuts()); } } }
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; }