Java Code Examples for com.intellij.openapi.actionSystem.AnAction#getTemplatePresentation()
The following examples show how to use
com.intellij.openapi.actionSystem.AnAction#getTemplatePresentation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlutterRetargetAppAction.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); final Project project = e.getProject(); if (project == null || !FlutterModuleUtils.hasFlutterModule(project) || !myPlaces.contains(e.getPlace())) { presentation.setVisible(false); return; } presentation.setVisible(true); presentation.setEnabled(false); // Retargeted actions defer to their targets for presentation updates. final AnAction action = getAction(project); if (action != null) { final Presentation template = action.getTemplatePresentation(); final String text = template.getTextWithMnemonic(); if (text != null) { presentation.setText(text, true); } action.update(e); } }
Example 2
Source File: FlutterRetargetAppAction.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); final Project project = e.getProject(); if (project == null || !FlutterModuleUtils.hasFlutterModule(project) || !myPlaces.contains(e.getPlace())) { presentation.setVisible(false); return; } presentation.setVisible(true); presentation.setEnabled(false); // Retargeted actions defer to their targets for presentation updates. final AnAction action = getAction(project); if (action != null) { final Presentation template = action.getTemplatePresentation(); final String text = template.getTextWithMnemonic(); if (text != null) { presentation.setText(text, true); } action.update(e); } }
Example 3
Source File: PresentationFactory.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public final Presentation getPresentation(@Nonnull AnAction action){ UIAccess.assertIsUIThread(); Presentation presentation = myAction2Presentation.get(action); if (presentation == null || !action.isDefaultIcon()){ Presentation templatePresentation = action.getTemplatePresentation(); if (presentation == null) { presentation = templatePresentation.clone(); myAction2Presentation.put(action, presentation); } if (!action.isDefaultIcon()) { presentation.setIcon(templatePresentation.getIcon()); presentation.setDisabledIcon(templatePresentation.getDisabledIcon()); } processPresentation(presentation); } return presentation; }
Example 4
Source File: CustomizableActionsPanel.java From consulo with Apache License 2.0 | 6 votes |
private void editToolbarIcon(String actionId, DefaultMutableTreeNode node) { final AnAction anAction = ActionManager.getInstance().getAction(actionId); if (isToolbarAction(node) && anAction.getTemplatePresentation() != null && 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.setDefaultIcon(false); node.setUserObject(Pair.create(actionId, AllIcons.Toolbar.Unknown)); myActionsTree.repaint(); setCustomizationSchemaForCurrentProjects(); } } }
Example 5
Source File: CustomizableActionsPanel.java From consulo with Apache License 2.0 | 6 votes |
protected void enableSetIconButton(ActionManager actionManager) { final TreePath selectionPath = myTree.getSelectionPath(); Object userObject = null; if (selectionPath != null) { userObject = ((DefaultMutableTreeNode)selectionPath.getLastPathComponent()).getUserObject(); if (userObject instanceof String) { final AnAction action = actionManager.getAction((String)userObject); if (action != null && action.getTemplatePresentation() != null && action.getTemplatePresentation().getIcon() != null) { mySetIconButton.setEnabled(true); return; } } } mySetIconButton.setEnabled(myTextField.getText().length() != 0 && selectionPath != null && new DefaultMutableTreeNode(selectionPath).isLeaf() && !(userObject instanceof AnSeparator)); }
Example 6
Source File: LombokLightActionTestCase.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void performActionTest() throws TimeoutException, ExecutionException { AnAction anAction = getAction(); Promise<DataContext> contextResult = DataManager.getInstance().getDataContextFromFocusAsync(); AnActionEvent anActionEvent = new AnActionEvent(null, contextResult.blockingGet(10, TimeUnit.SECONDS), "", anAction.getTemplatePresentation(), ActionManager.getInstance(), 0); anAction.actionPerformed(anActionEvent); FileDocumentManager.getInstance().saveAllDocuments(); }
Example 7
Source File: EditorNotificationPanel.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess protected void executeAction(final String actionId) { final AnAction action = ActionManager.getInstance().getAction(actionId); final AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(this), ActionPlaces.UNKNOWN, action.getTemplatePresentation(), ActionManager.getInstance(), 0); action.beforeActionPerformedUpdate(event); action.update(event); if (event.getPresentation().isEnabled() && event.getPresentation().isVisible()) { action.actionPerformed(event); } }
Example 8
Source File: CustomActionsSchema.java From consulo with Apache License 2.0 | 5 votes |
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(VfsUtil.convertToURL(VfsUtil.pathToUrl(iconPath)).openStream()); } catch (IOException e) { LOG.debug(e); } icon = image != null ? IconLoader.getIcon(image) : null; } else { icon = AllIcons.Toolbar.Unknown; } if (anAction.getTemplatePresentation() != null) { anAction.getTemplatePresentation().setIcon(icon); anAction.setDefaultIcon(false); } } } final IdeFrameEx frame = WindowManagerEx.getInstanceEx().getIdeFrame(null); if (frame != null) { frame.updateView(); } }
Example 9
Source File: TestActionEvent.java From consulo with Apache License 2.0 | 4 votes |
public TestActionEvent(@Nonnull DataContext dataContext, @Nonnull AnAction action) { super(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0); }
Example 10
Source File: CustomizableActionsPanel.java From consulo with Apache License 2.0 | 4 votes |
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 && action.getTemplatePresentation() != null) { if (StringUtil.isNotEmpty(path)) { Image image = null; try { image = ImageLoader.loadFromStream(VfsUtil.convertToURL(VfsUtil.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; }