Search in sources :

Example 36 with AnAction

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

the class EditorNotificationPanel method executeAction.

protected void executeAction(final String actionId) {
    final AnAction action = ActionManager.getInstance().getAction(actionId);
    final AnActionEvent event = AnActionEvent.createFromAnAction(action, null, ActionPlaces.UNKNOWN, DataManager.getInstance().getDataContext(this));
    action.beforeActionPerformedUpdate(event);
    action.update(event);
    if (event.getPresentation().isEnabled() && event.getPresentation().isVisible()) {
        action.actionPerformed(event);
    }
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 37 with AnAction

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

the class CustomizableActionsPanel method editToolbarIcon.

private void editToolbarIcon(String actionId, DefaultMutableTreeNode node) {
    final AnAction anAction = ActionManager.getInstance().getAction(actionId);
    if (isToolbarAction(node) && anAction.getTemplatePresentation().getIcon() == null) {
        final int exitCode = Messages.showOkCancelDialog(IdeBundle.message("error.adding.action.without.icon.to.toolbar"), IdeBundle.message("title.unable.to.add.action.without.icon.to.toolbar"), Messages.getInformationIcon());
        if (exitCode == Messages.OK) {
            mySelectedSchema.addIconCustomization(actionId, null);
            anAction.getTemplatePresentation().setIcon(AllIcons.Toolbar.Unknown);
            anAction.getTemplatePresentation().setDisabledIcon(IconLoader.getDisabledIcon(AllIcons.Toolbar.Unknown));
            anAction.setDefaultIcon(false);
            node.setUserObject(Pair.create(actionId, AllIcons.Toolbar.Unknown));
            myActionsTree.repaint();
            CustomActionsSchema.setCustomizationSchemaForCurrentProjects();
        }
    }
}
Also used : AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 38 with AnAction

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

the class CustomizableActionsPanel method doSetIcon.

protected boolean doSetIcon(DefaultMutableTreeNode node, @Nullable String path, Component component) {
    if (StringUtil.isNotEmpty(path) && !new File(path).isFile()) {
        Messages.showErrorDialog(component, IdeBundle.message("error.file.not.found.message", path), IdeBundle.message("title.choose.action.icon"));
        return false;
    }
    String actionId = getActionId(node);
    if (actionId == null)
        return false;
    final AnAction action = ActionManager.getInstance().getAction(actionId);
    if (action != null) {
        if (StringUtil.isNotEmpty(path)) {
            Image image = null;
            try {
                image = ImageLoader.loadFromStream(VfsUtilCore.convertToURL(VfsUtilCore.pathToUrl(path.replace(File.separatorChar, '/'))).openStream());
            } catch (IOException e) {
                LOG.debug(e);
            }
            Icon icon = new File(path).exists() ? IconLoader.getIcon(image) : null;
            if (icon != null) {
                if (icon.getIconWidth() > EmptyIcon.ICON_18.getIconWidth() || icon.getIconHeight() > EmptyIcon.ICON_18.getIconHeight()) {
                    Messages.showErrorDialog(component, IdeBundle.message("custom.icon.validation.message"), IdeBundle.message("title.choose.action.icon"));
                    return false;
                }
                node.setUserObject(Pair.create(actionId, icon));
                mySelectedSchema.addIconCustomization(actionId, path);
            }
        } else {
            node.setUserObject(Pair.create(actionId, null));
            mySelectedSchema.removeIconCustomization(actionId);
            final DefaultMutableTreeNode nodeOnToolbar = findNodeOnToolbar(actionId);
            if (nodeOnToolbar != null) {
                editToolbarIcon(actionId, nodeOnToolbar);
                node.setUserObject(nodeOnToolbar.getUserObject());
            }
        }
        return true;
    }
    return false;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IOException(java.io.IOException) EmptyIcon(com.intellij.util.ui.EmptyIcon) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 39 with AnAction

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

the class ActionUrl method readExternal.

@Override
public void readExternal(Element element) throws InvalidDataException {
    myGroupPath = new ArrayList<>();
    for (Object o : element.getChildren(PATH)) {
        myGroupPath.add(((Element) o).getAttributeValue(VALUE));
    }
    final String attributeValue = element.getAttributeValue(VALUE);
    if (element.getAttributeValue(IS_ACTION) != null) {
        myComponent = attributeValue;
    } else if (element.getAttributeValue(SEPARATOR) != null) {
        myComponent = Separator.getInstance();
    } else if (element.getAttributeValue(IS_GROUP) != null) {
        final AnAction action = ActionManager.getInstance().getAction(attributeValue);
        myComponent = action instanceof ActionGroup ? ActionsTreeUtil.createGroup((ActionGroup) action, true, null) : new Group(attributeValue, attributeValue, null);
    }
    myActionType = Integer.parseInt(element.getAttributeValue(ACTION_TYPE));
    myAbsolutePosition = Integer.parseInt(element.getAttributeValue(POSITION));
    DefaultJDOMExternalizer.readExternal(this, element);
}
Also used : ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) Group(com.intellij.openapi.keymap.impl.ui.Group) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 40 with AnAction

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

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