com.intellij.openapi.actionSystem.ex.ActionManagerEx Java Examples

The following examples show how to use com.intellij.openapi.actionSystem.ex.ActionManagerEx. 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: ContentTabLabel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void execute(final MouseEvent e) {

  Optional<Runnable> first = myAdditionalIcons.stream().filter(icon -> mouseOverIcon(icon)).map(icon -> icon.getAction()).findFirst();

  if (first.isPresent()) {
    first.get().run();
    return;
  }

  selectContent();

  if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1 && !myLayout.myDoubleClickActions.isEmpty()) {
    DataContext dataContext = DataManager.getInstance().getDataContext(ContentTabLabel.this);
    for (AnAction action : myLayout.myDoubleClickActions) {
      AnActionEvent event = AnActionEvent.createFromInputEvent(e, ActionPlaces.UNKNOWN, null, dataContext);
      if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) {
        ActionManagerEx.getInstanceEx().fireBeforeActionPerformed(action, dataContext, event);
        ActionUtil.performActionDumbAware(action, event);
      }
    }
  }
}
 
Example #2
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 #3
Source File: ModifierKeyDoubleClickHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean run(KeyEvent event) {
  myIsRunningAction = true;
  try {
    AnAction action = myActionManager.getAction(myActionId);
    if (action == null) return false;
    DataContext context = DataManager.getInstance().getDataContext(IdeFocusManager.findInstance().getFocusOwner());
    AnActionEvent anActionEvent = AnActionEvent.createFromAnAction(action, event, ActionPlaces.MAIN_MENU, context);
    action.update(anActionEvent);
    if (!anActionEvent.getPresentation().isEnabled()) return false;

    ((ActionManagerEx)myActionManager).fireBeforeActionPerformed(action, anActionEvent.getDataContext(), anActionEvent);
    action.actionPerformed(anActionEvent);
    ((ActionManagerEx)myActionManager).fireAfterActionPerformed(action, anActionEvent.getDataContext(), anActionEvent);
    return true;
  }
  finally {
    myIsRunningAction = false;
  }
}
 
Example #4
Source File: AbstractGotoSEContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public JComponent createCustomComponent(@Nonnull Presentation presentation, @Nonnull String place) {
  JComponent component = new ActionButtonWithText(this, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
  UIUtil.putClientProperty(component, MnemonicHelper.MNEMONIC_CHECKER, keyCode -> KeyEvent.getExtendedKeyCodeForChar(TOGGLE) == keyCode || KeyEvent.getExtendedKeyCodeForChar(CHOOSE) == keyCode);

  MnemonicHelper.registerMnemonicAction(component, CHOOSE);
  InputMap map = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  int mask = MnemonicHelper.getFocusAcceleratorKeyMask();
  map.put(KeyStroke.getKeyStroke(TOGGLE, mask, false), TOGGLE_ACTION_NAME);
  component.getActionMap().put(TOGGLE_ACTION_NAME, new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      // mimic AnAction event invocation to trigger myEverywhereAutoSet=false logic
      DataContext dataContext = DataManager.getInstance().getDataContext(component);
      KeyEvent inputEvent = new KeyEvent(component, KeyEvent.KEY_PRESSED, e.getWhen(), MnemonicHelper.getFocusAcceleratorKeyMask(), KeyEvent.getExtendedKeyCodeForChar(TOGGLE), TOGGLE);
      AnActionEvent event = AnActionEvent.createFromAnAction(ScopeChooserAction.this, inputEvent, ActionPlaces.TOOLBAR, dataContext);
      ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
      actionManager.fireBeforeActionPerformed(ScopeChooserAction.this, dataContext, event);
      onProjectScopeToggled();
      actionManager.fireAfterActionPerformed(ScopeChooserAction.this, dataContext, event);
    }
  });
  return component;
}
 
