Search in sources :

Example 6 with ActionManagerEx

use of com.intellij.openapi.actionSystem.ex.ActionManagerEx in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method _performEditorAction.

private boolean _performEditorAction(@NotNull String actionId) {
    final DataContext dataContext = getEditorDataContext();
    final ActionManagerEx managerEx = ActionManagerEx.getInstanceEx();
    final AnAction action = managerEx.getAction(actionId);
    final AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, new Presentation(), managerEx, 0);
    action.beforeActionPerformedUpdate(event);
    if (!event.getPresentation().isEnabled()) {
        return false;
    }
    managerEx.fireBeforeActionPerformed(action, dataContext, event);
    action.actionPerformed(event);
    managerEx.fireAfterActionPerformed(action, dataContext, event);
    return true;
}
Also used : ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Example 7 with ActionManagerEx

use of com.intellij.openapi.actionSystem.ex.ActionManagerEx in project intellij-community by JetBrains.

the class IdeMouseEventDispatcher method dispatchMouseEvent.

/**
   * @return {@code true} if and only if the passed event is already dispatched by the
   *         {@code IdeMouseEventDispatcher} and there is no need for any other processing of the event.
   *         If the method returns {@code false} then it means that the event should be delivered
   *         to normal event dispatching.
   */
public boolean dispatchMouseEvent(MouseEvent e) {
    Component c = e.getComponent();
    //frame activation by mouse click
    if (e.getID() == MOUSE_PRESSED && c instanceof IdeFrame && !c.hasFocus()) {
        IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
        if (focusManager instanceof FocusManagerImpl) {
            Component at = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());
            if (at != null && at.isFocusable()) {
                ((FocusManagerImpl) focusManager).setLastFocusedAtDeactivation((IdeFrame) c, at);
            }
        }
    }
    if (e.isPopupTrigger()) {
        if (BUTTON3 == e.getButton()) {
            if (Registry.is("ide.mouse.popup.trigger.modifiers.disabled") && (~BUTTON3_DOWN_MASK & e.getModifiersEx()) != 0) {
                // it allows to use our mouse shortcuts for Ctrl+Button3, for example
                resetPopupTrigger(e);
            }
        } else if (SystemInfo.isXWindow) {
            // we can do better than silly triggering popup on everything but left click
            resetPopupTrigger(e);
        }
    }
    boolean ignore = false;
    if (!(e.getID() == MOUSE_PRESSED || e.getID() == MOUSE_RELEASED || e.getID() == MOUSE_WHEEL && 0 < e.getModifiersEx() || e.getID() == MOUSE_CLICKED)) {
        ignore = true;
    }
    patchClickCount(e);
    int clickCount = e.getClickCount();
    int button = MouseShortcut.getButton(e);
    if (button == MouseShortcut.BUTTON_WHEEL_UP || button == MouseShortcut.BUTTON_WHEEL_DOWN) {
        clickCount = 1;
    }
    if (e.isConsumed() || e.isPopupTrigger() || (button > 3 ? e.getID() != MOUSE_PRESSED && e.getID() != MOUSE_WHEEL : e.getID() != MOUSE_RELEASED) || clickCount < 1 || button == NOBUTTON) {
        // See #16995. It did happen
        ignore = true;
    }
    @JdkConstants.InputEventMask int modifiers = e.getModifiers();
    @JdkConstants.InputEventMask int modifiersEx = e.getModifiersEx();
    if (e.getID() == MOUSE_PRESSED) {
        myPressedModifiersStored = true;
        myModifiers = modifiers;
        myModifiersEx = modifiersEx;
    } else if (e.getID() == MOUSE_RELEASED) {
        myForceTouchIsAllowed = true;
        if (myPressedModifiersStored) {
            myPressedModifiersStored = false;
            modifiers = myModifiers;
            modifiersEx = myModifiersEx;
        }
    }
    final JRootPane root = findRoot(e);
    if (root != null) {
        BlockState blockState = myRootPane2BlockedId.get(root);
        if (blockState != null) {
            if (SWING_EVENTS_PRIORITY.indexOf(blockState.currentEventId) < SWING_EVENTS_PRIORITY.indexOf(e.getID())) {
                blockState.currentEventId = e.getID();
                if (blockState.blockMode == IdeEventQueue.BlockMode.COMPLETE) {
                    return true;
                } else {
                    ignore = true;
                }
            } else {
                myRootPane2BlockedId.remove(root);
            }
        }
    }
    if (c == null) {
        throw new IllegalStateException("component cannot be null");
    }
    c = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());
    if (c instanceof IdeGlassPaneImpl) {
        c = ((IdeGlassPaneImpl) c).getTargetComponentFor(e);
    }
    if (c == null) {
        // do nothing if component doesn't contains specified point
        return false;
    }
    if (c instanceof MouseShortcutPanel || c.getParent() instanceof MouseShortcutPanel) {
        // forward mouse processing to the special shortcut panel
        return false;
    }
    if (isHorizontalScrolling(c, e)) {
        boolean done = doHorizontalScrolling(c, (MouseWheelEvent) e);
        if (done)
            return true;
    }
    if (ignore)
        return false;
    // avoid "cyclic component initialization error" in case of dialogs shown because of component initialization failure
    if (!KeymapManagerImpl.ourKeymapManagerInitialized) {
        return false;
    }
    final MouseShortcut shortcut = new MouseShortcut(button, modifiersEx, clickCount);
    fillActionsList(c, shortcut, IdeKeyEventDispatcher.isModalContext(c));
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    if (actionManager != null) {
        AnAction[] actions = myActions.toArray(new AnAction[myActions.size()]);
        for (AnAction action : actions) {
            DataContext dataContext = DataManager.getInstance().getDataContext(c);
            Presentation presentation = myPresentationFactory.getPresentation(action);
            AnActionEvent actionEvent = new AnActionEvent(e, dataContext, ActionPlaces.MAIN_MENU, presentation, ActionManager.getInstance(), modifiers);
            if (ActionUtil.lastUpdateAndCheckDumb(action, actionEvent, false)) {
                actionManager.fireBeforeActionPerformed(action, dataContext, actionEvent);
                final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
                if (context != null && !context.isShowing())
                    continue;
                ActionUtil.performActionDumbAware(action, actionEvent);
                actionManager.fireAfterActionPerformed(action, dataContext, actionEvent);
                e.consume();
            }
        }
    }
    return e.getButton() > 3;
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) IdeGlassPaneImpl(com.intellij.openapi.wm.impl.IdeGlassPaneImpl) MouseShortcutPanel(com.intellij.openapi.keymap.impl.ui.MouseShortcutPanel) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) IdeFrame(com.intellij.openapi.wm.IdeFrame) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Example 8 with ActionManagerEx

