com.intellij.openapi.util.ActionCallback Java Examples

The following examples show how to use com.intellij.openapi.util.ActionCallback. 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: GridImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CellTransform.Restore detach() {
  if (getComponentCount() == 1) {
    myContent = (JComponent)getComponent(0);
    removeAll();
  }

  if (getParent() instanceof JComponent) {
    ((JComponent)getParent()).revalidate();
    getParent().repaint();
  }

  return new CellTransform.Restore() {
    @Override
    public ActionCallback restoreInGrid() {
      if (myContent != null) {
        setContent(myContent);
        myContent = null;
      }
      return ActionCallback.DONE;
    }
  };
}
 
Example #2
Source File: AbstractCommand.java    From consulo with Apache License 2.0 6 votes vote down vote up
public final ActionCallback execute(final PlaybackContext context) {
  try {
    if (isToDumpCommand()) {
      dumpCommand(context);
    }
    final ActionCallback result = new ActionCallback();
    if (isAwtThread()) {
      _execute(context).notify(result);
    } else {
      ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        @Override
        public void run() {
          _execute(context).notify(result);
        }
      });
    }

   return result;
  }
  catch (Exception e) {
    context.error(e.getMessage(), getLine());
    return new ActionCallback.Rejected();
  }
}
 
Example #3
Source File: RegistryValueCommand.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected ActionCallback _execute(PlaybackContext context) {
  final String[] keyValue = getText().substring(PREFIX.length()).trim().split("=");
  if (keyValue.length != 2) {
    context.error("Expected expresstion: " + PREFIX + " key=value", getLine());
    return new ActionCallback.Rejected();
  }

  final String key = keyValue[0];
  final String value = keyValue[1];

  context.storeRegistryValue(key);

  Registry.get(key).setValue(value);

  return new ActionCallback.Done();
}
 
Example #4
Source File: FavoritesViewSelectInTarget.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static ActionCallback select(@Nonnull Project project, Object toSelect, VirtualFile virtualFile, boolean requestFocus) {
  final ActionCallback result = new ActionCallback();

  ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  final ToolWindow favoritesToolWindow = windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW);

  if (favoritesToolWindow != null) {
    final Runnable runnable = () -> {
      final FavoritesTreeViewPanel panel = UIUtil.findComponentOfType(favoritesToolWindow.getComponent(), FavoritesTreeViewPanel.class);
      if (panel != null) {
        panel.selectElement(toSelect, virtualFile, requestFocus);
        result.setDone();
      }
    };

    if (requestFocus) {
      favoritesToolWindow.activate(runnable, false);
    }
    else {
      favoritesToolWindow.show(runnable);
    }
  }

  return result;
}
 
Example #5
Source File: History.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void goThere(final int nextPos) {
  myNavigatedNow = true;
  final Place next = myHistory.get(nextPos);
  final Place from = getCurrent();
  fireStarted(from, next);
  try {
    final ActionCallback callback = myRoot.navigateTo(next, false);
    callback.doWhenDone(new Runnable() {
      @Override
      public void run() {
        myCurrentPos = nextPos;
      }
    }).doWhenProcessed(new Runnable() {
      @Override
      public void run() {
        myNavigatedNow = false;
        fireFinished(from, next);
      }
    });
  }
  catch (Throwable e) {
    myNavigatedNow = false;
    throw new RuntimeException(e);
  }
}
 
Example #6
Source File: GridCellImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void minimize(Content[] contents) {
  myContext.saveUiState();

  for (final Content each : contents) {
    myMinimizedContents.add(each);
    remove(each);
    boolean isShowing = myTabs.getComponent().getRootPane() != null;
    updateSelection(isShowing);
    myContainer.minimize(each, new CellTransform.Restore() {
      @Override
      public ActionCallback restoreInGrid() {
        return restore(each);
      }
    });
  }
}
 