Example #5
Source File: ActionsTreeUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Group createQuickListsGroup(final Condition<AnAction> filtered, final String filter, final boolean forceFiltering, final QuickList[] quickLists) {
  Arrays.sort(quickLists, new Comparator<QuickList>() {
    public int compare(QuickList l1, QuickList l2) {
      return l1.getActionId().compareTo(l2.getActionId());
    }
  });

  Group group = new Group(KeyMapBundle.message("quick.lists.group.title"), null, null);
  for (QuickList quickList : quickLists) {
    if (filtered != null && filtered.value(ActionManagerEx.getInstanceEx().getAction(quickList.getActionId()))) {
      group.addQuickList(quickList);
    } else if (SearchUtil.isComponentHighlighted(quickList.getDisplayName(), filter, forceFiltering, null)) {
      group.addQuickList(quickList);
    } else if (filtered == null && StringUtil.isEmpty(filter)) {
      group.addQuickList(quickList);
    }
  }
  return group;
}
 
Example #6
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 #7
Source File: DesktopEditorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean processKeyTyped(char c) {

    if (ProgressManager.getInstance().hasModalProgressIndicator()) {
      return false;
    }
    FileDocumentManager manager = FileDocumentManager.getInstance();
    final VirtualFile file = manager.getFile(myDocument);
    if (file != null && !file.isValid()) {
      return false;
    }

    DataContext context = getDataContext();

    Graphics graphics = GraphicsUtil.safelyGetGraphics(myEditorComponent);
    if (graphics != null) { // editor component is not showing
      PaintUtil.alignTxToInt((Graphics2D)graphics, PaintUtil.insets2offset(getInsets()), true, false, RoundingMode.CEIL);
      processKeyTypedImmediately(c, graphics, context);
      graphics.dispose();
    }

    ActionManagerEx.getInstanceEx().fireBeforeEditorTyping(c, context);
    EditorUIUtil.hideCursorInEditor(this);
    processKeyTypedNormally(c, context);

    return true;
  }
 
Example #8
Source File: ActionMenuItem.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
  final IdeFocusManager fm = IdeFocusManager.findInstanceByContext(myContext);
  final ActionCallback typeAhead = new ActionCallback();
  final String id = ActionManager.getInstance().getId(myAction.getAction());
  if (id != null) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed("context.menu.click.stats." + id.replace(' ', '.'));
  }
  fm.typeAheadUntil(typeAhead, getText());
  fm.runOnOwnContext(myContext, () -> {
    final AnActionEvent event =
            new AnActionEvent(new MouseEvent(ActionMenuItem.this, MouseEvent.MOUSE_PRESSED, 0, e.getModifiers(), getWidth() / 2, getHeight() / 2, 1, false),
                              myContext, myPlace, myPresentation, ActionManager.getInstance(), e.getModifiers(), true, false);
    final AnAction menuItemAction = myAction.getAction();
    if (ActionUtil.lastUpdateAndCheckDumb(menuItemAction, event, false)) {
      ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
      actionManager.fireBeforeActionPerformed(menuItemAction, myContext, event);
      fm.doWhenFocusSettlesDown(typeAhead::setDone);
      ActionUtil.performActionDumbAware(menuItemAction, event);
      actionManager.queueActionPerformedEvent(menuItemAction, myContext, event);
    }
    else {
      typeAhead.setDone();
    }
  });
}
 
Example #9
Source File: ButtonToolbarImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
ButtonToolbarImpl(@Nonnull String place, @Nonnull ActionGroup actionGroup) {
  super(new GridBagLayout());
  myPlace = place;
  myPresentationFactory = new PresentationFactory();
  myDataManager = DataManager.getInstance();

  initButtons(actionGroup);

  updateActions();
  ActionManagerEx.getInstanceEx().addTimerListener(500, new WeakTimerListener(new MyTimerListener()));
  enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
}
 
