Search in sources :

Example 6 with ActionManager

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

the class CustomActionsSchema method initActionIcons.

private void initActionIcons() {
    ActionManager actionManager = ActionManager.getInstance();
    for (String actionId : myIconCustomizations.keySet()) {
        final AnAction anAction = actionManager.getAction(actionId);
        if (anAction != null) {
            Icon icon;
            final String iconPath = myIconCustomizations.get(actionId);
            if (iconPath != null && new File(FileUtil.toSystemDependentName(iconPath)).exists()) {
                Image image = null;
                try {
                    image = ImageLoader.loadFromStream(VfsUtilCore.convertToURL(VfsUtil.pathToUrl(iconPath)).openStream());
                } catch (IOException e) {
                    LOG.debug(e);
                }
                icon = image == null ? null : new JBImageIcon(image);
            } else {
                icon = AllIcons.Toolbar.Unknown;
            }
            anAction.getTemplatePresentation().setIcon(icon);
            anAction.getTemplatePresentation().setDisabledIcon(IconLoader.getDisabledIcon(icon));
            anAction.setDefaultIcon(false);
        }
    }
    final IdeFrameImpl frame = WindowManagerEx.getInstanceEx().getFrame(null);
    if (frame != null) {
        frame.updateView();
    }
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) JBImageIcon(com.intellij.util.ui.JBImageIcon) IOException(java.io.IOException) JBImageIcon(com.intellij.util.ui.JBImageIcon) AnAction(com.intellij.openapi.actionSystem.AnAction) File(java.io.File)

Example 7 with ActionManager

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

the class WindowSystemPlaybackCall method contextMenu.

public static AsyncResult<String> contextMenu(final PlaybackContext context, final String path) {
    final AsyncResult<String> result = new AsyncResult<>();
    final IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
    fm.doWhenFocusSettlesDown(() -> {
        Component owner = fm.getFocusOwner();
        if (owner == null) {
            result.setRejected("No component focused");
            return;
        }
        ActionManager am = ActionManager.getInstance();
        AnAction showPopupMenu = am.getAction("ShowPopupMenu");
        if (showPopupMenu == null) {
            result.setRejected("Cannot find action: ShowPopupMenu");
            return;
        }
        am.tryToExecute(showPopupMenu, new MouseEvent(owner, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, 0, 0, 1, true), null, null, false).doWhenDone(() -> SwingUtilities.invokeLater(() -> {
            MenuElement[] selectedPath = MenuSelectionManager.defaultManager().getSelectedPath();
            if (selectedPath.length == 0) {
                result.setRejected("Failed to find active popup menu");
                return;
            }
            selectNext(context, path.split("\\|"), 0, selectedPath[0].getSubElements(), result);
        })).doWhenRejected(() -> result.setRejected("Cannot invoke popup menu from the ShowPopupMenu action, action call rejected"));
    });
    return result;
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) MouseEvent(java.awt.event.MouseEvent) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) AsyncResult(com.intellij.openapi.util.AsyncResult) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 8 with ActionManager

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

the class StatusPanel method createCopyAction.

private Action createCopyAction() {
    ActionManager actionManager = ActionManager.getInstance();
    if (actionManager == null)
        return null;
    AnAction action = actionManager.getAction(IdeActions.ACTION_COPY);
    if (action == null)
        return null;
    return new AbstractAction(action.getTemplatePresentation().getText(), action.getTemplatePresentation().getIcon()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            StringSelection content = new StringSelection(getText());
            ClipboardSynchronizer.getInstance().setContent(content, content);
        }

        @Override
        public boolean isEnabled() {
            return !getText().isEmpty();
        }
    };
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) ActionEvent(java.awt.event.ActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) StringSelection(java.awt.datatransfer.StringSelection)

Example 9 with ActionManager

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

the class FileSystemTreeFactoryImpl method createDefaultFileSystemActions.

public DefaultActionGroup createDefaultFileSystemActions(FileSystemTree fileSystemTree) {
    DefaultActionGroup group = new DefaultActionGroup();
    final ActionManager actionManager = ActionManager.getInstance();
    group.add(actionManager.getAction("FileChooser.GotoHome"));
    group.add(actionManager.getAction("FileChooser.GotoProject"));
    group.addSeparator();
    group.add(actionManager.getAction("FileChooser.NewFolder"));
    group.add(actionManager.getAction("FileChooser.Delete"));
    group.addSeparator();
    SynchronizeAction action1 = new SynchronizeAction();
    AnAction original = actionManager.getAction(IdeActions.ACTION_SYNCHRONIZE);
    action1.copyFrom(original);
    action1.registerCustomShortcutSet(original.getShortcutSet(), fileSystemTree.getTree());
    group.add(action1);
    group.addSeparator();
    group.add(actionManager.getAction("FileChooser.ShowHiddens"));
    return group;
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) SynchronizeAction(com.intellij.ide.actions.SynchronizeAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 10 with ActionManager

use of com.intellij.openapi.actionSystem.ActionManager 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)

Aggregations

ActionManager (com.intellij.openapi.actionSystem.ActionManager)43 AnAction (com.intellij.openapi.actionSystem.AnAction)27 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)15 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)4 ActionToolbar (com.intellij.openapi.actionSystem.ActionToolbar)4 MouseEvent (java.awt.event.MouseEvent)4 Keymap (com.intellij.openapi.keymap.Keymap)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ActionPopupMenu (com.intellij.openapi.actionSystem.ActionPopupMenu)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 ActionManagerImpl (com.intellij.openapi.actionSystem.impl.ActionManagerImpl)2 Application (com.intellij.openapi.application.Application)2 ToolWindow (com.intellij.openapi.wm.ToolWindow)2 IntellijAzureActionManager (com.microsoft.azure.toolkit.intellij.common.action.IntellijAzureActionManager)2 File (java.io.File)2 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)1 CloudDebugHelpAction (com.google.cloud.tools.intellij.debugger.actions.CloudDebugHelpAction)1 DataManager (com.intellij.ide.DataManager)1