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

The following examples show how to use com.intellij.openapi.actionSystem.ex.ActionUtil. 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: 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: ThreesideDiffViewer.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ShowPartialDiffAction(@Nonnull PartialDiffMode mode) {
  String id;
  switch (mode) {
    case LEFT_BASE:
      mySide1 = ThreeSide.LEFT;
      mySide2 = ThreeSide.BASE;
      id = "Diff.ComparePartial.Base.Left";
      break;
    case BASE_RIGHT:
      mySide1 = ThreeSide.BASE;
      mySide2 = ThreeSide.RIGHT;
      id = "Diff.ComparePartial.Base.Right";
      break;
    case LEFT_RIGHT:
      mySide1 = ThreeSide.LEFT;
      mySide2 = ThreeSide.RIGHT;
      id = "Diff.ComparePartial.Left.Right";
      break;
    default:
      throw new IllegalArgumentException();
  }
  ActionUtil.copyFrom(this, id);
}
 
Example #4
Source File: ActionGroupUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isActionEnabledAndVisible(@Nonnull final AnActionEvent e,
                                                 @Nonnull final Map<AnAction, Presentation> action2presentation,
                                                 @Nonnull final AnAction action,
                                                 boolean isInModalContext) {
  Presentation presentation = getPresentation(action, action2presentation);
  AnActionEvent event = new AnActionEvent(e.getInputEvent(),
                                          e.getDataContext(),
                                          ActionPlaces.UNKNOWN,
                                          presentation,
                                          ActionManager.getInstance(),
                                          e.getModifiers());
  event.setInjectedContext(action.isInInjectedContext());
  ActionUtil.performDumbAwareUpdate(isInModalContext, action, event, false);

  return presentation.isEnabled() && presentation.isVisible();
}
 
Example #5
Source File: ActionLink.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ActionLink(String text, Icon icon, @Nonnull AnAction action, @Nullable final Runnable onDone) {
  super(text, icon);
  setListener(new LinkListener() {
    @Override
    public void linkSelected(LinkLabel aSource, Object aLinkData) {
      final Presentation presentation = myAction.getTemplatePresentation().clone();
      final AnActionEvent event = new AnActionEvent(myEvent,
                                                    DataManager.getInstance().getDataContext(ActionLink.this),
                                                    myPlace,
                                                    presentation,
                                                    ActionManager.getInstance(),
                                                    0);
      ActionUtil.performDumbAwareUpdate(false, myAction, event, true);
      if (event.getPresentation().isEnabled() && event.getPresentation().isVisible()) {
        myAction.actionPerformed(event);
        if (onDone != null) {
          onDone.run();
        }
      }
    }
  }, null);
  myAction = action;
}
 
Example #6
Source File: Notification.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void fire(@Nonnull final Notification notification, @Nonnull AnAction action, @Nullable DataContext context) {
  AnActionEvent event = AnActionEvent.createFromAnAction(action, null, ActionPlaces.UNKNOWN, new DataContext() {
    @Nullable
    @Override
    @SuppressWarnings("unchecked")
    public <T> T getData(@Nonnull Key<T> dataId) {
      if (KEY == dataId) {
        return (T)notification;
      }
      return context == null ? null : context.getData(dataId);
    }
  });

  if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) {
    ActionUtil.performActionDumbAware(action, event);
  }
}
 
Example #7
Source File: IdeKeyEventDispatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void performAction(@Nonnull InputEvent e, @Nonnull AnAction action, @Nonnull AnActionEvent actionEvent) {
  e.consume();

  DataContext ctx = actionEvent.getDataContext();
  if (action instanceof ActionGroup && !((ActionGroup)action).canBePerformed(ctx)) {
    ActionGroup group = (ActionGroup)action;
    JBPopupFactory.getInstance().createActionGroupPopup(group.getTemplatePresentation().getText(), group, ctx, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false).showInBestPositionFor(ctx);
  }
  else {
    ActionUtil.performActionDumbAware(action, actionEvent);
  }

  if (Registry.is("actionSystem.fixLostTyping")) {
    IdeEventQueue.getInstance().doWhenReady(() -> IdeEventQueue.getInstance().getKeyEventDispatcher().resetState());
  }
}
 