Example #10
Source File: FrameWrapperPeerFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private MyJFrame(FrameWrapper owner, IdeFrame parent) throws HeadlessException {
  myOwner = owner;
  myParent = parent;

  toUIWindow().putUserData(IdeFrame.KEY, this);
  toUIWindow().addUserDataProvider(this::getData);

  FrameState.setFrameStateListener(this);
  setGlassPane(new IdeGlassPaneImpl(getRootPane(), true));

  boolean setMenuOnFrame = SystemInfo.isMac;

  if (SystemInfo.isLinux) {
    final String desktop = System.getenv("XDG_CURRENT_DESKTOP");
    if ("Unity".equals(desktop) || "Unity:Unity7".equals(desktop)) {
      try {
        Class.forName("com.jarego.jayatana.Agent");
        setMenuOnFrame = true;
      }
      catch (ClassNotFoundException e) {
        // ignore
      }
    }
  }

  if (setMenuOnFrame) {
    setJMenuBar(new IdeMenuBar(ActionManagerEx.getInstanceEx(), DataManager.getInstance()));
  }

  MouseGestureManager.getInstance().add(this);
  setFocusTraversalPolicy(new LayoutFocusTraversalPolicyExt());
  setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
 
Example #11
Source File: GotoActionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void performAction(Object element, @Nullable Component component, @Nullable AnActionEvent e, @JdkConstants.InputEventMask int modifiers, @Nullable Runnable callback) {
  // element could be AnAction (SearchEverywhere)
  if (component == null) return;
  AnAction action = element instanceof AnAction ? (AnAction)element : ((GotoActionModel.ActionWrapper)element).getAction();
  TransactionGuard.getInstance().submitTransactionLater(ApplicationManager.getApplication(), () -> {
    DataManager instance = DataManager.getInstance();
    DataContext context = instance != null ? instance.getDataContext(component) : DataContext.EMPTY_CONTEXT;
    InputEvent inputEvent = e != null ? e.getInputEvent() : null;
    AnActionEvent event = AnActionEvent.createFromAnAction(action, inputEvent, ActionPlaces.ACTION_SEARCH, context);
    if (inputEvent == null && modifiers != 0) {
      event = new AnActionEvent(null, event.getDataContext(), event.getPlace(), event.getPresentation(), event.getActionManager(), modifiers);
    }

    if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) {
      if (action instanceof ActionGroup && !((ActionGroup)action).canBePerformed(context)) {
        ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(event.getPresentation().getText(), (ActionGroup)action, context, false, callback, -1);
        Window window = SwingUtilities.getWindowAncestor(component);
        if (window != null) {
          popup.showInCenterOf(window);
        }
        else {
          popup.showInFocusCenter();
        }
      }
      else {
        ActionManagerEx manager = ActionManagerEx.getInstanceEx();
        manager.fireBeforeActionPerformed(action, context, event);
        ActionUtil.performActionDumbAware(action, event);
        if (callback != null) callback.run();
        manager.fireAfterActionPerformed(action, context, event);
      }
    }
  });
}
 
Example #12
Source File: ShowErrorDescriptionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void changeState() {
  if (Comparing.strEqual(ActionManagerEx.getInstanceEx().getPrevPreformedActionId(), IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)) {
    shouldShowDescription = descriptionShown;
  } else {
    shouldShowDescription = false;
    descriptionShown = true;
  }
}
 
Example #13
Source File: ActionMacroManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean checkCanCreateMacro(String name) {
  final ActionManagerEx actionManager = (ActionManagerEx)ActionManager.getInstance();
  final String actionId = ActionMacro.MACRO_ACTION_PREFIX + name;
  if (actionManager.getAction(actionId) != null) {
    if (Messages.showYesNoDialog(IdeBundle.message("message.macro.exists", name), IdeBundle.message("title.macro.name.already.used"), Messages.getWarningIcon()) != 0) {
      return false;
    }
    actionManager.unregisterAction(actionId);
    removeMacro(name);
  }

  return true;
}
 
Example #14
Source File: MacrosGroup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public AnAction[] getChildren(@Nullable AnActionEvent e) {
  ArrayList<AnAction> actions = new ArrayList<AnAction>();
  final ActionManagerEx actionManager = ((ActionManagerEx) ActionManager.getInstance());
  String[] ids = actionManager.getActionIds(ActionMacro.MACRO_ACTION_PREFIX);

  for (String id : ids) {
    actions.add(actionManager.getAction(id));
  }

  return actions.toArray(new AnAction[actions.size()]);
}
 