Example #7
Source File: UpdaterTreeState.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void processNextHang(Object element, final ActionCallback callback) {
  if (element == null || myUi.getSelectedElements().contains(element)) {
    callback.setDone();
  }
  else {
    final Object nextElement = myUi.getTreeStructure().getParentElement(element);
    if (nextElement == null) {
      callback.setDone();
    }
    else {
      myUi.select(nextElement, new TreeRunnable("UpdaterTreeState.processNextHang") {
        @Override
        public void perform() {
          processNextHang(nextElement, callback);
        }
      }, true);
    }
  }
}
 
Example #8
Source File: SourceJarGenerator.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public ActionCallback perform(Collection<Library> libraries) {
  ActionCallback callback = new ActionCallback();
  Task task = new Task.Backgroundable(psiFile.getProject(), "Generating source jar from Pants") {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      try {
        indicator.setText("Generating source jar");
        File sourceJar = generateSourceJar(indicator, target, sourceJarPath, psiFile);
        indicator.setText("Attaching source jar");
        attach(sourceJar, libraries);
        callback.setDone();
      }
      catch (Exception e) {
        String msg = "Error while generating sources ";
        LOG.warn(msg, e);
        callback.reject(msg + e.getMessage());
      }
    }
  };
  task.queue();
  return callback;
}
 
Example #9
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 #10
Source File: CellTransform.java    From consulo with Apache License 2.0 6 votes vote down vote up
private ActionCallback restore(final int index) {
  final ActionCallback result = new ActionCallback();
  final Restore action = myActions.get(index);
  final ActionCallback actionCalback = action.restoreInGrid();
  actionCalback.doWhenDone(new Runnable() {
    @Override
    public void run() {
      if (index < myActions.size() - 1) {
        restore(index + 1).notifyWhenDone(result);
      } else {
        result.setDone();
      }
    }
  });

  return result;
}
 
Example #11
Source File: TreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ActionCallback moveUp(@Nonnull final JTree tree) {
  int row = tree.getLeadSelectionRow();
  if (row > 0) {
    row--;
    return showAndSelect(tree, row - 2, row, row, getSelectedRow(tree), false, true, true);
  }
  else {
    return ActionCallback.DONE;
  }
}
 
Example #12
Source File: SourceJarGenerator.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
  Collection<Library> libraries = orderEntriesContainingFile.stream()
    .map(LibraryOrderEntry::getLibrary)
    .filter(Objects::nonNull)
    .collect(Collectors.toSet());

  if (libraries.isEmpty()) return ActionCallback.REJECTED;
  return perform(libraries);
}
 
Example #13
Source File: GridCellImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionCallback restoreLastUiState() {
  final ActionCallback result = new ActionCallback();

  restoreProportions();

  Content[] contents = getContents();
  int window = 0;
  for (Content each : contents) {
    final View view = myContainer.getStateFor(each);
    if (view.isMinimizedInGrid()) {
      minimize(each);
    }
    window = view.getWindow();
  }
  final Tab tab = myContainer.getTab();
  final boolean detached = (tab != null && tab.isDetached(myPlaceInGrid)) || window != myContext.getWindow();
  if (detached && contents.length > 0) {
    if (tab != null) {
      tab.setDetached(myPlaceInGrid, false);
    }
    myContext.detachTo(window, this).notifyWhenDone(result);
  }
  else {
    result.setDone();
  }

  return result;
}
 
Example #14
Source File: Promises.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Promise<Object> toPromise(ActionCallback callback) {
  AsyncPromise<Object> promise = new AsyncPromise<>();
  callback.doWhenDone(() -> promise.setResult(null));
  callback.doWhenRejected(error -> promise.setError(createError(error == null ? "Internal error" : error)));
  return promise;
}
 
Example #15
Source File: KeyShortcutCommand.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionCallback _execute(PlaybackContext context) {
  final String one = getText().substring(PREFIX.length());
  if (!one.endsWith(POSTFIX)) {
    dumpError(context, "Expected " + "]");
    return new ActionCallback.Rejected();
  }

  type(context.getRobot(), getFromShortcut(one.substring(0, one.length() - 1).trim()));

  return new ActionCallback.Done();
}
 