Example #8
Source File: IdeKeyEventDispatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static ListPopupStep buildStep(@Nonnull final List<Pair<AnAction, KeyStroke>> actions, final DataContext ctx) {
  return new BaseListPopupStep<Pair<AnAction, KeyStroke>>("Choose an action", ContainerUtil.findAll(actions, pair -> {
    final AnAction action = pair.getFirst();
    final Presentation presentation = action.getTemplatePresentation().clone();
    AnActionEvent event = new AnActionEvent(null, ctx, ActionPlaces.UNKNOWN, presentation, ActionManager.getInstance(), 0);

    ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, event, true);
    return presentation.isEnabled() && presentation.isVisible();
  })) {
    @Override
    public PopupStep onChosen(Pair<AnAction, KeyStroke> selectedValue, boolean finalChoice) {
      invokeAction(selectedValue.getFirst(), ctx);
      return FINAL_CHOICE;
    }
  };
}
 
Example #9
Source File: FrameWrapper.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addCloseOnEsc(final RootPaneContainer frame) {
  JRootPane rootPane = frame.getRootPane();
  ActionListener closeAction = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      if (!PopupUtil.handleEscKeyEvent()) {
        // if you remove this line problems will start happen on Mac OS X
        // 2 projects opened, call Cmd+D on the second opened project and then Esc.
        // Weird situation: 2nd IdeFrame will be active, but focus will be somewhere inside the 1st IdeFrame
        // App is unusable until Cmd+Tab, Cmd+tab
        FrameWrapper.this.myFrame.setVisible(false);
        close();
      }
    }
  };
  rootPane.registerKeyboardAction(closeAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
  ActionUtil.registerForEveryKeyboardShortcut(rootPane, closeAction, CommonShortcuts.getCloseActiveWindow());
}
 
Example #10
Source File: ActionButton.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void actionPerformed(final AnActionEvent event) {
  if (myAction instanceof ActionGroup && !(myAction instanceof CustomComponentAction) && ((ActionGroup)myAction).isPopup() && !((ActionGroup)myAction).canBePerformed(event.getDataContext())) {
    final ActionManagerImpl am = (ActionManagerImpl)ActionManager.getInstance();
    ActionPopupMenuImpl popupMenu = (ActionPopupMenuImpl)am.createActionPopupMenu(event.getPlace(), (ActionGroup)myAction, new MenuItemPresentationFactory() {
      @Override
      protected void processPresentation(Presentation presentation) {
        if (myNoIconsInPopup) {
          presentation.setIcon(null);
          presentation.setHoveredIcon(null);
        }
      }
    });
    popupMenu.setDataContextProvider(this::getDataContext);
    if (event.isFromActionToolbar()) {
      popupMenu.getComponent().show(this, 0, getHeight());
    }
    else {
      popupMenu.getComponent().show(this, getWidth(), 0);
    }

  }
  else {
    ActionUtil.performActionDumbAware(myAction, event);
  }
}
 
Example #11
Source File: ButtonToolbarImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
ActionJButton(final AnAction action) {
  super(action.getTemplatePresentation().getText());
  myAction = action;
  setMnemonic(action.getTemplatePresentation().getMnemonic());
  setDisplayedMnemonicIndex(action.getTemplatePresentation().getDisplayedMnemonicIndex());

  addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      AnActionEvent event = new AnActionEvent(null, ((BaseDataManager)DataManager.getInstance()).getDataContextTest(ButtonToolbarImpl.this), myPlace, myPresentationFactory.getPresentation(action),
                                              ActionManager.getInstance(), e.getModifiers());
      if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) {
        ActionUtil.performActionDumbAware(action, event);
      }
    }
  });

}
 
Example #12
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 #13
Source File: ActionUpdater.java    From consulo with Apache License 2.0 6 votes vote down vote up
static boolean doUpdate(boolean isInModalContext, AnAction action, AnActionEvent e, Utils.ActionGroupVisitor visitor) {
  if (ApplicationManager.getApplication().isDisposed()) return false;

  if (visitor != null && !visitor.beginUpdate(action, e)) return true;

  long startTime = System.currentTimeMillis();
  final boolean result;
  try {
    result = !ActionUtil.performDumbAwareUpdate(isInModalContext, action, e, false);
  }
  catch (ProcessCanceledException ex) {
    throw ex;
  }
  catch (Throwable exc) {
    handleUpdateException(action, e.getPresentation(), exc);
    return false;
  }
  finally {
    if (visitor != null) visitor.endUpdate(action);
  }
  long endTime = System.currentTimeMillis();
  if (endTime - startTime > 10 && LOG.isDebugEnabled()) {
    LOG.debug("Action " + action + ": updated in " + (endTime - startTime) + " ms");
  }
  return result;
}
 
