Java Code Examples for com.intellij.openapi.actionSystem.ActionManager#getInstance()

The following examples show how to use com.intellij.openapi.actionSystem.ActionManager#getInstance() . 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: BuckToolWindowImpl.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public ActionGroup getLeftToolbarActions() {
  ActionManager actionManager = ActionManager.getInstance();

  DefaultActionGroup group = new DefaultActionGroup();

  group.add(actionManager.getAction("buck.ChooseTarget"));
  group.addSeparator();
  group.add(actionManager.getAction("buck.Build"));
  group.add(actionManager.getAction("buck.Stop"));
  group.add(actionManager.getAction("buck.Test"));
  group.add(actionManager.getAction("buck.Install"));
  group.add(actionManager.getAction("buck.Uninstall"));
  group.add(actionManager.getAction("buck.Kill"));
  group.add(actionManager.getAction("buck.ScrollToEnd"));
  group.add(actionManager.getAction("buck.Clear"));

  return group;
}
 
Example 2
Source File: AbstractConnectionAction.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
protected void doPurge(@NotNull final Project project, @NotNull final ProgressHandler progressHandler) {
    // First Run the Purge Cache
    ActionManager actionManager = ActionManager.getInstance();
    final ResetConfigurationAction resetConfigurationAction = (ResetConfigurationAction) actionManager.getAction("AEM.Purge.Cache.Action");
    WaitableRunner<Void> runner;
    if(resetConfigurationAction != null) {
        runner = new WaitableRunner<Void>() {
            @Override
            public void run() {
                resetConfigurationAction.doReset(project, progressHandler);
            }
            @Override
            public void handleException(Exception e) {
                // Catch and report unexpected exception as debug message to keep it going
                getMessageManager(project).sendErrorNotification("server.configuration.purge.failed.unexpected", e);
            }
            @Override
            public boolean isAsynchronous() {
                return AbstractConnectionAction.this.isAsynchronous();
            }
        };
        runAndWait(runner);
    }
}
 
Example 3
Source File: StatusPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
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();
    }
  };
}
 
Example 4
Source File: CustomizableActionsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void doOKAction() {
  final ActionManager actionManager = ActionManager.getInstance();
  TreeUtil.traverseDepth((TreeNode)myTree.getModel().getRoot(), new TreeUtil.Traverse() {
    public boolean accept(Object node) {
      if (node instanceof DefaultMutableTreeNode) {
        final DefaultMutableTreeNode mutableNode = (DefaultMutableTreeNode)node;
        final Object userObject = mutableNode.getUserObject();
        if (userObject instanceof Pair) {
          String actionId = (String)((Pair)userObject).first;
          final AnAction action = actionManager.getAction(actionId);
          Icon icon = (Icon)((Pair)userObject).second;
          action.getTemplatePresentation().setIcon(icon);
          action.setDefaultIcon(icon == null);
          editToolbarIcon(actionId, mutableNode);
        }
      }
      return true;
    }
  });
  super.doOKAction();
  setCustomizationSchemaForCurrentProjects();
}
 
Example 5
Source File: NewBashFileActionTest.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeDialog() throws IOException {
    ActionManager actionManager = ActionManager.getInstance();
    final NewBashFileAction action = (NewBashFileAction) actionManager.getAction("Bash.NewBashScript");

    VirtualFile directoryVirtualFile = myFixture.getTempDirFixture().findOrCreateDir("");
    final PsiDirectory directory = myFixture.getPsiManager().findDirectory(directoryVirtualFile);

    try {
        action.invokeDialog(directory.getProject(), directory);
        Assert.fail("dialog wasn't invoked");
    } catch (Throwable e) {
        //the dialog invocation is raised as an exception in test mode
        Assert.assertTrue(e.getMessage().contains("Create a new Bash file"));
    }

}
 
Example 6
Source File: TitleWithToolbar.java    From consulo with Apache License 2.0 5 votes vote down vote up
public TitleWithToolbar(@Nonnull String title,
                        @Nonnull String actionGroupId,
                        @Nonnull String place,
                        @Nonnull JComponent targetComponent)
{
  super(new GridBagLayout());
  ActionManager actionManager = ActionManager.getInstance();
  ActionGroup group = (ActionGroup)actionManager.getAction(actionGroupId);
  ActionToolbar actionToolbar = actionManager.createActionToolbar(place, group, true);
  actionToolbar.setTargetComponent(targetComponent);
  actionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);

  add(new MyTitleComponent(title), new GridBag().weightx(1).anchor(GridBagConstraints.WEST).fillCellHorizontally());
  add(actionToolbar.getComponent(), new GridBag().anchor(GridBagConstraints.CENTER));
}
 