Example #15
Source File: MacGestureSupportForEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public MacGestureSupportForEditor(JComponent component) {
  GestureUtilities.addGestureListenerTo(component, new PressureListener() {
    @Override
    public void pressure(PressureEvent e) {
      if (IdeMouseEventDispatcher.isForceTouchAllowed() && e.getStage() == 2) {
        MouseShortcut shortcut = new PressureShortcut(e.getStage());
        fillActionsList(shortcut, IdeKeyEventDispatcher.isModalContext(component));
        ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
        if (actionManager != null) {
          AnAction[] actions = myActions.toArray(new AnAction[myActions.size()]);
          for (AnAction action : actions) {
            DataContext dataContext = DataManager.getInstance().getDataContext(component);
            Presentation presentation = myPresentationFactory.getPresentation(action);
            AnActionEvent actionEvent = new AnActionEvent(null, dataContext, ActionPlaces.MAIN_MENU, presentation,
                                                          ActionManager.getInstance(),
                                                          0);
            action.beforeActionPerformedUpdate(actionEvent);

            if (presentation.isEnabled()) {
              actionManager.fireBeforeActionPerformed(action, dataContext, actionEvent);
              final Component context = dataContext.getData(PlatformDataKeys.CONTEXT_COMPONENT);

              if (context != null && !context.isShowing()) continue;

              action.actionPerformed(actionEvent);

            }
          }
        }
        e.consume();
        IdeMouseEventDispatcher.forbidForceTouch();
      }
    }
  });
}
 
Example #16
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 #17
Source File: WeakTimerListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ModalityState getModalityState() {
  TimerListener delegate = myRef.get();
  if (delegate != null) {
    return delegate.getModalityState();
  }
  else {
    ActionManagerEx.getInstanceEx().removeTimerListener(this);
    return null;
  }
}
 
Example #18
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 #19
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 #20
Source File: HintManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeActionPerformed(@Nonnull AnAction action, @Nonnull DataContext dataContext, @Nonnull AnActionEvent event) {
  if (action instanceof ActionToIgnore) return;

  AnAction escapeAction = ActionManagerEx.getInstanceEx().getAction(IdeActions.ACTION_EDITOR_ESCAPE);
  if (action == escapeAction) return;

  hideHints(HIDE_BY_ANY_KEY, false, false);
}
 
Example #21
Source File: MyApplicationService.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
public AnAction getAnAction() {
	if (lastCustomActionModel != null) {
		return ActionManagerEx.getInstanceEx().getAction(lastCustomActionModel.getId());
	}
	return getActionMap().get(lastAction);
}
 
Example #22
Source File: ToolbarUpdater.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public ActionManagerEx getActionManager() {
  return myActionManager;
}
 
Example #23
Source File: XLineBreakpointManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseClicked(final EditorMouseEvent e) {
  final Editor editor = e.getEditor();
  final MouseEvent mouseEvent = e.getMouseEvent();
  if (mouseEvent.isPopupTrigger() ||
      mouseEvent.isMetaDown() ||
      mouseEvent.isControlDown() ||
      mouseEvent.getButton() != MouseEvent.BUTTON1 ||
      DiffUtil.isDiffEditor(editor) ||
      !isInsideGutter(e, editor) ||
      ConsoleViewUtil.isConsoleViewEditor(editor) ||
      !isFromMyProject(editor) ||
      (editor.getSelectionModel().hasSelection() && myDragDetected)) {
    return;
  }

  PsiDocumentManager.getInstance(myProject).commitAllDocuments();
  final int line = EditorUtil.yPositionToLogicalLine(editor, mouseEvent);
  final Document document = editor.getDocument();
  final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
  if (line >= 0 && line < document.getLineCount() && file != null) {
    ActionManagerEx.getInstanceEx().fireBeforeActionPerformed(IdeActions.ACTION_TOGGLE_LINE_BREAKPOINT, e.getMouseEvent());

    final AsyncResult<XLineBreakpoint> lineBreakpoint =
            XBreakpointUtil.toggleLineBreakpoint(myProject, XSourcePositionImpl.create(file, line), editor, mouseEvent.isAltDown(), false);
    lineBreakpoint.doWhenDone(breakpoint -> {
      if (!mouseEvent.isAltDown() && mouseEvent.isShiftDown() && breakpoint != null) {
        breakpoint.setSuspendPolicy(SuspendPolicy.NONE);
        String selection = editor.getSelectionModel().getSelectedText();
        if (selection != null) {
          breakpoint.setLogExpression(selection);
        }
        else {
          breakpoint.setLogMessage(true);
        }
        // edit breakpoint
        DebuggerUIUtil.showXBreakpointEditorBalloon(myProject, mouseEvent.getPoint(), ((EditorEx)editor).getGutterComponentEx(), false, breakpoint);
      }
    });
  }
}
 
