Search in sources :

Example 51 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class JBSlidingPanel method swipe.

public ActionCallback swipe(String id, JBCardLayout.SwipeDirection direction) {
    final ActionCallback done = new ActionCallback();
    getLayout().swipe(this, id, direction, () -> done.setDone());
    return done;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 52 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class Utils method fillMenu.

public static void fillMenu(@NotNull final ActionGroup group, final JComponent component, final boolean enableMnemonics, final PresentationFactory presentationFactory, @NotNull DataContext context, final String place, final boolean isWindowMenu, final boolean mayDataContextBeInvalid, boolean isInModalContext) {
    final ActionCallback menuBuilt = new ActionCallback();
    final boolean checked = group instanceof CheckedActionGroup;
    final ArrayList<AnAction> list = new ArrayList<>();
    expandActionGroup(isInModalContext, group, list, presentationFactory, context, place, ActionManager.getInstance());
    final boolean fixMacScreenMenu = SystemInfo.isMacSystemMenu && isWindowMenu && Registry.is("actionSystem.mac.screenMenuNotUpdatedFix");
    final ArrayList<Component> children = new ArrayList<>();
    for (int i = 0, size = list.size(); i < size; i++) {
        final AnAction action = list.get(i);
        if (action instanceof Separator) {
            final String text = ((Separator) action).getText();
            if (!StringUtil.isEmpty(text) || (i > 0 && i < size - 1)) {
                component.add(new JPopupMenu.Separator() {

                    private final JMenuItem myMenu = !StringUtil.isEmpty(text) ? new JMenuItem(text) : null;

                    @Override
                    public Insets getInsets() {
                        final Insets insets = super.getInsets();
                        final boolean fix = UIUtil.isUnderGTKLookAndFeel() && getBorder() != null && insets.top + insets.bottom == 0;
                        // workaround for Sun bug #6636964
                        return fix ? new Insets(2, insets.left, 3, insets.right) : insets;
                    }

                    @Override
                    public void doLayout() {
                        super.doLayout();
                        if (myMenu != null) {
                            myMenu.setBounds(getBounds());
                        }
                    }

                    @Override
                    protected void paintComponent(Graphics g) {
                        if (UIUtil.isUnderWindowsClassicLookAndFeel() || UIUtil.isUnderDarcula() || UIUtil.isUnderWindowsLookAndFeel() || (SystemInfo.isWindows && Registry.is("ide.intellij.laf.win10.ui"))) {
                            g.setColor(component.getBackground());
                            g.fillRect(0, 0, getWidth(), getHeight());
                        }
                        if (myMenu != null) {
                            myMenu.paint(g);
                        } else {
                            if (SystemInfo.isMac) {
                                Graphics2D g2 = (Graphics2D) g.create();
                                g2.setStroke(new BasicStroke(2));
                                g2.setColor(UIUtil.AQUA_SEPARATOR_FOREGROUND_COLOR);
                                double y = (double) getHeight() / 2;
                                g2.draw(new Line2D.Double(0, y, getWidth(), y));
                                return;
                            }
                            super.paintComponent(g);
                        }
                    }

                    @Override
                    public Dimension getPreferredSize() {
                        return myMenu != null ? myMenu.getPreferredSize() : super.getPreferredSize();
                    }
                });
            }
        } else if (action instanceof ActionGroup && !(((ActionGroup) action).canBePerformed(context) && !hasVisibleChildren((ActionGroup) action, presentationFactory, context, place))) {
            ActionMenu menu = new ActionMenu(context, place, (ActionGroup) action, presentationFactory, enableMnemonics, false);
            component.add(menu);
            children.add(menu);
        } else {
            final ActionMenuItem each = new ActionMenuItem(action, presentationFactory.getPresentation(action), place, context, enableMnemonics, !fixMacScreenMenu, checked);
            component.add(each);
            children.add(each);
        }
    }
    if (list.isEmpty()) {
        final ActionMenuItem each = new ActionMenuItem(EMPTY_MENU_FILLER, presentationFactory.getPresentation(EMPTY_MENU_FILLER), place, context, enableMnemonics, !fixMacScreenMenu, checked);
        component.add(each);
        children.add(each);
    }
    if (fixMacScreenMenu) {
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(() -> {
            for (Component each : children) {
                if (each.getParent() != null && each instanceof ActionMenuItem) {
                    ((ActionMenuItem) each).prepare();
                }
            }
            menuBuilt.setDone();
        });
    } else {
        menuBuilt.setDone();
    }
    menuBuilt.doWhenDone(() -> {
        if (!mayDataContextBeInvalid)
            return;
        if (IdeFocusManager.getInstance(null).isFocusBeingTransferred()) {
            IdeFocusManager.getInstance(null).doWhenFocusSettlesDown(() -> {
                if (!component.isShowing())
                    return;
                DataContext context1 = DataManager.getInstance().getDataContext();
                expandActionGroup(LaterInvocator.isInModalContext(), group, new ArrayList<>(), presentationFactory, context1, place, ActionManager.getInstance());
                for (Component each : children) {
                    if (each instanceof ActionMenuItem) {
                        ((ActionMenuItem) each).updateContext(context1);
                    } else if (each instanceof ActionMenu) {
                        ((ActionMenu) each).updateContext(context1);
                    }
                }
            });
        }
    });
}
Also used : ArrayList(java.util.ArrayList) ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 53 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class ActionManagerImpl method tryToExecute.

@Override
public ActionCallback tryToExecute(@NotNull final AnAction action, @NotNull final InputEvent inputEvent, @Nullable final Component contextComponent, @Nullable final String place, boolean now) {
    final Application app = ApplicationManager.getApplication();
    assert app.isDispatchThread();
    final ActionCallback result = new ActionCallback();
    final Runnable doRunnable = () -> tryToExecuteNow(action, inputEvent, contextComponent, place, result);
    if (now) {
        doRunnable.run();
    } else {
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(doRunnable);
    }
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 54 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class LaterInvocator method invokeLater.

@NotNull
static ActionCallback invokeLater(@NotNull Runnable runnable, @NotNull ModalityState modalityState, @NotNull Condition<?> expired) {
    if (expired.value(null))
        return ActionCallback.REJECTED;
    final ActionCallback callback = new ActionCallback();
    RunnableInfo runnableInfo = new RunnableInfo(runnable, modalityState, expired, callback);
    synchronized (LOCK) {
        ourQueue.add(runnableInfo);
    }
    requestFlush();
    return callback;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 55 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.

the class PlaybackRunner method run.

public ActionCallback run() {
    myStopRequested = false;
    myRegistryValues.clear();
    final UiActivityMonitor activityMonitor = UiActivityMonitor.getInstance();
    activityMonitor.clear();
    activityMonitor.setActive(true);
    myCurrentStageDepth.clear();
    myPassedStages.clear();
    myContextTimestamp++;
    ApplicationManager.getApplication().getMessageBus().connect(ApplicationManager.getApplication()).subscribe(ApplicationActivationListener.TOPIC, myAppListener);
    try {
        myActionCallback = new ActionCallback();
        myActionCallback.doWhenProcessed(() -> {
            stop();
            SwingUtilities.invokeLater(() -> {
                activityMonitor.setActive(false);
                restoreRegistryValues();
            });
        });
        myRobot = new Robot();
        parse();
        new Thread("playback runner") {

            @Override
            public void run() {
                if (myUseDirectActionCall) {
                    executeFrom(0, getScriptDir());
                } else {
                    IdeEventQueue.getInstance().doWhenReady(() -> executeFrom(0, getScriptDir()));
                }
            }
        }.start();
    } catch (AWTException e) {
        LOG.error(e);
    }
    return myActionCallback;
}
Also used : UiActivityMonitor(com.intellij.ide.UiActivityMonitor) ActionCallback(com.intellij.openapi.util.ActionCallback)

Aggregations

ActionCallback (com.intellij.openapi.util.ActionCallback)70 NotNull (org.jetbrains.annotations.NotNull)16 IOException (java.io.IOException)5 Notification (com.intellij.notification.Notification)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrayList (java.util.ArrayList)4 ProjectView (com.intellij.ide.projectView.ProjectView)3 Configurable (com.intellij.openapi.options.Configurable)3 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)3 AsyncResult (com.intellij.openapi.util.AsyncResult)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 DocumentInfo (com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 Project (com.intellij.openapi.project.Project)2 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)2 MasterDetailsComponent (com.intellij.openapi.ui.MasterDetailsComponent)2 NamedConfigurable (com.intellij.openapi.ui.NamedConfigurable)2 TypingTarget (com.intellij.openapi.ui.TypingTarget)2 FocusCommand (com.intellij.openapi.wm.FocusCommand)2