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 AnAction createBackspaceHandlingAction() { final AnAction upAction = new AnAction() { @Override public void actionPerformed(final AnActionEvent e) { new WriteCommandAction( getLanguageConsole().getProject(), getLanguageConsole().getFile()) { @Override protected void run(@NotNull final Result result) throws Throwable { String text = getLanguageConsole().getEditorDocument().getText(); String newText = text.substring( 0, text.length() - myConsoleExecuteActionHandler.getPythonIndent()); getLanguageConsole().getEditorDocument().setText(newText); getLanguageConsole() .getConsoleEditor() .getCaretModel() .moveToOffset(newText.length()); } }.execute(); } @Override public void update(final AnActionEvent e) { e.getPresentation() .setEnabled( myConsoleExecuteActionHandler.getCurrentIndentSize() >= myConsoleExecuteActionHandler.getPythonIndent() && isIndentSubstring(getLanguageConsole().getEditorDocument().getText())); } }; upAction.registerCustomShortcutSet(KeyEvent.VK_BACK_SPACE, 0, null); upAction.getTemplatePresentation().setVisible(false); return upAction; }
private void mousePressedInIconsArea(MouseEvent e) { EditorMessageIconRenderer iconRenderer = getIconRendererUnderMouse(e); if (iconRenderer != null) { if (e.getButton() == MouseEvent.BUTTON3) { JPopupMenu popupMenu = iconRenderer.getPopupMenu(); if (popupMenu != null && e.getID() == MouseEvent.MOUSE_PRESSED) { e.consume(); Component component = e.getComponent(); popupMenu.show(component == null ? myEditorComponent : component, e.getX(), e.getY()); } return; } AnAction action = iconRenderer.getClickAction(); if (e.getButton() == MouseEvent.BUTTON1 && action != null) { if (e.getID() == MouseEvent.MOUSE_CLICKED) { AnActionEvent actionEvent = new AnActionEvent( e, new LeftEditorHighlighterDataContext(myEditorComponent, iconRenderer.getNode()), ICON_AREA, action.getTemplatePresentation(), ActionManager.getInstance(), e.getModifiers()); action.update(actionEvent); action.actionPerformed(actionEvent); } e.consume(); } } }
private AnAction createInterruptAction() { AnAction anAction = new AnAction() { @Override public void actionPerformed(final AnActionEvent e) { if (myPydevConsoleCommunication.isExecuting()) { getConsoleView().print("^C", ProcessOutputTypes.SYSTEM); } myPydevConsoleCommunication.interrupt(); } @Override public void update(final AnActionEvent e) { EditorEx consoleEditor = getConsoleView().getConsole().getConsoleEditor(); boolean enabled = IJSwingUtilities.hasFocus(consoleEditor.getComponent()) && !consoleEditor.getSelectionModel().hasSelection(); e.getPresentation().setEnabled(enabled); } }; anAction.registerCustomShortcutSet( KeyEvent.VK_C, InputEvent.CTRL_MASK, getConsoleView().getConsole().getConsoleEditor().getComponent()); anAction.getTemplatePresentation().setVisible(false); return anAction; }
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 Presentation getPresentation(@NotNull AnAction action) { Presentation presentation = myAction2presentation.get(action); if (presentation == null) { presentation = action.getTemplatePresentation().clone(); myAction2presentation.put(action, presentation); } return presentation; }
private ActionPopupMenu createNewResourcePopupMenu() { ActionManager actionManager = ActionManager.getInstance(); DefaultActionGroup actionGroup = new DefaultActionGroup(); ResourceGroup resourceGroup = getSelectedElement(myProjectPanel.myTreeBuilder, ResourceGroup.class); if (resourceGroup == null) { resourceGroup = getSelectedElement(myProjectPanel.myTreeBuilder, ResourceItem.class).getGroup(); } if (AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.contains(resourceGroup.getType())) { myNewResourceFileAction .getTemplatePresentation() .setText("New " + resourceGroup + " File..."); myNewResourceFileAction .getTemplatePresentation() .putClientProperty(TYPE_KEY, resourceGroup.getType()); actionGroup.add(myNewResourceFileAction); } if (AndroidResourceUtil.VALUE_RESOURCE_TYPES.contains(resourceGroup.getType())) { String title = "New " + resourceGroup + " Value..."; if (resourceGroup.getType() == ResourceType.LAYOUT) { title = "New Layout Alias"; } myNewResourceValueAction.getTemplatePresentation().setText(title); myNewResourceValueAction .getTemplatePresentation() .putClientProperty(TYPE_KEY, resourceGroup.getType()); actionGroup.add(myNewResourceValueAction); } if (myTag != null && ResourceType.STYLE.equals(resourceGroup.getType())) { final boolean enabled = AndroidBaseLayoutRefactoringAction.getLayoutViewElement(myTag) != null && AndroidExtractStyleAction.doIsEnabled(myTag); myExtractStyleAction.getTemplatePresentation().setEnabled(enabled); actionGroup.add(myExtractStyleAction); } return actionManager.createActionPopupMenu(ActionPlaces.UNKNOWN, actionGroup); }
public void playBack(DataContext context) { AnAction action = ActionManager.getInstance().getAction(getActionId()); if (action == null) return; Presentation presentation = (Presentation) action.getTemplatePresentation().clone(); AnActionEvent event = new AnActionEvent( null, context, "MACRO_PLAYBACK", presentation, ActionManager.getInstance(), 0); action.beforeActionPerformedUpdate(event); if (!presentation.isEnabled()) { return; } action.actionPerformed(event); }
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); }
public static void performReferenceCopy(DataContext dataContext) { ActionManager actionManager = ActionManager.getInstance(); AnAction action = actionManager.getAction(IdeActions.ACTION_COPY_REFERENCE); AnActionEvent event = new AnActionEvent( null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0); action.update(event); Assert.assertTrue(event.getPresentation().isEnabled()); action.actionPerformed(event); }
public static void executeAction( @NotNull Editor editor, @NotNull String actionId, boolean assertActionIsEnabled) { ActionManager actionManager = ActionManager.getInstance(); AnAction action = actionManager.getAction(actionId); assertNotNull(action); DataContext dataContext = createEditorContext(editor); AnActionEvent event = new AnActionEvent( null, dataContext, "", action.getTemplatePresentation(), actionManager, 0); action.beforeActionPerformedUpdate(event); if (!event.getPresentation().isEnabled()) { assertFalse("Action " + actionId + " is disabled", assertActionIsEnabled); return; } action.actionPerformed(event); }
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); } }