use of com.intellij.openapi.actionSystem.ex.ActionManagerEx in project intellij-community by JetBrains.

the class ActionsTreeUtil method createOtherGroup.

@NotNull
private static Group createOtherGroup(@Nullable Condition<AnAction> filtered, Group addedActions, @Nullable Keymap keymap) {
    addedActions.initIds();
    Set<String> result = new THashSet<>();
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    if (keymap != null) {
        for (String id : keymap.getActionIdList()) {
            if (id.startsWith(EDITOR_PREFIX) && actionManager.getActionOrStub("$" + id.substring(6)) != null) {
                continue;
            }
            if (!id.startsWith(QuickList.QUICK_LIST_PREFIX) && !addedActions.containsId(id)) {
                result.add(id);
            }
        }
    }
    // add all registered actions
    final KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    String[] registeredActionIds = actionManager.getActionIds("");
    for (String id : registeredActionIds) {
        final AnAction actionOrStub = actionManager.getActionOrStub(id);
        if (actionOrStub instanceof ActionGroup && !((ActionGroup) actionOrStub).canBePerformed(DataManager.getInstance().getDataContext())) {
            continue;
        }
        if (id.startsWith(QuickList.QUICK_LIST_PREFIX) || addedActions.containsId(id) || result.contains(id) || keymapManager.getBoundActions().contains(id)) {
            continue;
        }
        result.add(id);
    }
    filterOtherActionsGroup(result);
    Group group = new Group(KeyMapBundle.message("other.group.title"), AllIcons.Nodes.KeymapOther);
    AnAction[] groupedActions = getActions("Other.KeymapGroup");
    for (AnAction action : groupedActions) {
        addAction(group, action, filtered);
    }
    result.removeAll(group.initIds());
    for (String id : ContainerUtil.sorted(result, (id1, id2) -> getTextToCompare(id1).compareToIgnoreCase(getTextToCompare(id2)))) {
        if (filtered == null || filtered.value(actionManager.getActionOrStub(id)))
            group.addActionId(id);
    }
    return group;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) THashSet(gnu.trove.THashSet) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ActionManagerEx

