Search in sources :

Example 1 with ActionPopupMenu

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

the class SimpleTree method invokeContextMenu.

protected void invokeContextMenu(final MouseEvent e) {
    SwingUtilities.invokeLater(() -> {
        final ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(myPlace, myPopupGroup);
        menu.getComponent().show(e.getComponent(), e.getPoint().x, e.getPoint().y);
    });
}
Also used : ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu)

Example 2 with ActionPopupMenu

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

the class PopupHandler method installFollowingSelectionTreePopup.

public static MouseListener installFollowingSelectionTreePopup(final JTree tree, @NotNull final ActionGroup group, final String place, final ActionManager actionManager) {
    if (ApplicationManager.getApplication() == null)
        return new MouseAdapter() {
        };
    PopupHandler handler = new PopupHandler() {

        public void invokePopup(Component comp, int x, int y) {
            if (tree.getPathForLocation(x, y) != null && Arrays.binarySearch(tree.getSelectionRows(), tree.getRowForLocation(x, y)) > -1) {
                //do not show popup menu on rows other than selection
                final ActionPopupMenu popupMenu = actionManager.createActionPopupMenu(place, group);
                popupMenu.getComponent().show(comp, x, y);
            }
        }
    };
    tree.addMouseListener(handler);
    return handler;
}
Also used : ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu) MouseAdapter(java.awt.event.MouseAdapter)

Example 3 with ActionPopupMenu

use of com.intellij.openapi.actionSystem.ActionPopupMenu in project azure-tools-for-java by Microsoft.

the class Tree method installPopupMenu.

public static void installPopupMenu(JTree tree) {
    final MouseAdapter popupHandler = new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            final TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            final Object node = path.getLastPathComponent();
            if (node instanceof TreeNode) {
                if (SwingUtilities.isLeftMouseButton(e)) {
                    if (((TreeNode<?>) node).inner.hasChildren() && ((TreeNode<?>) node).loaded == null) {
                        ((TreeNode<?>) node).refreshChildren();
                        tree.expandPath(path);
                    }
                } else if (SwingUtilities.isRightMouseButton(e) || e.isPopupTrigger()) {
                    final ActionGroup actions = ((TreeNode<?>) node).inner.actions();
                    if (Objects.nonNull(actions)) {
                        final ActionManager am = ActionManager.getInstance();
                        final ActionPopupMenu menu = am.createActionPopupMenu("azure.component.tree", toIntellijActionGroup(actions));
                        menu.setTargetComponent(tree);
                        menu.getComponent().show(tree, e.getX(), e.getY());
                    }
                }
            }
        }

        private com.intellij.openapi.actionSystem.ActionGroup toIntellijActionGroup(ActionGroup actions) {
            final ActionManager am = ActionManager.getInstance();
            if (actions instanceof ActionGroup.Proxy) {
                final String id = ((ActionGroup.Proxy) actions).id();
                if (Objects.nonNull(id)) {
                    return (com.intellij.openapi.actionSystem.ActionGroup) am.getAction(id);
                }
            }
            return new IntellijAzureActionManager.ActionGroupWrapper(actions);
        }
    };
    tree.addMouseListener(popupHandler);
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) ActionManager(com.intellij.openapi.actionSystem.ActionManager) IntellijAzureActionManager(com.microsoft.azure.toolkit.intellij.common.action.IntellijAzureActionManager) TreePath(javax.swing.tree.TreePath) ActionGroup(com.microsoft.azure.toolkit.lib.common.action.ActionGroup) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu)

Example 4 with ActionPopupMenu

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

the class EditorActionUtil method showEditorPopup.

private static void showEditorPopup(final EditorMouseEvent event, @NotNull final ActionGroup group) {
    if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) {
        ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.EDITOR_POPUP, group);
        MouseEvent e = event.getMouseEvent();
        final Component c = e.getComponent();
        if (c != null && c.isShowing()) {
            popupMenu.getComponent().show(c, e.getX(), e.getY());
        }
        e.consume();
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu)

Example 5 with ActionPopupMenu

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

the class PopupHandler method installPopupHandler.

public static MouseListener installPopupHandler(JComponent component, @NotNull final ActionGroup group, final String place, final ActionManager actionManager) {
    if (ApplicationManager.getApplication() == null)
        return new MouseAdapter() {
        };
    PopupHandler popupHandler = new PopupHandler() {

        public void invokePopup(Component comp, int x, int y) {
            final ActionPopupMenu popupMenu = actionManager.createActionPopupMenu(place, group);
            popupMenu.getComponent().show(comp, x, y);
        }
    };
    component.addMouseListener(popupHandler);
    return popupHandler;
}
Also used : ActionPopupMenu(com.intellij.openapi.actionSystem.ActionPopupMenu) MouseAdapter(java.awt.event.MouseAdapter)

Aggregations

ActionPopupMenu (com.intellij.openapi.actionSystem.ActionPopupMenu)10 ActionManager (com.intellij.openapi.actionSystem.ActionManager)3 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)3 MouseEvent (java.awt.event.MouseEvent)3 MouseAdapter (java.awt.event.MouseAdapter)2 CommonBundle.getCancelButtonText (com.intellij.CommonBundle.getCancelButtonText)1 IdeBundle (com.intellij.ide.IdeBundle)1 com.intellij.ide.todo (com.intellij.ide.todo)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 ActionPlaces (com.intellij.openapi.actionSystem.ActionPlaces)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ApplicationNamesInfo (com.intellij.openapi.application.ApplicationNamesInfo)1 ModalityState (com.intellij.openapi.application.ModalityState)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 EditorMouseEvent (com.intellij.openapi.editor.event.EditorMouseEvent)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Task (com.intellij.openapi.progress.Task)1 DumbService (com.intellij.openapi.project.DumbService)1