Search in sources :

Example 31 with AnAction

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

the class ChameleonAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    AnAction action = getAction(e);
    assert action != null;
    action.actionPerformed(e);
}
Also used : AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 32 with AnAction

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

the class MacGestureAdapter method swipedRight.

@Override
public void swipedRight(SwipeEvent event) {
    ActionManager actionManager = ActionManager.getInstance();
    AnAction back = actionManager.getAction("Back");
    if (back == null)
        return;
    actionManager.tryToExecute(back, createMouseEventWrapper(myFrame), null, null, false);
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 33 with AnAction

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

the class KeymapsTestCase method testValidActionIds.

public void testValidActionIds() {
    THashSet<String> unknownActions = new THashSet<>();
    collectUnknownActions(unknownActions);
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") Map<String, List<String>> missingActions = new FactoryMap<String, List<String>>() {

        @Override
        protected Map<String, List<String>> createMap() {
            return new LinkedHashMap<>();
        }

        @Nullable
        @Override
        protected List<String> create(String key) {
            return new ArrayList<>();
        }
    };
    for (Keymap keymap : KeymapManagerEx.getInstanceEx().getAllKeymaps()) {
        List<String> ids = new ArrayList<>(keymap.getActionIdList());
        ids.sort(null);
        assertThat(ids).isEqualTo(new ArrayList<>(new LinkedHashSet<>(ids)));
        for (String cid : ids) {
            if (unknownActions.contains(cid))
                continue;
            AnAction action = ActionManager.getInstance().getAction(cid);
            if (action == null) {
                if (OUTPUT_TEST_DATA) {
                    System.out.print("\"" + cid + "\", ");
                } else {
                    missingActions.get(keymap.getName()).add(cid);
                }
            }
        }
    }
    List<String> reappearedAction = new ArrayList<>();
    for (String id : unknownActions) {
        AnAction action = ActionManager.getInstance().getAction(id);
        if (action != null) {
            reappearedAction.add(id);
        }
    }
    if (!missingActions.isEmpty() || !reappearedAction.isEmpty()) {
        StringBuilder message = new StringBuilder();
        if (!missingActions.isEmpty()) {
            for (Map.Entry<String, List<String>> keymapAndActions : missingActions.entrySet()) {
                message.append("Unknown actions in keymap ").append(keymapAndActions.getKey()).append(", add them to unknown actions list:\n");
                for (String action : keymapAndActions.getValue()) {
                    message.append("\"").append(action).append("\",").append("\n");
                }
            }
        }
        if (!reappearedAction.isEmpty()) {
            message.append("The following actions have reappeared, remove them from unknown action list:\n");
            for (String action : reappearedAction) {
                message.append(action).append("\n");
            }
        }
        fail("\n" + message);
    }
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) AnAction(com.intellij.openapi.actionSystem.AnAction) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) FactoryMap(com.intellij.util.containers.FactoryMap) MacOSDefaultKeymap(com.intellij.openapi.keymap.impl.MacOSDefaultKeymap) Keymap(com.intellij.openapi.keymap.Keymap)

Example 34 with AnAction

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

the class UnwrapTestCase method assertOptions.

protected void assertOptions(String code, String... expectedOptions) throws IOException {
    configureCode(code);
    final List<String> actualOptions = new ArrayList<>();
    UnwrapHandler h = new UnwrapHandler() {

        @Override
        protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
            for (AnAction each : options) {
                actualOptions.add(each.getTemplatePresentation().getText());
            }
        }
    };
    h.invoke(getProject(), getEditor(), getFile());
    //noinspection MisorderedAssertEqualsArguments
    assertEquals(Arrays.asList(expectedOptions), actualOptions);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 35 with AnAction

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

the class ShowQuickActionPopupAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    QuickActionProvider provider = e.getRequiredData(QuickActionProvider.KEY);
    List<AnAction> actions = provider.getActions(true);
    DefaultActionGroup group = new DefaultActionGroup(actions);
    group.addSeparator();
    JComponent component = provider.getComponent();
    if (component != null && !provider.isCycleRoot()) {
        Component eachParent = component.getParent();
        while (eachParent != null) {
            QuickActionProvider parentProvider = ObjectUtils.tryCast(eachParent, QuickActionProvider.class);
            if (parentProvider != null) {
                List<AnAction> parentActions = parentProvider.getActions(false);
                if (!parentActions.isEmpty()) {
                    String name = StringUtil.notNullize(parentProvider.getName(), "");
                    DefaultActionGroup parentGroup = new DefaultActionGroup(name, parentActions);
                    if (!StringUtil.isEmpty(name)) {
                        parentGroup.setPopup(true);
                    } else {
                        group.add(Separator.getInstance());
                    }
                    group.add(parentGroup);
                }
                if (parentProvider.isCycleRoot())
                    break;
            }
            eachParent = eachParent.getParent();
        }
    }
    JBPopupFactory.getInstance().createActionGroupPopup(null, group, e.getDataContext(), ALPHA_NUMBERING, true).showInBestPositionFor(e.getDataContext());
}
Also used : AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Aggregations

AnAction (com.intellij.openapi.actionSystem.AnAction)184 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)62 NotNull (org.jetbrains.annotations.NotNull)31 Project (com.intellij.openapi.project.Project)24 Nullable (org.jetbrains.annotations.Nullable)22 ActionManager (com.intellij.openapi.actionSystem.ActionManager)21 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)21 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)13 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)7 Presentation (com.intellij.openapi.actionSystem.Presentation)7 PsiFile (com.intellij.psi.PsiFile)7 ReopenProjectAction (com.intellij.ide.ReopenProjectAction)6 Editor (com.intellij.openapi.editor.Editor)6 Keymap (com.intellij.openapi.keymap.Keymap)6 Ref (com.intellij.openapi.util.Ref)6 List (java.util.List)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5