use of com.intellij.openapi.actionSystem.ex.ActionManagerEx in project intellij-community by JetBrains.

the class MacGestureSupportForEditor method handleMouseShortcut.

private void handleMouseShortcut(PressureEvent e, MouseShortcut shortcut, JComponent component) {
    fillActionsList(shortcut, IdeKeyEventDispatcher.isModalContext(component));
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    if (actionManager != null) {
        AnAction[] actions = myActions.toArray(new AnAction[myActions.size()]);
        for (AnAction action : actions) {
            DataContext dataContext = DataManager.getInstance().getDataContext(component);
            Presentation presentation = myPresentationFactory.getPresentation(action);
            AnActionEvent actionEvent = new AnActionEvent(null, dataContext, ActionPlaces.MAIN_MENU, presentation, ActionManager.getInstance(), 0);
            action.beforeActionPerformedUpdate(actionEvent);
            if (presentation.isEnabled()) {
                actionManager.fireBeforeActionPerformed(action, dataContext, actionEvent);
                final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
                if (context != null && !context.isShowing())
                    continue;
                action.actionPerformed(actionEvent);
            }
        }
    }
    e.consume();
    IdeMouseEventDispatcher.forbidForceTouch();
}
Also used : ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Example 10 with ActionManagerEx

use of com.intellij.openapi.actionSystem.ex.ActionManagerEx in project android by JetBrains.

the class ConfigurationAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ActionManagerEx manager = ActionManagerEx.getInstanceEx();
    final DataContext dataContext = e.getDataContext();
    // Regular actions invoke this method before performing the action. We do so as well since the analytics subsystem hooks into
    // this event to monitor invoked actions.
    manager.fireBeforeActionPerformed(this, dataContext, e);
    tryUpdateConfiguration();
    updatePresentation();
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Aggregations

ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)20 KeymapGroup (com.intellij.openapi.keymap.KeymapGroup)5 DataContext (com.intellij.openapi.actionSystem.DataContext)3 AnAction (com.intellij.openapi.actionSystem.AnAction)2 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)2 KeymapManagerEx (com.intellij.openapi.keymap.ex.KeymapManagerEx)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 HashMap (com.intellij.util.containers.HashMap)2 NotNull (org.jetbrains.annotations.NotNull)2 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 AntBuildFile (com.intellij.lang.ant.config.AntBuildFile)1 AntConfiguration (com.intellij.lang.ant.config.AntConfiguration)1 TargetAction (com.intellij.lang.ant.config.actions.TargetAction)1 MockApplication (com.intellij.mock.MockApplication)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 ActionToolbar (com.intellij.openapi.actionSystem.ActionToolbar)1 PluginId (com.intellij.openapi.extensions.PluginId)1 Group (com.intellij.openapi.keymap.impl.ui.Group)1 MouseShortcutPanel (com.intellij.openapi.keymap.impl.ui.MouseShortcutPanel)1