Example #14
Source File: DesktopEditorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isMouseActionEvent(@Nonnull MouseEvent e, String actionId) {
  KeymapManager keymapManager = KeymapManager.getInstance();
  if (keymapManager == null) return false;
  Keymap keymap = keymapManager.getActiveKeymap();
  MouseShortcut mouseShortcut = KeymapUtil.createMouseShortcut(e);
  String[] mappedActions = keymap.getActionIds(mouseShortcut);
  if (!ArrayUtil.contains(actionId, mappedActions)) return false;
  if (mappedActions.length < 2 || e.getID() == MouseEvent.MOUSE_DRAGGED /* 'normal' actions are not invoked on mouse drag */) return true;
  ActionManager actionManager = ActionManager.getInstance();
  for (String mappedActionId : mappedActions) {
    if (actionId.equals(mappedActionId)) continue;
    AnAction action = actionManager.getAction(mappedActionId);
    AnActionEvent actionEvent = AnActionEvent.createFromAnAction(action, e, ActionPlaces.MAIN_MENU, DataManager.getInstance().getDataContext(e.getComponent()));
    if (ActionUtil.lastUpdateAndCheckDumb(action, actionEvent, false)) return false;
  }
  return true;
}
 
Example #15
Source File: ClasspathPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void navigate(boolean openLibraryEditor) {
  final OrderEntry entry = getSelectedEntry();
  final ProjectStructureConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myState.getProject());
  if (entry instanceof ModuleOrderEntry) {
    Module module = ((ModuleOrderEntry)entry).getModule();
    if (module != null) {
      rootConfigurable.select(module.getName(), null, true);
    }
  }
  else if (entry instanceof LibraryOrderEntry) {
    if (!openLibraryEditor) {
      rootConfigurable.select((LibraryOrderEntry)entry, true);
    }
    else {
      myEditButton.actionPerformed(ActionUtil.createEmptyEvent());
    }
  }
  else if (entry instanceof ModuleExtensionWithSdkOrderEntry) {
    Sdk jdk = ((ModuleExtensionWithSdkOrderEntry)entry).getSdk();
    if (jdk != null) {
      rootConfigurable.select(jdk, true);
    }
  }
}
 
Example #16
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 #17
Source File: NewActionGroup.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isActionInNewPopupMenu(@Nonnull AnAction action) {
  ActionManager actionManager = ActionManager.getInstance();
  ActionGroup fileGroup = (ActionGroup)actionManager.getAction(IdeActions.GROUP_FILE);
  if (!ActionUtil.anyActionFromGroupMatches(fileGroup, false, child -> child instanceof NewActionGroup)) return false;

  AnAction newProjectOrModuleGroup = ActionManager.getInstance().getAction(PROJECT_OR_MODULE_GROUP_ID);
  if (newProjectOrModuleGroup instanceof ActionGroup && ActionUtil.anyActionFromGroupMatches((ActionGroup)newProjectOrModuleGroup, false, Predicate.isEqual(action))) {
    return true;
  }

  ActionGroup newGroup = (ActionGroup)actionManager.getAction(IdeActions.GROUP_NEW);
  return ActionUtil.anyActionFromGroupMatches(newGroup, false, Predicate.isEqual(action));
}
 
Example #18
Source File: GotoActionModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static AnActionEvent updateActionBeforeShow(@Nonnull AnAction anAction, @Nonnull DataContext dataContext) {
  Presentation presentation = new Presentation();
  presentation.copyFrom(anAction.getTemplatePresentation());
  AnActionEvent event = AnActionEvent.createFromDataContext(ActionPlaces.ACTION_SEARCH, presentation, dataContext);
  ActionUtil.performDumbAwareUpdate(false, anAction, event, false);
  return event;
}
 