Example #16
Source File: ListDelegationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static ActionCallback installKeyboardDelegation(final JComponent focusedComponent, final JList delegateTo) {
  final KeyListener keyListener = new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      final int code = e.getKeyCode();
      final int modifiers = e.getModifiers();
      switch (code) {
        case KeyEvent.VK_UP:
          ScrollingUtil.moveUp(delegateTo, modifiers);
          break;
        case KeyEvent.VK_DOWN:
          ScrollingUtil.moveDown(delegateTo, modifiers);
          break;
        case KeyEvent.VK_HOME:
          ScrollingUtil.moveHome(delegateTo);
          break;
        case KeyEvent.VK_END:
          ScrollingUtil.moveEnd(delegateTo);
          break;
        case KeyEvent.VK_PAGE_UP:
          ScrollingUtil.movePageUp(delegateTo);
          break;
        case KeyEvent.VK_PAGE_DOWN:
          ScrollingUtil.movePageDown(delegateTo);
          break;
      }
    }
  };

  focusedComponent.addKeyListener(keyListener);

  final ActionCallback callback = new ActionCallback();
  callback.doWhenProcessed(() -> focusedComponent.removeKeyListener(keyListener));
  return callback;
}
 
Example #17
Source File: CellTransform.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ActionCallback restoreInGrid() {
  myRestoringNow = true;
  if (myActions.size() == 0) return new ActionCallback.Done();
  final ActionCallback topCallback = restore(0);
  return topCallback.doWhenDone(new Runnable() {
    @Override
    public void run() {
      myActions.clear();
      myRestoringNow = false;
    }
  });
}
 
Example #18
Source File: JBSlidingPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ActionCallback applySlide(JBCardLayout.SwipeDirection direction) {
  final ActionCallback callback = new ActionCallback();
  getLayout().swipe(this, mySlides.get(mySelectedIndex).first, direction, new Runnable() {
    @Override
    public void run() {
      callback.setDone();
    }
  });
  return callback;
}
 
Example #19
Source File: DelayCommand.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionCallback _execute(PlaybackContext context) {
  final String s = getText().substring(PREFIX.length()).trim();

  try {
    final Integer delay = Integer.valueOf(s);
    context.getRobot().delay(delay.intValue());
  }
  catch (NumberFormatException e) {
    dumpError(context, "Invalid delay value: " + s);
    return new ActionCallback.Rejected();
  }

  return new ActionCallback.Done();
}
 
Example #20
Source File: OptionsEditorContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
ActionCallback fireSelected(@Nullable final Configurable configurable, @Nonnull OptionsEditorColleague requestor) {
  if (myCurrentConfigurable == configurable) return new ActionCallback.Rejected();

  final Configurable old = myCurrentConfigurable;
  myCurrentConfigurable = configurable;

  return notify(colleague -> colleague.onSelected(configurable, old), requestor);
}
 
Example #21
Source File: TreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ActionCallback moveDown(@Nonnull final JTree tree) {
  final int size = tree.getRowCount();
  int row = tree.getLeadSelectionRow();
  if (row < size - 1) {
    row++;
    return showAndSelect(tree, row, row + 2, row, getSelectedRow(tree), false, true, true);
  }
  else {
    return ActionCallback.DONE;
  }
}
 
Example #22
Source File: TreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ActionCallback movePageUp(@Nonnull final JTree tree) {
  final int visible = getVisibleRowCount(tree);
  if (visible <= 0) {
    return moveHome(tree);
  }
  final int decrement = visible - 1;
  final int row = Math.max(getSelectedRow(tree) - decrement, 0);
  final int top = getFirstVisibleRow(tree) - decrement;
  final int bottom = top + visible - 1;
  return showAndSelect(tree, top, bottom, row, getSelectedRow(tree));
}
 
Example #23
Source File: IdeFrameDecorator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ActionCallback toggleFullScreen(boolean state) {
  JFrame jFrame = getJFrame();
  if (jFrame != null) {
    myRequestedState = state;
    X11UiUtil.toggleFullScreenMode(jFrame);
  }
  return ActionCallback.DONE;
}
 
