Java Code Examples for com.intellij.openapi.actionSystem.ex.ActionUtil#performDumbAwareUpdate()

The following examples show how to use com.intellij.openapi.actionSystem.ex.ActionUtil#performDumbAwareUpdate() . 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: 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 2
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 3
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 4
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 5
Source File: RunAnythingChooseContextAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected ListCellRenderer getListElementRenderer() {
  return new PopupListElementRenderer<PopupFactoryImpl.ActionItem>(this) {
    private JLabel myInfoLabel;

    @Override
    protected JComponent createItemComponent() {
      myTextLabel = new ErrorLabel();
      myInfoLabel = new JLabel();
      myTextLabel.setBorder(JBUI.Borders.empty(10));

      JPanel textPanel = new JPanel(new BorderLayout());
      textPanel.add(myTextLabel, BorderLayout.WEST);
      textPanel.add(myInfoLabel, BorderLayout.CENTER);
      return layoutComponent(textPanel);
    }

    @Override
    protected void customizeComponent(JList<? extends PopupFactoryImpl.ActionItem> list, PopupFactoryImpl.ActionItem actionItem, boolean isSelected) {
      AnActionEvent event = ActionUtil.createEmptyEvent();
      ActionUtil.performDumbAwareUpdate(true, actionItem.getAction(), event, false);

      String description = event.getPresentation().getDescription();
      if (description != null) {
        myInfoLabel.setText(description);
      }

      myTextLabel.setText(event.getPresentation().getText());
      myInfoLabel.setForeground(isSelected ? UIUtil.getListSelectionForeground(true) : UIUtil.getInactiveTextColor());
    }
  };
}
 
Example 6
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 7
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 8
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 9
Source File: ActionButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void update() {
  AnActionEvent e = AnActionEvent.createFromInputEvent(null, myPlace, myPresentation, getDataContext(), false, true);
  ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), myAction, e, false);
  updateToolTipText();
  updateIcon();
}