Search in sources :

Example 1 with ActionMenuItem

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

the class JBPopupFixture method invokeAction.

public void invokeAction(String... actionPath) {
    boolean assertion = false;
    final MenuElement[] elements = myContextMenu.getSubElements();
    if (actionPath.length > 1) {
        //actionGroup
        for (MenuElement element : elements) {
            if (element instanceof ActionMenu) {
                final ActionMenu actionMenu = (ActionMenu) element;
                if (actionMenu.getText().toLowerCase().contains(actionPath[0].toLowerCase())) {
                    final Point locationOnScreen = myContextMenu.getLocationOnScreen();
                    final Rectangle bounds = actionMenu.getBounds();
                    final Point point = new Point(locationOnScreen.x + bounds.x + bounds.width / 2, locationOnScreen.y + bounds.y + bounds.height / 2);
                    robot().click(point, MouseButton.LEFT_BUTTON, 1);
                    //invoke action for a new JBPopupMenu
                    final String actionName = actionPath[1];
                    final JBPopupFixture fixture = new JBPopupFixture(waitUntilFoundMenu(actionName), myRobot);
                    fixture.invokeAction(ArrayUtil.remove(actionPath, 0));
                    return;
                }
            }
        }
    } else {
        //actionMenuItem
        for (MenuElement element : elements) {
            if (element instanceof ActionMenuItem) {
                final ActionMenuItem actionMenuItem = (ActionMenuItem) element;
                if (actionMenuItem.getText().toLowerCase().contains(actionPath[0].toLowerCase())) {
                    pause(new Condition("Waiting to showing JBPopupMenu on screen") {

                        @Override
                        public boolean test() {
                            try {
                                myContextMenu.getLocationOnScreen();
                                return true;
                            } catch (IllegalComponentStateException e) {
                                return false;
                            }
                        }
                    }, SHORT_TIMEOUT);
                    final Point locationOnScreen = myContextMenu.getLocationOnScreen();
                    final Rectangle bounds = actionMenuItem.getBounds();
                    final Point point = new Point(locationOnScreen.x + bounds.x + bounds.width / 2, locationOnScreen.y + bounds.y + bounds.height / 2);
                    robot().click(point, MouseButton.LEFT_BUTTON, 1);
                    return;
                }
            }
        }
    }
}
Also used : Condition(org.fest.swing.timing.Condition) ActionMenuItem(com.intellij.openapi.actionSystem.impl.ActionMenuItem) ActionMenu(com.intellij.openapi.actionSystem.impl.ActionMenu)

Example 2 with ActionMenuItem

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

the class BegMenuItemUI method doClick.

/** Copied from BasicMenuItemUI */
private void doClick(MenuSelectionManager msm, MouseEvent e) {
    // Auditory cue
    if (!isInternalFrameSystemMenu()) {
        @NonNls ActionMap map = menuItem.getActionMap();
        if (map != null) {
            Action audioAction = map.get(getPropertyPrefix() + ".commandSound");
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                BasicLookAndFeel lf = (BasicLookAndFeel) UIManager.getLookAndFeel();
                // it's imposible to mormally invoke it.
                try {
                    Method playSoundMethod = BasicLookAndFeel.class.getDeclaredMethod(PLAY_SOUND_METHOD, new Class[] { Action.class });
                    playSoundMethod.setAccessible(true);
                    playSoundMethod.invoke(lf, new Object[] { audioAction });
                } catch (Exception ignored) {
                }
            }
        }
    }
    // Visual feedback
    if (msm == null) {
        msm = MenuSelectionManager.defaultManager();
    }
    msm.clearSelectedPath();
    ((ActionMenuItem) menuItem).fireActionPerformed(new ActionEvent(menuItem, ActionEvent.ACTION_PERFORMED, null, e.getWhen(), e.getModifiers()));
}
Also used : NonNls(org.jetbrains.annotations.NonNls) BasicLookAndFeel(javax.swing.plaf.basic.BasicLookAndFeel) ActionEvent(java.awt.event.ActionEvent) ActionMenuItem(com.intellij.openapi.actionSystem.impl.ActionMenuItem) Method(java.lang.reflect.Method)

Example 3 with ActionMenuItem

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

the class ProjectWindowAction method setSelected.

@Override
public void setSelected(@Nullable AnActionEvent e, boolean selected) {
    if (e == null)
        return;
    boolean macMainMenu = SystemInfo.isMac && ActionPlaces.isMainMenuOrActionSearch(e.getPlace());
    if (!selected && !macMainMenu) {
        return;
    }
    final Project project = findProject();
    if (project == null) {
        return;
    }
    final JFrame projectFrame = WindowManager.getInstance().getFrame(project);
    final int frameState = projectFrame.getExtendedState();
    if (macMainMenu && !(e.getInputEvent().getSource() instanceof ActionMenuItem) && (projectFrame.getExtendedState() & Frame.ICONIFIED) != 0) {
        // On Mac minimized window should not be restored this way
        return;
    }
    if (BitUtil.isSet(frameState, Frame.ICONIFIED)) {
        // restore the frame if it is minimized
        projectFrame.setExtendedState(frameState ^ Frame.ICONIFIED);
    }
    projectFrame.toFront();
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
        IdeFocusManager.getGlobalInstance().requestFocus(projectFrame, true);
    });
//ProjectUtil.focusProjectWindow(project, true);
}
Also used : Project(com.intellij.openapi.project.Project) ActionMenuItem(com.intellij.openapi.actionSystem.impl.ActionMenuItem)

Aggregations

ActionMenuItem (com.intellij.openapi.actionSystem.impl.ActionMenuItem)3 ActionMenu (com.intellij.openapi.actionSystem.impl.ActionMenu)1 Project (com.intellij.openapi.project.Project)1 ActionEvent (java.awt.event.ActionEvent)1 Method (java.lang.reflect.Method)1 BasicLookAndFeel (javax.swing.plaf.basic.BasicLookAndFeel)1 Condition (org.fest.swing.timing.Condition)1 NonNls (org.jetbrains.annotations.NonNls)1