Search in sources :

Example 41 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class WindowSystemPlaybackCall method contextMenu.

public static AsyncResult<String> contextMenu(final PlaybackContext context, final String path) {
    final AsyncResult<String> result = new AsyncResult<>();
    final IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
    fm.doWhenFocusSettlesDown(() -> {
        Component owner = fm.getFocusOwner();
        if (owner == null) {
            result.setRejected("No component focused");
            return;
        }
        ActionManager am = ActionManager.getInstance();
        AnAction showPopupMenu = am.getAction("ShowPopupMenu");
        if (showPopupMenu == null) {
            result.setRejected("Cannot find action: ShowPopupMenu");
            return;
        }
        am.tryToExecute(showPopupMenu, new MouseEvent(owner, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, 0, 0, 1, true), null, null, false).doWhenDone(() -> SwingUtilities.invokeLater(() -> {
            MenuElement[] selectedPath = MenuSelectionManager.defaultManager().getSelectedPath();
            if (selectedPath.length == 0) {
                result.setRejected("Failed to find active popup menu");
                return;
            }
            selectNext(context, path.split("\\|"), 0, selectedPath[0].getSubElements(), result);
        })).doWhenRejected(() -> result.setRejected("Cannot invoke popup menu from the ShowPopupMenu action, action call rejected"));
    });
    return result;
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) MouseEvent(java.awt.event.MouseEvent) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) AsyncResult(com.intellij.openapi.util.AsyncResult) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 42 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class BalloonImpl method show.

private void show(PositionTracker<Balloon> tracker, AbstractPosition position) {
    assert !myDisposed : "Balloon is already disposed";
    if (isVisible())
        return;
    final Component comp = tracker.getComponent();
    if (!comp.isShowing())
        return;
    myTracker = tracker;
    myTracker.init(this);
    JRootPane root = ObjectUtils.notNull(UIUtil.getRootPane(comp));
    myVisible = true;
    myLayeredPane = root.getLayeredPane();
    myPosition = position;
    UIUtil.setFutureRootPane(myContent, root);
    myFocusManager = IdeFocusManager.findInstanceByComponent(myLayeredPane);
    final Ref<Component> originalFocusOwner = new Ref<>();
    final Ref<FocusRequestor> focusRequestor = new Ref<>();
    final Ref<ActionCallback> proxyFocusRequest = new Ref<>(ActionCallback.DONE);
    boolean mnemonicsFix = myDialogMode && SystemInfo.isMac && Registry.is("ide.mac.inplaceDialogMnemonicsFix");
    if (mnemonicsFix) {
        final IdeGlassPaneEx glassPane = (IdeGlassPaneEx) IdeGlassPaneUtil.find(myLayeredPane);
        assert glassPane != null;
        proxyFocusRequest.set(new ActionCallback());
        myFocusManager.doWhenFocusSettlesDown(new ExpirableRunnable() {

            @Override
            public boolean isExpired() {
                return isDisposed();
            }

            @Override
            public void run() {
                IdeEventQueue.getInstance().disableInputMethods(BalloonImpl.this);
                originalFocusOwner.set(myFocusManager.getFocusOwner());
                focusRequestor.set(myFocusManager.getFurtherRequestor());
            }
        });
    }
    if (myRequestFocus) {
        myFocusManager.doWhenFocusSettlesDown(new ExpirableRunnable() {

            @Override
            public boolean isExpired() {
                return isDisposed();
            }

            @Override
            public void run() {
                myOriginalFocusOwner = myFocusManager.getFocusOwner();
                // Set the accessible parent so that screen readers don't announce
                // a window context change -- the tooltip is "logically" hosted
                // inside the component (e.g. editor) it appears on top of.
                AccessibleContextUtil.setParent(myContent, myOriginalFocusOwner);
                // Set the focus to "myContent"
                myFocusManager.requestFocus(getContentToFocus(), true);
            }
        });
    }
    myLayeredPane.addComponentListener(myComponentListener);
    myTargetPoint = myPosition.getShiftedPoint(myTracker.recalculateLocation(this).getPoint(myLayeredPane), myCalloutShift);
    int positionChangeFix = 0;
    if (myShowPointer) {
        Rectangle rec = getRecForPosition(myPosition, true);
        if (!myPosition.isOkToHavePointer(myTargetPoint, rec, getPointerLength(myPosition), getPointerWidth(myPosition), getArc())) {
            rec = getRecForPosition(myPosition, false);
            Rectangle lp = new Rectangle(new Point(myContainerInsets.left, myContainerInsets.top), myLayeredPane.getSize());
            lp.width -= myContainerInsets.right;
            lp.height -= myContainerInsets.bottom;
            if (!lp.contains(rec)) {
                Rectangle2D currentSquare = lp.createIntersection(rec);
                double maxSquare = currentSquare.getWidth() * currentSquare.getHeight();
                AbstractPosition targetPosition = myPosition;
                for (AbstractPosition eachPosition : myPosition.getOtherPositions()) {
                    Rectangle2D eachIntersection = lp.createIntersection(getRecForPosition(eachPosition, false));
                    double eachSquare = eachIntersection.getWidth() * eachIntersection.getHeight();
                    if (maxSquare < eachSquare) {
                        maxSquare = eachSquare;
                        targetPosition = eachPosition;
                    }
                }
                myPosition = targetPosition;
                positionChangeFix = myPosition.getChangeShift(position, myPositionChangeXShift, myPositionChangeYShift);
            }
        }
    }
    if (myPosition != position) {
        myTargetPoint = myPosition.getShiftedPoint(myTracker.recalculateLocation(this).getPoint(myLayeredPane), myCalloutShift > 0 ? myCalloutShift + positionChangeFix : positionChangeFix);
    }
    createComponent();
    myComp.validate();
    Rectangle rec = myComp.getContentBounds();
    if (myShowPointer && !myPosition.isOkToHavePointer(myTargetPoint, rec, getPointerLength(myPosition), getPointerWidth(myPosition), getArc())) {
        myShowPointer = false;
        myComp.removeAll();
        myLayeredPane.remove(myComp);
        createComponent();
        if (!new Rectangle(myLayeredPane.getSize()).contains(new Rectangle(myComp.getSize()))) {
            // Balloon is bigger than window, don't show it at all.
            myComp.removeAll();
            myLayeredPane.remove(myComp);
            myLayeredPane = null;
            hide();
            return;
        }
    }
    for (JBPopupListener each : myListeners) {
        each.beforeShown(new LightweightWindowEvent(this));
    }
    runAnimation(true, myLayeredPane, null);
    myLayeredPane.revalidate();
    myLayeredPane.repaint();
    if (mnemonicsFix) {
        proxyFocusRequest.get().doWhenDone(() -> myFocusManager.requestFocus(originalFocusOwner.get(), true));
    }
    Toolkit.getDefaultToolkit().addAWTEventListener(myAwtActivityListener, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
    if (ApplicationManager.getApplication() != null) {
        ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() {

            @Override
            public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
                if (myHideOnAction) {
                    hide();
                }
            }
        }, this);
    }
    if (myHideOnLinkClick) {
        JEditorPane editorPane = UIUtil.uiTraverser(myContent).traverse().filter(JEditorPane.class).first();
        if (editorPane != null) {
            editorPane.addHyperlinkListener(new HyperlinkAdapter() {

                @Override
                protected void hyperlinkActivated(HyperlinkEvent e) {
                    hide();
                }
            });
        }
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) IdeGlassPaneEx(com.intellij.openapi.wm.impl.IdeGlassPaneEx) JBPopupListener(com.intellij.openapi.ui.popup.JBPopupListener) DataContext(com.intellij.openapi.actionSystem.DataContext) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) FocusRequestor(com.intellij.openapi.wm.FocusRequestor) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 43 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class StatusPanel method createCopyAction.