Example #19
Source File: RecentProjectPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private AnAction performSelectedAction(@Nonnull InputEvent event, AnAction selection) {
  String actionPlace = UIUtil.uiParents(myList, true).filter(FlatWelcomeFrame.class).isEmpty() ? ActionPlaces.POPUP : ActionPlaces.WELCOME_SCREEN;
  AnActionEvent actionEvent = AnActionEvent.createFromInputEvent(event, actionPlace, selection.getTemplatePresentation(), DataManager.getInstance().getDataContext(myList), false, false);
  ActionUtil.performActionDumbAwareWithCallbacks(selection, actionEvent, actionEvent.getDataContext());
  return selection;
}
 
Example #20
Source File: CypherLineMarkerProvider.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
    PsiElement queryElement = PsiTraversalUtilities.Cypher.getCypherStatement(element);
    PsiElement lastQueryChild = isNull(queryElement) ? null : getFirstLeaf(queryElement);
    if (element == lastQueryChild) {
        return new LineMarkerInfo<PsiElement>(element,
                element.getTextRange(),
                AllIcons.Actions.Execute,
                element1 -> "Execute Query",
                (mouseEvent, psiElement) ->
                        getDataContext().ifPresent(c ->
                                ActionUtil.invokeAction(new ExecuteQueryAction(queryElement), c, "", mouseEvent, null)),
                GutterIconRenderer.Alignment.CENTER) {
            @Override
            public GutterIconRenderer createGutterRenderer() {
                return new LineMarkerGutterIconRenderer<PsiElement>(this) {
                    @Override
                    public AnAction getClickAction() {
                        return new ExecuteQueryAction(queryElement);
                    }

                    @Override
                    public boolean isNavigateAction() {
                        return true;
                    }
                };
            }
        };
    }
    return null;
}
 
Example #21
Source File: RunAnythingPopupUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateContextCombobox() {
  DataContext dataContext = getDataContext();
  Object value = myResultsList.getSelectedValue();
  String text = value instanceof RunAnythingItem ? ((RunAnythingItem)value).getCommand() : getSearchPattern();
  RunAnythingProvider provider = RunAnythingProvider.findMatchedProvider(dataContext, text);
  if (provider != null) {
    myChooseContextAction.setAvailableContexts(provider.getExecutionContexts(dataContext));
  }

  AnActionEvent event = AnActionEvent.createFromDataContext(ActionPlaces.UNKNOWN, null, dataContext);
  ActionUtil.performDumbAwareUpdate(false, myChooseContextAction, event, false);
}
 
Example #22
Source File: LineStatusTrackerDrawing.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected ActionToolbar buildToolbar(@javax.annotation.Nullable Point mousePosition, @Nonnull Disposable parentDisposable) {
  final DefaultActionGroup group = new DefaultActionGroup();

  final ShowPrevChangeMarkerAction localShowPrevAction = new ShowPrevChangeMarkerAction(myTracker.getPrevRange(myRange), myTracker, myEditor);
  final ShowNextChangeMarkerAction localShowNextAction = new ShowNextChangeMarkerAction(myTracker.getNextRange(myRange), myTracker, myEditor);
  final RollbackLineStatusRangeAction rollback = new RollbackLineStatusRangeAction(myTracker, myRange, myEditor);
  final ShowLineStatusRangeDiffAction showDiff = new ShowLineStatusRangeDiffAction(myTracker, myRange, myEditor);
  final CopyLineStatusRangeAction copyRange = new CopyLineStatusRangeAction(myTracker, myRange);
  final ToggleByWordDiffAction toggleWordDiff = new ToggleByWordDiffAction(myRange, myEditor, myTracker, mousePosition);

  group.add(localShowPrevAction);
  group.add(localShowNextAction);
  group.add(rollback);
  group.add(showDiff);
  group.add(copyRange);
  group.add(toggleWordDiff);

  JComponent editorComponent = myEditor.getComponent();
  DiffUtil.registerAction(localShowPrevAction, editorComponent);
  DiffUtil.registerAction(localShowNextAction, editorComponent);
  DiffUtil.registerAction(rollback, editorComponent);
  DiffUtil.registerAction(showDiff, editorComponent);
  DiffUtil.registerAction(copyRange, editorComponent);

  final List<AnAction> actionList = ActionUtil.getActions(editorComponent);
  Disposer.register(parentDisposable, new Disposable() {
    @Override
    public void dispose() {
      actionList.remove(localShowPrevAction);
      actionList.remove(localShowNextAction);
      actionList.remove(rollback);
      actionList.remove(showDiff);
      actionList.remove(copyRange);
    }
  });

  return ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, group, true);
}
 
