Search in sources :

Example 61 with AnActionEvent

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

the class ShowGeneratedManifestTest method testMenuGroup.

@Test
public void testMenuGroup() {
    ViewGeneratedManifestGroup group = (ViewGeneratedManifestGroup) ActionManager.getInstance().getAction("osmorc.viewGeneratedManifests");
    assertNotNull(group);
    @SuppressWarnings("deprecation") DataContext context = DataManager.getInstance().getDataContext();
    AnActionEvent event = AnActionEvent.createFromAnAction(group, null, "", context);
    AnAction[] actions = group.getChildren(event);
    assertEquals(3, actions.length);
    Arrays.sort(actions, (o1, o2) -> Comparing.compare(o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText()));
    assertEquals("[t0] t0.jar", actions[0].getTemplatePresentation().getText());
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Test(org.junit.Test)

Example 62 with AnActionEvent

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

the class OptionsButton method addResetPreferencesActionTo.

private void addResetPreferencesActionTo(DefaultActionGroup actionGroup) {
    myResetSettingsAction = new AnAction("Reset to default settings") {

        public void actionPerformed(AnActionEvent e) {
            try {
                Preferences preferences = Preferences.userRoot().node("jetbrains.communicator");
                preferences.removeNode();
                preferences.flush();
            } catch (BackingStoreException e1) {
                LOG.error(e1.getMessage(), e1);
            }
        }
    };
    actionGroup.add(myResetSettingsAction);
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Preferences(java.util.prefs.Preferences) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 63 with AnActionEvent

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

the class ManifestPanel method registerGotoAction.

private void registerGotoAction() {
    AnAction goToDeclarationAction = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            ManifestTreeNode node = (ManifestTreeNode) myTree.getLastSelectedPathComponent();
            if (node != null) {
                goToDeclaration(node.getUserObject());
            }
        }
    };
    goToDeclarationAction.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_GOTO_DECLARATION).getShortcutSet(), myTree);
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 64 with AnActionEvent

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

the class AnalysisResultsManager method createActions.

@NotNull
@Override
protected AnAction[] createActions() {
    return new AnAction[] { new ToggleAction(AndroidBundle.message("android.captures.analysis.results.manager.run.name"), AndroidBundle.message("android.captures.analysis.results.manager.run.description"), AllIcons.Toolwindows.ToolWindowRun) {

        @Override
        public boolean isSelected(AnActionEvent e) {
            AnalysisResultsContent analysisResultsContent = getContentFromDesigner();
            return analysisResultsContent != null && !analysisResultsContent.canRunAnalysis();
        }

        @Override
        public void setSelected(AnActionEvent e, boolean state) {
            if (state) {
                AnalysisResultsContent analysisResultsContent = getContentFromDesigner();
                if (analysisResultsContent != null && analysisResultsContent.canRunAnalysis()) {
                    analysisResultsContent.performAnalysis();
                }
            }
        }

        @Override
        public void update(@NotNull AnActionEvent e) {
            super.update(e);
            Presentation presentation = e.getPresentation();
            if (isSelected(e)) {
                presentation.setText(AndroidBundle.message("android.captures.analysis.results.manager.run.disabled.name"));
                presentation.setDescription(AndroidBundle.message("android.captures.analysis.results.manager.run.disabled.description"));
                presentation.setIcon(AllIcons.Process.DisabledRun);
            } else {
                presentation.setText(AndroidBundle.message("android.captures.analysis.results.manager.run.enabled.name"));
                presentation.setDescription(AndroidBundle.message("android.captures.analysis.results.manager.run.enabled.description"));
                presentation.setIcon(AllIcons.Toolwindows.ToolWindowRun);
            }
        }
    } };
}
Also used : ToggleAction(com.intellij.openapi.actionSystem.ToggleAction) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with AnActionEvent

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

the class AndroidBaseXmlRefactoringAction method update.

@Override
public void update(AnActionEvent e) {
    final DataContext context = e.getDataContext();
    final DataContext patchedContext = new DataContext() {

        @Override
        public Object getData(@NonNls String dataId) {
            final Object data = context.getData(dataId);
            if (data != null) {
                return data;
            }
            if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
                final XmlTag[] tags = getXmlTagsFromExternalContext(context);
                return tags.length == 1 ? tags[0] : null;
            } else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
                return getXmlTagsFromExternalContext(context);
            }
            return null;
        }
    };
    super.update(new AnActionEvent(e.getInputEvent(), patchedContext, e.getPlace(), e.getPresentation(), e.getActionManager(), e.getModifiers()));
}
Also used : NonNls(org.jetbrains.annotations.NonNls) DataContext(com.intellij.openapi.actionSystem.DataContext) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) XmlTag(com.intellij.psi.xml.XmlTag)

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