private Action createCopyAction() {
    ActionManager actionManager = ActionManager.getInstance();
    if (actionManager == null)
        return null;
    AnAction action = actionManager.getAction(IdeActions.ACTION_COPY);
    if (action == null)
        return null;
    return new AbstractAction(action.getTemplatePresentation().getText(), action.getTemplatePresentation().getIcon()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            StringSelection content = new StringSelection(getText());
            ClipboardSynchronizer.getInstance().setContent(content, content);
        }

        @Override
        public boolean isEnabled() {
            return !getText().isEmpty();
        }
    };
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) ActionEvent(java.awt.event.ActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) StringSelection(java.awt.datatransfer.StringSelection)

Example 44 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class ChangeProjectIconAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    List<AnAction> elements = getSelectedElements(e);
    String path = ((ReopenProjectAction) elements.get(0)).getProjectPath();
    final ChangeProjectIconForm form = new ChangeProjectIconForm(path);
    DialogWrapper dialog = new DialogWrapper(null) {

        {
            init();
        }

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            return form.myRootPanel;
        }
    };
    dialog.show();
    if (dialog.isOK()) {
        try {
            form.apply();
        } catch (IOException e1) {
            System.out.println(e1);
        }
    }
}
Also used : ReopenProjectAction(com.intellij.ide.ReopenProjectAction) IOException(java.io.IOException) AnAction(com.intellij.openapi.actionSystem.AnAction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 45 with AnAction

use of com.intellij.openapi.actionSystem.AnAction in project intellij-community by JetBrains.

the class MoveProjectToGroupAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final List<AnAction> elements = getSelectedElements(e);
    for (AnAction element : elements) {
        if (element instanceof ReopenProjectAction) {
            final String path = ((ReopenProjectAction) element).getProjectPath();
            for (ProjectGroup group : RecentProjectsManager.getInstance().getGroups()) {
                group.removeProject(path);
                myGroup.addProject(path);
            }
        }
    }
    rebuildRecentProjectsList(e);
}
Also used : ReopenProjectAction(com.intellij.ide.ReopenProjectAction) AnAction(com.intellij.openapi.actionSystem.AnAction) ProjectGroup(com.intellij.ide.ProjectGroup)

Aggregations

AnAction (com.intellij.openapi.actionSystem.AnAction)184 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)62 NotNull (org.jetbrains.annotations.NotNull)31 Project (com.intellij.openapi.project.Project)24 Nullable (org.jetbrains.annotations.Nullable)22 ActionManager (com.intellij.openapi.actionSystem.ActionManager)21 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)21 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)13 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)7 Presentation (com.intellij.openapi.actionSystem.Presentation)7 PsiFile (com.intellij.psi.PsiFile)7 ReopenProjectAction (com.intellij.ide.ReopenProjectAction)6 Editor (com.intellij.openapi.editor.Editor)6 Keymap (com.intellij.openapi.keymap.Keymap)6 Ref (com.intellij.openapi.util.Ref)6 List (java.util.List)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5