Example #24
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;
}
 
Example #25
Source File: KeymapImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String[] sortInOrderOfRegistration(String[] ids) {
  Arrays.sort(ids, ActionManagerEx.getInstanceEx().getRegistrationOrderComparator());
  return ids;
}
 
Example #26
Source File: CommonActionsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
CommonActionsPanel(ListenerFactory factory, @Nullable JComponent contextComponent, ActionToolbarPosition position,
                   @Nullable AnAction[] additionalActions, @Nullable Comparator<AnAction> buttonComparator,
                   String addName, String removeName, String moveUpName, String moveDownName, String editName,
                   Icon addIcon, Buttons... buttons) {
  super(new BorderLayout());
  final Listener listener = factory.createListener(this);
  AnAction[] actions = new AnAction[buttons.length];
  for (int i = 0; i < buttons.length; i++) {
    Buttons button = buttons[i];
    String name = null;
    switch (button) {
      case ADD:    name = addName;      break;        
      case EDIT:   name = editName;     break;
      case REMOVE: name = removeName;   break;
      case UP:     name = moveUpName;   break;
      case DOWN:   name = moveDownName; break;
    }
    final MyActionButton b = button.createButton(listener, name, button == Buttons.ADD && addIcon != null ? addIcon : button.getIcon());
    actions[i] = b;
    myButtons.put(button, b);
  }
  if (additionalActions != null && additionalActions.length > 0) {
    final ArrayList<AnAction> allActions = new ArrayList<>(Arrays.asList(actions));
    allActions.addAll(Arrays.asList(additionalActions));
    actions = allActions.toArray(new AnAction[allActions.size()]);
  }
  myActions = actions;
  for (AnAction action : actions) {
    if(action instanceof AnActionButton) {
      ((AnActionButton)action).setContextComponent(contextComponent);
    }
  }
  if (buttonComparator != null) {
    Arrays.sort(myActions, buttonComparator);
  }
  ArrayList<AnAction> toolbarActions = new ArrayList<>(Arrays.asList(myActions));
  for (int i = 0; i < toolbarActions.size(); i++) {
      if (toolbarActions.get(i) instanceof AnActionButton.CheckedAnActionButton) {
        toolbarActions.set(i, ((AnActionButton.CheckedAnActionButton)toolbarActions.get(i)).getDelegate());
      }
  }
  myDecorateButtons = UIUtil.isUnderAquaLookAndFeel() && position == ActionToolbarPosition.BOTTOM;

  final ActionManagerEx mgr = (ActionManagerEx)ActionManager.getInstance();
  final ActionToolbar toolbar = mgr.createActionToolbar(ActionPlaces.UNKNOWN,
                                                        new DefaultActionGroup(toolbarActions.toArray(new AnAction[toolbarActions.size()])),
                                                        position == ActionToolbarPosition.BOTTOM || position == ActionToolbarPosition.TOP,
                                                        myDecorateButtons);
  toolbar.getComponent().setOpaque(false);
  toolbar.getComponent().setBorder(null);
  add(toolbar.getComponent(), BorderLayout.CENTER);
}
 
Example #27
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void type(final char c) {
  assertInitialized();
  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      final EditorActionManager actionManager = EditorActionManager.getInstance();
      if (c == '\b') {
        performEditorAction(IdeActions.ACTION_EDITOR_BACKSPACE);
        return;
      }
      if (c == '\n') {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM)) {
          return;
        }

        performEditorAction(IdeActions.ACTION_EDITOR_ENTER);
        return;
      }
      if (c == '\t') {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EXPAND_LIVE_TEMPLATE_BY_TAB)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EDITOR_TAB)) {
          return;
        }
      }
      if (c == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT)) {
          return;
        }
      }

      CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
        @Override
        public void run() {
          CommandProcessor.getInstance().setCurrentCommandGroupId(myEditor.getDocument());
          ActionManagerEx.getInstanceEx().fireBeforeEditorTyping(c, getEditorDataContext());
          actionManager.getTypedAction().actionPerformed(getEditor(), c, getEditorDataContext());
        }
      }, null, DocCommandGroupId.noneGroupId(myEditor.getDocument()));
    }
  });
}