Example 7
Source File: NewBashFileActionTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewFile() throws Exception {
    ActionManager actionManager = ActionManager.getInstance();
    final NewBashFileAction action = (NewBashFileAction) actionManager.getAction("Bash.NewBashScript");

    // @see https://devnet.jetbrains.com/message/5539349#5539349
    VirtualFile directoryVirtualFile = myFixture.getTempDirFixture().findOrCreateDir("");
    final PsiDirectory directory = myFixture.getPsiManager().findDirectory(directoryVirtualFile);

    Assert.assertEquals(BashStrings.message("newfile.command.name"), action.getCommandName());
    Assert.assertEquals(BashStrings.message("newfile.menu.action.text"), action.getActionName(directory, ""));

    PsiElement result = ApplicationManager.getApplication().runWriteAction(new Computable<PsiElement>() {
        @Override
        public PsiElement compute() {
            try {
                PsiElement[] elements = action.create("bash_file", directory);
                return elements.length >= 1 ? elements[0] : null; //the firet element is the BashFile
            } catch (Exception e) {
                return null;
            }
        }
    });

    assertNotNull("Expected a newly created bash file", result);
    assertTrue("Expected a newly created bash file", result instanceof BashFile);

    VirtualFile vFile = ((BashFile) result).getVirtualFile();
    File ioFile = VfsUtilCore.virtualToIoFile(vFile);
    assertTrue("Expected that the new file is executable", ioFile.canExecute());

    Assert.assertEquals("Expected default bash file template content", "#!/usr/bin/env bash", result.getText());
}
 
Example 8
Source File: BuckToolWindowFactory.java    From Buck-IntelliJ-Plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
public ActionGroup getLeftToolbarActions(final Project project) {
  ActionManager actionManager = ActionManager.getInstance();

  DefaultActionGroup group = new DefaultActionGroup();
  group.add(actionManager.getAction("buck.ChooseTarget"));
  group.addSeparator();
  group.add(actionManager.getAction("buck.Install"));
  group.add(actionManager.getAction("buck.Build"));
  group.add(actionManager.getAction("buck.Kill"));
  group.add(actionManager.getAction("buck.Uninstall"));
  group.add(actionManager.getAction("buck.Project"));
  return group;
}
 
Example 9
Source File: MacGestureAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void swipedLeft(SwipeEvent event) {
  ActionManager actionManager = ActionManager.getInstance();
  AnAction forward = actionManager.getAction("Forward");
  if (forward == null) return;

  actionManager.tryToExecute(forward, createMouseEventWrapper(myFrame), null, null, false);
}
 
Example 10
Source File: SlingPluginExplorer.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
private JPanel createToolbarPanel(SlingServerTreeManager treeManager) {
    ActionManager actionManager = ActionManager.getInstance();
    DefaultActionGroup group = new DefaultActionGroup();
    group.add(actionManager.getAction("AEM.Toolbar"));
    treeManager.adjustToolbar(group);

    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.TOOLBAR, group, true);

    final JPanel buttonsPanel = new JPanel(new BorderLayout());
    buttonsPanel.add(actionToolbar.getComponent(), BorderLayout.CENTER);
    return buttonsPanel;
}
 
Example 11
Source File: CustomActionsSchema.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void fillActionGroups(DefaultMutableTreeNode root) {
  final ActionManager actionManager = ActionManager.getInstance();
  for (Pair pair : myIdToNameList) {
    final ActionGroup actionGroup = (ActionGroup)actionManager.getAction(pair.first);
    if (actionGroup != null) { //J2EE/Commander plugin was disabled
      root.add(ActionsTreeUtil.createNode(ActionsTreeUtil.createGroup(actionGroup, pair.second, null, null, true, null, false)));
    }
  }
}
 
Example 12
Source File: TreeMouseListener.java    From leetcode-editor with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {

    TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
    if (selPath != null) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent();
        Question question = (Question) node.getUserObject();
        if ("lock".equals(question.getStatus())) {
            return;
        }
        if (question.isLeaf()) {
            if (e.getButton() == 3) { //鼠标右键
                final ActionManager actionManager = ActionManager.getInstance();
                final ActionGroup actionGroup = (ActionGroup) actionManager.getAction("leetcode.NavigatorActionsMenu");
                if (actionGroup != null) {
                    actionManager.createActionPopupMenu("", actionGroup).getComponent().show(e.getComponent(), e.getX(), e.getY());
                }
            } else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                ProgressManager.getInstance().run(new Task.Backgroundable(project,"leetcode.editor.openCode",false) {
                    @Override
                    public void run(@NotNull ProgressIndicator progressIndicator) {
                        CodeManager.openCode(question, project);
                    }
                });
            }
        }
    }


}
 
