Search in sources :

Example 61 with AnAction

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

the class UsageNodeTreeBuilderTest method buildUsageTree.

private GroupNode buildUsageTree(int[] indices, UsageGroupingRule[] rules) {
    Usage[] usages = new Usage[indices.length];
    for (int i = 0; i < usages.length; i++) {
        usages[i] = createUsage(indices[i]);
    }
    UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setUsagesString("searching for mock usages");
    ExtensionsArea area = Extensions.getRootArea();
    ExtensionPoint<UsageGroupingRuleProvider> point = area.getExtensionPoint(UsageGroupingRuleProvider.EP_NAME);
    UsageGroupingRuleProvider provider = new UsageGroupingRuleProvider() {

        @NotNull
        @Override
        public UsageGroupingRule[] getActiveRules(Project project) {
            return rules;
        }

        @NotNull
        @Override
        public AnAction[] createGroupingActions(UsageView view) {
            return AnAction.EMPTY_ARRAY;
        }
    };
    point.registerExtension(provider);
    try {
        UsageViewImpl usageView = new UsageViewImpl(getProject(), presentation, UsageTarget.EMPTY_ARRAY, null);
        Disposer.register(getTestRootDisposable(), usageView);
        for (Usage usage : usages) {
            usageView.appendUsage(usage);
        }
        UIUtil.dispatchAllInvocationEvents();
        return usageView.getRoot();
    } finally {
        point.unregisterExtension(provider);
    }
}
Also used : ExtensionsArea(com.intellij.openapi.extensions.ExtensionsArea) Project(com.intellij.openapi.project.Project) UsageGroupingRule(com.intellij.usages.rules.UsageGroupingRule) AnAction(com.intellij.openapi.actionSystem.AnAction) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) UsageGroupingRuleProvider(com.intellij.usages.rules.UsageGroupingRuleProvider)

Example 62 with AnAction

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

the class ImportTestsGroup method getChildren.

@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    if (e == null)
        return EMPTY_ARRAY;
    final Project project = e.getProject();
    if (project == null)
        return EMPTY_ARRAY;
    final Collection<String> filePaths = TestHistoryConfiguration.getInstance(project).getFiles();
    final File testHistoryRoot = TestStateStorage.getTestHistoryRoot(project);
    final List<File> fileNames = ContainerUtil.map(filePaths, fileName -> new File(testHistoryRoot, fileName));
    Collections.sort(fileNames, (f1, f2) -> f1.lastModified() > f2.lastModified() ? -1 : 1);
    final int historySize = fileNames.size();
    final AnAction[] actions = new AnAction[historySize + 2];
    for (int i = 0; i < historySize; i++) {
        actions[i] = new ImportTestsFromHistoryAction(myProperties, project, fileNames.get(i).getName());
    }
    actions[historySize] = Separator.getInstance();
    actions[historySize + 1] = new ImportTestsFromFileAction(myProperties);
    return actions;
}
Also used : Project(com.intellij.openapi.project.Project) File(java.io.File) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with AnAction

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

the class ActionLinkFixture method findByActionId.

@NotNull
public static ActionLinkFixture findByActionId(@NotNull final String actionId, @NotNull final Robot robot, @NotNull final Container container) {
    final Ref<ActionLink> actionLinkRef = new Ref<ActionLink>();
    pause(new Condition("Find ActionLink with ID '" + actionId + "'") {

        @Override
        public boolean test() {
            Collection<ActionLink> found = robot.finder().findAll(container, new GenericTypeMatcher<ActionLink>(ActionLink.class) {

                @Override
                protected boolean isMatching(@NotNull ActionLink actionLink) {
                    if (actionLink.isVisible()) {
                        AnAction action = actionLink.getAction();
                        String id = ActionManager.getInstance().getId(action);
                        return actionId.equals(id);
                    }
                    return false;
                }
            });
            if (found.size() == 1) {
                actionLinkRef.set(getFirstItem(found));
                return true;
            }
            return false;
        }
    }, SHORT_TIMEOUT);
    ActionLink actionLink = actionLinkRef.get();
    if (actionLink == null) {
        throw new ComponentLookupException("Failed to find ActionLink with ID '" + actionId + "'");
    }
    return new ActionLinkFixture(robot, actionLink);
}
Also used : Condition(org.fest.swing.timing.Condition) Ref(com.intellij.openapi.util.Ref) Collection(java.util.Collection) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) NotNull(org.jetbrains.annotations.NotNull) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionLink(com.intellij.ui.components.labels.ActionLink) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with AnAction

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

the class IdeFrameFixture method invokeMainMenu.

/**
   * Invokes an action from main menu
   *
   * @param mainMenuAction is the typical AnAction with ActionPlaces.MAIN_MENU
   */
public void invokeMainMenu(@NotNull String mainMenuActionId) {
    ActionManager actionManager = ActionManager.getInstance();
    AnAction mainMenuAction = actionManager.getAction(mainMenuActionId);
    JMenuBar jMenuBar = this.target().getRootPane().getJMenuBar();
    MouseEvent fakeMainMenuMouseEvent = new MouseEvent(jMenuBar, MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), 0, MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y, 1, false);
    ApplicationManager.getApplication().invokeLater(() -> actionManager.tryToExecute(mainMenuAction, fakeMainMenuMouseEvent, null, ActionPlaces.MAIN_MENU, true));
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) MouseEvent(java.awt.event.MouseEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 65 with AnAction

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

the class CompositeCommittedChangesProvider method createActions.

@Nullable
public VcsCommittedViewAuxiliary createActions(final DecoratorManager manager, final RepositoryLocation location) {
    JTabbedPane tabbedPane = null;
    List<AnAction> actions = null;
    List<AnAction> toolbarActions = null;
    final List<Runnable> calledOnDispose = new ArrayList<>();
    for (AbstractVcs baseVcs : myBaseVcss) {
        final CommittedChangesProvider provider = baseVcs.getCommittedChangesProvider();
        if (provider != null) {
            VcsCommittedViewAuxiliary auxiliary = provider.createActions(manager, location);
            if (auxiliary != null) {
                if (tabbedPane == null) {
                    tabbedPane = new JBTabbedPane();
                    actions = new ArrayList<>();
                    toolbarActions = new ArrayList<>();
                }
                actions.addAll(auxiliary.getPopupActions());
                toolbarActions.addAll(auxiliary.getToolbarActions());
                calledOnDispose.add(auxiliary.getCalledOnViewDispose());
            }
        }
    }
    if (tabbedPane != null) {
        final JPanel panel = new JPanel();
        panel.add(tabbedPane);
        return new VcsCommittedViewAuxiliary(actions, new Runnable() {

            public void run() {
                for (Runnable runnable : calledOnDispose) {
                    runnable.run();
                }
            }
        }, toolbarActions);
    }
    return null;
}
Also used : JBTabbedPane(com.intellij.ui.components.JBTabbedPane) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

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