protected AnActionEvent updateActionBeforShow(AnAction anAction, DataContext dataContext) { final AnActionEvent event = new AnActionEvent( null, dataContext, ActionPlaces.UNKNOWN, new Presentation(), ActionManager.getInstance(), 0); ActionUtil.performDumbAwareUpdate(anAction, event, false); ActionUtil.performDumbAwareUpdate(anAction, event, true); return event; }
public static void fire(@NotNull final Notification notification, @NotNull AnAction action) { AnActionEvent event = AnActionEvent.createFromAnAction( action, null, ActionPlaces.UNKNOWN, new DataContext() { @Nullable @Override public Object getData(@NonNls String dataId) { return KEY.getName().equals(dataId) ? notification : null; } }); if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) { ActionUtil.performActionDumbAware(action, event); } }
public boolean processAction(final InputEvent e, ActionProcessor processor) { ActionManagerEx actionManager = ActionManagerEx.getInstanceEx(); final Project project = PlatformDataKeys.PROJECT.getData(myContext.getDataContext()); final boolean dumb = project != null && DumbService.getInstance(project).isDumb(); List<AnActionEvent> nonDumbAwareAction = new ArrayList<AnActionEvent>(); for (final AnAction action : myContext.getActions()) { final Presentation presentation = myPresentationFactory.getPresentation(action); // Mouse modifiers are 0 because they have no any sense when action is invoked via keyboard final AnActionEvent actionEvent = processor.createEvent( e, myContext.getDataContext(), ActionPlaces.MAIN_MENU, presentation, ActionManager.getInstance()); ActionUtil.performDumbAwareUpdate(action, actionEvent, true); if (dumb && !action.isDumbAware()) { if (Boolean.FALSE.equals( presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) { continue; } nonDumbAwareAction.add(actionEvent); continue; } if (!presentation.isEnabled()) { continue; } processor.onUpdatePassed(e, action, actionEvent); ((DataManagerImpl.MyDataContext) myContext.getDataContext()) .setEventCount(IdeEventQueue.getInstance().getEventCount(), this); actionManager.fireBeforeActionPerformed(action, actionEvent.getDataContext(), actionEvent); Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(actionEvent.getDataContext()); if (component != null && !component.isShowing()) { return true; } processor.performAction(e, action, actionEvent); actionManager.fireAfterActionPerformed(action, actionEvent.getDataContext(), actionEvent); return true; } if (!nonDumbAwareAction.isEmpty()) { showDumbModeWarningLaterIfNobodyConsumesEvent( e, nonDumbAwareAction.toArray(new AnActionEvent[nonDumbAwareAction.size()])); } return false; }
protected void buildToolBar(final DefaultActionGroup toolBarGroup) { myDiffAction = new DumbAwareAction() { public void update(AnActionEvent e) { e.getPresentation().setEnabled(canShowDiff()); } public void actionPerformed(AnActionEvent e) { showDiff(); } }; ActionUtil.copyFrom(myDiffAction, "ChangesView.Diff"); myDiffAction.registerCustomShortcutSet(myViewer, null); toolBarGroup.add(myDiffAction); }
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 fillActionsList( Component component, MouseShortcut mouseShortcut, boolean isModalContext) { myActions.clear(); // here we try to find "local" shortcuts if (component instanceof JComponent) { for (AnAction action : ActionUtil.getActions((JComponent) component)) { for (Shortcut shortcut : action.getShortcutSet().getShortcuts()) { if (mouseShortcut.equals(shortcut) && !myActions.contains(action)) { myActions.add(action); } } } // once we've found a proper local shortcut(s), we exit if (!myActions.isEmpty()) { return; } } // search in main keymap if (KeymapManagerImpl.ourKeymapManagerInitialized) { final KeymapManager keymapManager = KeymapManager.getInstance(); if (keymapManager != null) { final Keymap keymap = keymapManager.getActiveKeymap(); final String[] actionIds = keymap.getActionIds(mouseShortcut); ActionManager actionManager = ActionManager.getInstance(); for (String actionId : actionIds) { AnAction action = actionManager.getAction(actionId); if (action == null) continue; if (isModalContext && !action.isEnabledInModalContext()) continue; if (!myActions.contains(action)) { myActions.add(action); } } } } }
public OpenInEditorAction(@Nullable Runnable afterRunnable) { ActionUtil.copyFrom(this, "EditSource"); myAfterRunnable = afterRunnable; }