Example 13
Source File: CustomActionsSchema.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 14
Source File: ActionsTopHitProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void consumeTopHits(String pattern, Consumer<Object> collector, Project project) {
  final ActionManager actionManager = ActionManager.getInstance();
  for (String[] strings : getActionsMatrix()) {
    if (StringUtil.isBetween(pattern, strings[0], strings[1])) {
      for (int i = 2; i < strings.length; i++) {
        collector.accept(actionManager.getAction(strings[i]));
      }
    }
  }
}
 
Example 15
Source File: AppComponent.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
@Override
public void initComponent() {
    checkAndCreateRootDir();

    ActionManager am = ActionManager.getInstance();
    ArrayList<PackageTemplate> listPackageTemplate = PackageTemplateHelper.getListPackageTemplate();

    for (PackageTemplate pt : listPackageTemplate) {
        if (!pt.isShouldRegisterAction()) {
            continue;
        }
        RunTemplateAction action = new RunTemplateAction(pt.getName(), pt);
        am.registerAction(Const.ACTION_PREFIX + action.getName(), action);
    }
}
 
Example 16
Source File: ShortcutStartupActivity.java    From StringManipulation with Apache License 2.0 5 votes vote down vote up
public static void unRegisterActions(List<CustomActionModel> customActionModels) {
	ActionManager instance = ActionManager.getInstance();
	DefaultActionGroup group = (DefaultActionGroup) instance.getAction("StringManipulation.Group.SwitchCase");
	for (CustomActionModel actionModel : customActionModels) {
		String id = actionModel.getId();
		if (StringUtils.isNotBlank(id)) {
			unRegisterAction(instance, id, group);
			unRegisterAction(instance, id + CustomActionModel.REVERSE, group);
		}
	}
}
 
Example 17
Source File: LombokLightActionTestCase.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 18
Source File: TestActionEvent.java    From consulo with Apache License 2.0 4 votes vote down vote up
public TestActionEvent(@Nonnull DataContext dataContext,
                       @Nonnull AnAction action) {
  super(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
}
 
Example 19
Source File: WindowTool.java    From ADB-Duang with MIT License 4 votes vote down vote up
private void actionPerform(String action) {
    ActionManager am = ActionManager.getInstance();
    am.tryToExecute(am.getAction(action),
            ActionCommand.getInputEvent(action), panel1, "", true);

}
 
Example 20
Source File: PantsCompileActionGroup.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent event) {
  //  Deletes existing make and compile options.
  ActionManager actionManager = ActionManager.getInstance();

  // TODO: don't remove these actions or put on our own unless we're in a
  // pants project, so we don't clobber these actions in a non-pants project
  DefaultActionGroup actionGroup = (DefaultActionGroup) actionManager.getAction(PantsConstants.ACTION_COMPILE_GROUP_ID);
  actionGroup.remove(actionManager.getAction(IdeActions.ACTION_MAKE_MODULE));
  actionGroup.remove(actionManager.getAction(IdeActions.ACTION_COMPILE));

  final AnAction[] emptyAction = new AnAction[0];

  if (event == null) {
    return emptyAction;
  }
  Project project = event.getProject();
  Optional<VirtualFile> eventFile = PantsUtil.getFileForEvent(event);
  // TODO: signal if no project found?
  if (project == null || !eventFile.isPresent()) {
    return emptyAction;
  }
  VirtualFile file = eventFile.get();

  List<AnAction> actions = new LinkedList<>();

  Module module = ModuleUtil.findModuleForFile(file, project);
  if (module == null) {
    return emptyAction;
  }
  List<String> targetAddresses = PantsUtil.getNonGenTargetAddresses(module);
  // TODO: signal if no addresses found?
  if (targetAddresses.isEmpty()) {
    return emptyAction;
  }

  actions.add(new PantsLintTargetAction(targetAddresses));
  // Adds compile all option for modules with multiple targets.
  if (targetAddresses.size() > 1) {
    actions.add(new PantsCompileAllTargetsInModuleAction(Optional.of(module)));
  }
  targetAddresses.forEach(target -> actions.add(new PantsCompileTargetAction(target)));

  return actions.toArray(emptyAction);
}