Search in sources :

Example 1 with ActionMenu

use of com.intellij.openapi.actionSystem.impl.ActionMenu 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 ActionMenu

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

the class IdeMenuBar method updateMenuActions.

void updateMenuActions() {
    myNewVisibleActions.clear();
    if (!myDisabled) {
        DataContext dataContext = ((DataManagerImpl) myDataManager).getDataContextTest(this);
        expandActionGroup(dataContext, myNewVisibleActions, myActionManager);
    }
    if (!myNewVisibleActions.equals(myVisibleActions)) {
        // should rebuild UI
        final boolean changeBarVisibility = myNewVisibleActions.isEmpty() || myVisibleActions.isEmpty();
        final List<AnAction> temp = myVisibleActions;
        myVisibleActions = myNewVisibleActions;
        myNewVisibleActions = temp;
        removeAll();
        final boolean enableMnemonics = !UISettings.getInstance().getDisableMnemonics();
        for (final AnAction action : myVisibleActions) {
            add(new ActionMenu(null, ActionPlaces.MAIN_MENU, (ActionGroup) action, myPresentationFactory, enableMnemonics, true));
        }
        fixMenuBackground();
        updateMnemonicsVisibility();
        if (myClockPanel != null) {
            add(myClockPanel);
            add(myButton);
        }
        validate();
        if (changeBarVisibility) {
            invalidate();
            final JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, this);
            if (frame != null) {
                frame.validate();
            }
        }
    }
}
Also used : ActionMenu(com.intellij.openapi.actionSystem.impl.ActionMenu) DataManagerImpl(com.intellij.ide.impl.DataManagerImpl)

Aggregations

ActionMenu (com.intellij.openapi.actionSystem.impl.ActionMenu)2 DataManagerImpl (com.intellij.ide.impl.DataManagerImpl)1 ActionMenuItem (com.intellij.openapi.actionSystem.impl.ActionMenuItem)1 Condition (org.fest.swing.timing.Condition)1