Example #23
Source File: XEvaluateInConsoleFromEditorActionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ConsoleExecuteAction getConsoleExecuteAction(@Nullable ConsoleView consoleView) {
  if (!(consoleView instanceof LanguageConsoleView)) {
    return null;
  }

  List<AnAction> actions = ActionUtil.getActions(((LanguageConsoleView)consoleView).getConsoleEditor().getComponent());
  ConsoleExecuteAction action = ContainerUtil.findInstance(actions, ConsoleExecuteAction.class);
  return action == null || !action.isEnabled() ? null : action;
}
 
Example #24
Source File: ActionPopupStep.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void performAction(@Nonnull AnAction action, int modifiers, InputEvent inputEvent) {
  DataContext dataContext = myContext.get();
  AnActionEvent event = new AnActionEvent(inputEvent, dataContext, myActionPlace, action.getTemplatePresentation().clone(), ActionManager.getInstance(), modifiers);
  event.setInjectedContext(action.isInInjectedContext());
  if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) {
    ActionUtil.performActionDumbAwareWithCallbacks(action, event, dataContext);
  }
}
 
Example #25
Source File: PopupFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Presentation updateActionItem(@Nonnull ActionItem actionItem) {
  AnAction action = actionItem.getAction();
  Presentation presentation = new Presentation();
  presentation.setDescription(action.getTemplatePresentation().getDescription());

  final AnActionEvent actionEvent = new AnActionEvent(null, DataManager.getInstance().getDataContext(myComponent), myActionPlace, presentation, ActionManager.getInstance(), 0);
  actionEvent.setInjectedContext(action.isInInjectedContext());
  ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, actionEvent, false);
  return presentation;
}
 
Example #26
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void performAction(@Nonnull AnAction action, @Nonnull InputEvent e, @Nonnull String place, @Nonnull DataContext context) {
  if (!checkDumbAware(action)) {
    notifyNotDumbAware();
    return;
  }

  AnActionEvent actionEvent = AnActionEvent.createFromAnAction(action, e, place, context);
  action.update(actionEvent);
  if (actionEvent.getPresentation().isEnabledAndVisible()) {
    ActionUtil.performActionDumbAwareWithCallbacks(action, actionEvent, context);
  }
}
 
Example #27
Source File: TextDiffViewerUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void install(@Nonnull List<? extends EditorEx> editors, @Nonnull JComponent component) {
  ActionUtil.recursiveRegisterShortcutSet(new DefaultActionGroup(myEditorPopupActions), component, null);

  EditorPopupHandler handler = new ContextMenuPopupHandler.Simple(myEditorPopupActions.isEmpty() ? null : new DefaultActionGroup(myEditorPopupActions));
  for (EditorEx editor : editors) {
    editor.installPopupHandler(handler);
  }
}
 
Example #28
Source File: ActionButton.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addNotify() {
  super.addNotify();
  if (myPresentationListener == null) {
    myPresentation.addPropertyChangeListener(myPresentationListener = this::presentationPropertyChanded);
  }
  AnActionEvent e = AnActionEvent.createFromInputEvent(null, myPlace, myPresentation, getDataContext(), false, true);
  ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), myAction, e, false);
  updateToolTipText();
  updateIcon();
}
 
Example #29
Source File: CommandExecutor.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unused") // ECJ compiler for some reason thinks handlerService == null is always false
private static boolean executeCommandClientSide(Command command, Document document) {
    Application workbench = ApplicationManager.getApplication();
    if (workbench == null) {
        return false;
    }
    URI context = LSPIJUtils.toUri(document);
    AnAction parameterizedCommand = createEclipseCoreCommand(command, context, workbench);
    if (parameterizedCommand == null) {
        return false;
    }
    DataContext dataContext = createDataContext(command, context, workbench);
    ActionUtil.invokeAction(parameterizedCommand, dataContext, ActionPlaces.UNKNOWN, null, null);
    return true;
}
 
Example #30
Source File: RollbackLineStatusRangeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public RollbackLineStatusRangeAction(@Nonnull LineStatusTracker tracker, @Nonnull Range range, @javax.annotation.Nullable Editor editor) {
  ActionUtil.copyFrom(this, IdeActions.SELECTED_CHANGES_ROLLBACK);

  myTracker = tracker;
  myEditor = editor;
  myRange = range;
}