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);
}
}
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();
}
}
}
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;
}
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);
}
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();
}
}
Aggregations