Search in sources :

Example 81 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-plugins by JetBrains.

the class FlexExtractSuperTest method checkAction.

private void checkAction(String actionId, boolean enabled, int pos) {
    AnAction action = ActionManager.getInstance().getAction(actionId);
    AnActionEvent e = new TestActionEvent(DataManager.getInstance().getDataContext(getEditor().getComponent()), action);
    action.beforeActionPerformedUpdate(e);
    assertEquals("Action " + actionId + " should be " + (enabled ? "enabled" : "disabled") + " at position " + pos, enabled, e.getPresentation().isEnabled());
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 82 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-plugins by JetBrains.

the class OpenFileActionTest method assertEnabled.

private void assertEnabled(String msg, boolean enabled) throws IllegalAccessException, InvocationTargetException, InstantiationException {
    AnActionEvent e = createActionEvent(myOpenFileAction.getTemplatePresentation());
    myOpenFileAction.update(e);
    assertEquals(msg, enabled, e.getPresentation().isEnabled());
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent)

Example 83 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-plugins by JetBrains.

the class ShowUiRouterStatesNewDiagramAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    UsageTrigger.trigger(USAGE_KEY);
    final Project project = e.getProject();
    if (project == null)
        return;
    final AngularUiRouterDiagramProvider diagramProvider = (AngularUiRouterDiagramProvider) DiagramProvider.findByID(AngularUiRouterDiagramProvider.ANGULAR_UI_ROUTER);
    if (diagramProvider == null)
        return;
    List<Pair<String, AngularUiRouterGraphBuilder>> graphBuilders = new ArrayList<>();
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        ApplicationManager.getApplication().runReadAction(() -> {
            final AngularUiRouterDiagramBuilder builder = new AngularUiRouterDiagramBuilder(project);
            builder.build();
            final Map<VirtualFile, RootTemplate> rootTemplates = builder.getRootTemplates();
            for (Map.Entry<VirtualFile, Map<String, UiRouterState>> entry : builder.getDefiningFiles2States().entrySet()) {
                final AngularUiRouterGraphBuilder graphBuilder = new AngularUiRouterGraphBuilder(project, entry.getValue(), builder.getTemplatesMap(), null, entry.getKey());
                graphBuilders.add(Pair.create(entry.getKey().getName(), graphBuilder));
            }
            for (Map.Entry<VirtualFile, Map<String, UiRouterState>> entry : builder.getRootTemplates2States().entrySet()) {
                final AngularUiRouterGraphBuilder graphBuilder = new AngularUiRouterGraphBuilder(project, entry.getValue(), builder.getTemplatesMap(), rootTemplates.get(entry.getKey()), entry.getKey());
                graphBuilders.add(Pair.create(entry.getKey().getName(), graphBuilder));
            }
        });
    }, "Building " + diagramProvider.getPresentableName() + " diagram", false, project);
    final AngularUiRouterProviderContext routerProviderContext = AngularUiRouterProviderContext.getInstance(project);
    routerProviderContext.reset();
    final Consumer<AngularUiRouterGraphBuilder> consumer = graphBuilder -> {
        final AngularUiRouterGraphBuilder.GraphNodesBuilder nodesBuilder = graphBuilder.createDataModel(diagramProvider);
        routerProviderContext.registerNodesBuilder(nodesBuilder);
        final DiagramObject element = nodesBuilder.getRootNode().getIdentifyingElement();
        final Runnable callback = show(element, diagramProvider, project, null, Collections.emptyList());
        if (callback != null) {
            callback.run();
        }
    };
    if (graphBuilders.isEmpty()) {
        Messages.showInfoMessage(project, "No router states found.", DESCRIPTION);
        return;
    }
    if (graphBuilders.size() == 1)
        consumer.consume(graphBuilders.get(0).getSecond());
    else
        filterGraphBuilders(project, graphBuilders, consumer);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DiagramProvider(com.intellij.diagram.DiagramProvider) ProgressManager(com.intellij.openapi.progress.ProgressManager) JBList(com.intellij.ui.components.JBList) ArrayUtil(com.intellij.util.ArrayUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AngularJSIcons(icons.AngularJSIcons) ArrayList(java.util.ArrayList) List(java.util.List) AngularIndexUtil(org.angularjs.index.AngularIndexUtil) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ShowDiagram(com.intellij.uml.core.actions.ShowDiagram) Map(java.util.Map) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) UsageTrigger(com.intellij.internal.statistic.UsageTrigger) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) Map(java.util.Map) Pair(com.intellij.openapi.util.Pair)

Example 84 with AnActionEvent

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

the class NlBooleanIconEditor method setProperty.

public void setProperty(@NotNull NlProperty property) {
    myAction.setProperty(property);
    updateDescription(property);
    // This will update the selected state of the ActionButton:
    AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(myButton), INSPECTOR_PLACE, myPresentation, ActionManager.getInstance(), 0);
    ActionUtil.performDumbAwareUpdate(myAction, event, false);
    myButton.updateIcon();
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent)

Example 85 with AnActionEvent

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

the class ImportTree method createExcludeAction.

public AnAction createExcludeAction() {
    return new AnAction(CvsBundle.message("import.wizard.exclude.from.import.action.name"), null, PlatformIcons.DELETE_ICON) {

        public void update(AnActionEvent e) {
            final VirtualFile[] selectedFiles = myFileSystemTree.getSelectedFiles();
            final Presentation presentation = e.getPresentation();
            presentation.setEnabled(isAtLeastOneFileIncluded(selectedFiles));
        }

        public void actionPerformed(AnActionEvent e) {
            final VirtualFile[] selectedFiles = myFileSystemTree.getSelectedFiles();
            for (VirtualFile selectedFile : selectedFiles) {
                exclude(selectedFile);
            }
            myWizard.updateStep();
            myFileSystemTree.getTree().repaint();
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)130 AnAction (com.intellij.openapi.actionSystem.AnAction)67 Project (com.intellij.openapi.project.Project)27 NotNull (org.jetbrains.annotations.NotNull)25 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 Nullable (org.jetbrains.annotations.Nullable)20 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)15 List (java.util.List)14 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)8 JBTable (com.intellij.ui.table.JBTable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)7 Pair (com.intellij.openapi.util.Pair)7 Logger (com.intellij.openapi.diagnostic.Logger)6 Ref (com.intellij.openapi.util.Ref)6 AnActionButton (com.intellij.ui.AnActionButton)6