Java Code Examples for com.intellij.openapi.actionSystem.ex.ActionManagerEx#getInstanceEx()

The following examples show how to use com.intellij.openapi.actionSystem.ex.ActionManagerEx#getInstanceEx() . 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: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean _performEditorAction(String actionId) {
  final DataContext dataContext = getEditorDataContext();

  ActionManagerEx managerEx = ActionManagerEx.getInstanceEx();
  AnAction action = managerEx.getAction(actionId);
  AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, new Presentation(), managerEx, 0);

  action.update(event);

  if (!event.getPresentation().isEnabled()) {
    return false;
  }

  managerEx.fireBeforeActionPerformed(action, dataContext, event);

  action.actionPerformed(event);

  managerEx.fireAfterActionPerformed(action, dataContext, event);
  return true;
}
 
Example 2
Source File: ActionButton.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void performAction(MouseEvent e) {
  AnActionEvent event = AnActionEvent.createFromInputEvent(e, myPlace, myPresentation, getDataContext(), false, true);
  if (!ActionUtil.lastUpdateAndCheckDumb(myAction, event, false)) {
    return;
  }

  if (isButtonEnabled()) {
    final ActionManagerEx manager = ActionManagerEx.getInstanceEx();
    final DataContext dataContext = event.getDataContext();
    manager.fireBeforeActionPerformed(myAction, dataContext, event);
    Component component = dataContext.getData(PlatformDataKeys.CONTEXT_COMPONENT);
    if (component != null && !component.isShowing()) {
      return;
    }
    actionPerformed(event);
    manager.queueActionPerformedEvent(myAction, dataContext, event);
    if (event.getInputEvent() instanceof MouseEvent) {
      //FIXME [VISTALL] we need that ?ToolbarClicksCollector.record(myAction, myPlace);
    }
  }
}
 
Example 3
Source File: ActionsTreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Group createMacrosGroup(Condition<AnAction> filtered) {
  final ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
  String[] ids = actionManager.getActionIds(ActionMacro.MACRO_ACTION_PREFIX);
  Arrays.sort(ids);
  Group group = new Group(KeyMapBundle.message("macros.group.title"), null, null);
  for (String id : ids) {
    if (filtered == null || filtered.value(actionManager.getActionOrStub(id))) {
      group.addActionId(id);
    }
  }
  return group;
}
 
Example 4
Source File: ToolbarUpdater.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ToolbarUpdater(@Nonnull KeymapManagerEx keymapManager, @Nonnull JComponent component) {
  myActionManager = ActionManagerEx.getInstanceEx();
  myKeymapManager = keymapManager;
  myComponent = component;
  myWeakTimerListener = new WeakTimerListener(myTimerListener);
  new UiNotifyConnector(component, this);
}
 
Example 5
Source File: ActionToolbarImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionToolbarImpl(@Nonnull String place, @Nonnull ActionGroup actionGroup, final boolean horizontal, final boolean decorateButtons, boolean updateActionsNow) {
  super(null);
  myActionManager = ActionManagerEx.getInstanceEx();
  myPlace = place;
  myActionGroup = actionGroup;
  myVisibleActions = new ArrayList<>();
  myDataManager = DataManager.getInstance();
  myDecorateButtons = decorateButtons;
  myUpdater = new ToolbarUpdater(KeymapManagerEx.getInstanceEx(), this) {
    @Override
    protected void updateActionsImpl(boolean transparentOnly, boolean forced) {
      if (!ApplicationManager.getApplication().isDisposedOrDisposeInProgress()) {
        ActionToolbarImpl.this.updateActionsImpl(transparentOnly, forced);
      }
    }
  };

  setOrientation(horizontal ? ActionToolbar.HORIZONTAL_ORIENTATION : ActionToolbar.VERTICAL_ORIENTATION);

  mySecondaryActions.getTemplatePresentation().setIcon(AllIcons.General.GearPlain);
  mySecondaryActions.setPopup(true);

  myUpdater.updateActions(updateActionsNow, false);

  // If the panel doesn't handle mouse event then it will be passed to its parent.
  // It means that if the panel is in sliding mode then the focus goes to the editor
  // and panel will be automatically hidden.
  enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.COMPONENT_EVENT_MASK | AWTEvent.CONTAINER_EVENT_MASK);
  setMiniMode(false);
}
 
Example 6
Source File: IdeKeyEventDispatcher.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean processAction(final InputEvent e, @Nonnull ActionProcessor processor) {
  ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
  final Project project = myContext.getDataContext().getData(CommonDataKeys.PROJECT);
  final boolean dumb = project != null && DumbService.getInstance(project).isDumb();
  List<AnActionEvent> nonDumbAwareAction = new ArrayList<>();
  List<AnAction> actions = myContext.getActions();
  for (final AnAction action : actions.toArray(new AnAction[actions.size()])) {
    Presentation presentation = myPresentationFactory.getPresentation(action);

    // Mouse modifiers are 0 because they have no any sense when action is invoked via keyboard
    final AnActionEvent actionEvent = processor.createEvent(e, myContext.getDataContext(), ActionPlaces.MAIN_MENU, presentation, ActionManager.getInstance());

    try (AccessToken ignored = ProhibitAWTEvents.start("update")) {
      ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, actionEvent, true);
    }

    if (dumb && !action.isDumbAware()) {
      if (!Boolean.FALSE.equals(presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) {
        nonDumbAwareAction.add(actionEvent);
      }
      continue;
    }

    if (!presentation.isEnabled()) {
      continue;
    }

    processor.onUpdatePassed(e, action, actionEvent);

    if (myContext.getDataContext() instanceof BaseDataManager.DataContextWithEventCount) { // this is not true for test data contexts
      ((BaseDataManager.DataContextWithEventCount)myContext.getDataContext()).setEventCount(IdeEventQueue.getInstance().getEventCount(), this);
    }
    actionManager.fireBeforeActionPerformed(action, actionEvent.getDataContext(), actionEvent);
    Component component = actionEvent.getData(PlatformDataKeys.CONTEXT_COMPONENT);
    if (component != null && !component.isShowing()) {
      return true;
    }

    ((TransactionGuardEx)TransactionGuard.getInstance()).performUserActivity(() -> processor.performAction(e, action, actionEvent));
    actionManager.fireAfterActionPerformed(action, actionEvent.getDataContext(), actionEvent);
    return true;
  }

  if (!nonDumbAwareAction.isEmpty()) {
    showDumbModeWarningLaterIfNobodyConsumesEvent(e, nonDumbAwareAction.toArray(new AnActionEvent[nonDumbAwareAction.size()]));
  }

  return false;
}