Example #24
Source File: TreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ActionCallback selectInTree(Project project, @Nullable DefaultMutableTreeNode node, boolean requestFocus, @Nonnull JTree tree, boolean center) {
  if (node == null) return ActionCallback.DONE;

  final TreePath treePath = new TreePath(node.getPath());
  tree.expandPath(treePath);
  if (requestFocus) {
    ActionCallback result = new ActionCallback(2);
    IdeFocusManager.getInstance(project).requestFocus(tree, true).notifyWhenDone(result);
    selectPath(tree, treePath, center).notifyWhenDone(result);
    return result;
  }
  return selectPath(tree, treePath, center);
}
 
Example #25
Source File: IdeFrameDecorator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ActionCallback toggleFullScreen(boolean state) {
  JFrame jFrame = getJFrame();
  if (jFrame == null) {
    return ActionCallback.REJECTED;
  }

  GraphicsDevice device = ScreenUtil.getScreenDevice(jFrame.getBounds());
  if (device == null) return ActionCallback.REJECTED;

  try {
    jFrame.getRootPane().putClientProperty(ScreenUtil.DISPOSE_TEMPORARY, Boolean.TRUE);
    if (state) {
      jFrame.getRootPane().putClientProperty("oldBounds", jFrame.getBounds());
    }
    jFrame.dispose();
    jFrame.setUndecorated(state);
  }
  finally {
    if (state) {
      jFrame.setBounds(device.getDefaultConfiguration().getBounds());
    }
    else {
      Object o = jFrame.getRootPane().getClientProperty("oldBounds");
      if (o instanceof Rectangle) {
        jFrame.setBounds((Rectangle)o);
      }
    }
    jFrame.setVisible(true);
    jFrame.getRootPane().putClientProperty(ScreenUtil.DISPOSE_TEMPORARY, null);

    notifyFrameComponents(state);
  }
  return ActionCallback.DONE;
}
 
Example #26
Source File: GridImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionCallback restoreLastUiState() {
  final ActionCallback result = new ActionCallback(myPlaceInGrid2Cell.values().size());
  for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) {
    cell.restoreLastUiState().notifyWhenDone(result);
  }

  return result;
}
 
Example #27
Source File: RunAnythingPopupUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void resetFields() {
  myCurrentWorker.doWhenProcessed(() -> {
    final Object lock = myCalcThread;
    if (lock != null) {
      synchronized (lock) {
        myCurrentWorker = ActionCallback.DONE;
        myCalcThread = null;
        myVirtualFile = null;
        myProject = null;
        myModule = null;
      }
    }
  });
  mySkipFocusGain = false;
}
 
Example #28
Source File: NavBarUpdateQueue.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void queueTypeAheadDone(final ActionCallback done) {
  queue(new AfterModelUpdate(ID.TYPE_AHEAD_FINISHED) {
    @Override
    protected void after() {
      done.setDone();
    }
  });
}
 
Example #29
Source File: BackgroundTaskByVfsChangeManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void call(final ProgressIndicator indicator, final VirtualFile file, final List<BackgroundTaskByVfsChangeTask> tasks, final int index) {
  if (index == tasks.size()) {
    file.putUserData(PROCESSING_BACKGROUND_TASK, null);
    return;
  }

  BackgroundTaskByVfsChangeTaskImpl task = (BackgroundTaskByVfsChangeTaskImpl)tasks.get(index);

  ActionCallback callback = new ActionCallback();
  callback.doWhenProcessed(() -> call(indicator, file, tasks, index + 1));
  indicator.setText2("Task: " + task.getName());
  task.run(callback);
}
 
Example #30
Source File: AbstractTreeStructure.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ActionCallback asyncCommitDocuments(@Nonnull Project project) {
  if (project.isDisposed()) return ActionCallback.DONE;
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  if (!documentManager.hasUncommitedDocuments()) {
    return ActionCallback.DONE;
  }
  final ActionCallback callback = new ActionCallback();
  documentManager.performWhenAllCommitted(callback.createSetDoneRunnable());
  return callback;
}