Search in sources :

Example 16 with ActionButton

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

the class ActionButtonFixture method findByActionId.

@NotNull
public static ActionButtonFixture findByActionId(@NotNull final String actionId, @NotNull final Robot robot, @NotNull final Container container, Timeout timeout) {
    final Ref<ActionButton> actionButtonRef = new Ref<ActionButton>();
    Pause.pause(new Condition("Find ActionButton with ID '" + actionId + "'") {

        @Override
        public boolean test() {
            Collection<ActionButton> found = robot.finder().findAll(container, new GenericTypeMatcher<ActionButton>(ActionButton.class) {

                @Override
                protected boolean isMatching(@NotNull ActionButton button) {
                    if (button.isVisible()) {
                        AnAction action = button.getAction();
                        if (action != null) {
                            String id = ActionManager.getInstance().getId(action);
                            return actionId.equals(id);
                        }
                    }
                    return false;
                }
            });
            if (found.size() == 1) {
                actionButtonRef.set(getFirstItem(found));
                return true;
            }
            return false;
        }
    }, timeout);
    ActionButton button = actionButtonRef.get();
    if (button == null) {
        throw new ComponentLookupException("Failed to find ActionButton with ID '" + actionId + "'");
    }
    return new ActionButtonFixture(robot, button);
}
Also used : Condition(org.fest.swing.timing.Condition) Ref(com.intellij.openapi.util.Ref) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) Collection(java.util.Collection) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) NotNull(org.jetbrains.annotations.NotNull) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with ActionButton

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

the class PropertyTablePanel method setCurrentTab.

public void setCurrentTab(@NotNull PropertyTableTab currentTab) {
    myCurrentTab = currentTab;
    for (Component component : myTabPanel.getComponents()) {
        ActionButton button = (ActionButton) component;
        TableTabAction action = (TableTabAction) button.getAction();
        action.updateState();
    }
    myPropertyTable.update();
}
Also used : ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton)

Example 18 with ActionButton

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

the class RichTextActionProcessor method process.

@Override
public JComponent process(@NotNull String s) {
    final ActionManager actionManager = ActionManager.getInstance();
    final AnAction action = actionManager.getAction(s);
    if (action == null) {
        return null;
    }
    final Presentation presentation = action.getTemplatePresentation();
    if (presentation.getIcon() != null) {
        return new ActionButton(action, presentation.clone(), GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, JBUI.emptySize()) {

            @Override
            protected void paintButtonLook(Graphics g) {
                // Don't draw border at the inline button.
                ActionButtonLook look = getButtonLook();
                look.paintBackground(g, this);
                look.paintIcon(g, this, getIcon());
            }
        };
    }
    final String text = action.getTemplatePresentation().getText();
    JLabel result = new JLabel(text) {

        public void paint(Graphics g) {
            super.paint(g);
            final int y = g.getClipBounds().height - getFontMetrics(getFont()).getDescent() + 2;
            final int width = getFontMetrics(getFont()).stringWidth(getText());
            g.drawLine(0, y, width, y);
        }
    };
    Color color = UIUtil.isUnderDarcula() ? Color.ORANGE : Color.BLUE;
    result.setForeground(color);
    result.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            final AsyncResult<DataContext> callback = DataManager.getInstance().getDataContextFromFocus();
            final DataContext context = callback.getResult();
            if (context == null) {
                return false;
            }
            final Presentation presentation = new PresentationFactory().getPresentation(action);
            action.actionPerformed(new AnActionEvent(e, context, GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, presentation, ActionManager.getInstance(), e.getModifiers()));
            return true;
        }
    }.installOn(result);
    return result;
}
Also used : MouseEvent(java.awt.event.MouseEvent) PresentationFactory(com.intellij.openapi.actionSystem.impl.PresentationFactory) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) AsyncResult(com.intellij.openapi.util.AsyncResult) ActionButtonLook(com.intellij.openapi.actionSystem.ex.ActionButtonLook) ClickListener(com.intellij.ui.ClickListener)

Example 19 with ActionButton

use of com.intellij.openapi.actionSystem.impl.ActionButton in project android by JetBrains.

the class AttachedToolWindowTest method findButtonByName.

private static ActionButton findButtonByName(@NotNull Container container, @NotNull String name) {
    for (Component component : container.getComponents()) {
        if (component instanceof ActionButton) {
            ActionButton button = (ActionButton) component;
            AnAction action = button.getAction();
            if (action != null && name.equals(action.getTemplatePresentation().getText())) {
                return button;
            }
        }
        if (component instanceof Container) {
            ActionButton button = findButtonByName((Container) component, name);
            if (button != null) {
                return button;
            }
        }
    }
    return null;
}
Also used : ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 20 with ActionButton

use of com.intellij.openapi.actionSystem.impl.ActionButton in project android by JetBrains.

the class AttachedToolWindowTest method getPopupMenuFromGearButtonInHeader.

private DefaultActionGroup getPopupMenuFromGearButtonInHeader() {
    ActionButton button = findButtonByName(myToolWindow.getComponent(), "Gear");
    assertThat(button).isNotNull();
    button.click();
    ArgumentCaptor<ActionGroup> menuCaptor = ArgumentCaptor.forClass(ActionGroup.class);
    verify(myActionManager).createActionPopupMenu(eq(ToolWindowContentUi.POPUP_PLACE), menuCaptor.capture());
    return (DefaultActionGroup) menuCaptor.getValue();
}
Also used : ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton)

Aggregations

ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)23 NotNull (org.jetbrains.annotations.NotNull)6 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Test (org.junit.Test)3 ActionButtonFixture (com.android.tools.idea.tests.gui.framework.fixture.ActionButtonFixture)2 PresentationFactory (com.intellij.openapi.actionSystem.impl.PresentationFactory)2 Ref (com.intellij.openapi.util.Ref)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ComponentLookupException (org.fest.swing.exception.ComponentLookupException)2 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 GotoFileCellRenderer (com.intellij.ide.util.gotoByName.GotoFileCellRenderer)1 ActionButtonLook (com.intellij.openapi.actionSystem.ex.ActionButtonLook)1 InplaceActionButtonLook (com.intellij.openapi.actionSystem.impl.InplaceActionButtonLook)1 Project (com.intellij.openapi.project.Project)1 ExistingLibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor)1 LibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor)1 LibraryRootsComponent (com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryRootsComponent)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 MultiLineLabel (com.intellij.openapi.ui.ex.MultiLineLabel)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1