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