Search in sources :

Example 1 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project buck by facebook.

the class BuckBuildManager method showNoTargetMessage.

/**
   * Print "no selected target" error message to console window.
   * Also provide a hyperlink which can directly jump to "Choose Target" GUI window.
   */
public void showNoTargetMessage(Project project) {
    BuckModule buckModule = project.getComponent(BuckModule.class);
    buckModule.getBuckEventsConsumer().consumeConsoleEvent("Please choose a build target!");
    BuckToolWindowFactory.outputConsoleMessage(project, "Please ", ConsoleViewContentType.ERROR_OUTPUT);
    BuckToolWindowFactory.outputConsoleHyperlink(project, "choose a build target!\n", new HyperlinkInfo() {

        @Override
        public void navigate(Project project) {
            JComponent frame = WindowManager.getInstance().getIdeFrame(project).getComponent();
            AnAction action = ActionManager.getInstance().getAction("buck.ChooseTarget");
            action.actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(frame), ActionPlaces.UNKNOWN, action.getTemplatePresentation(), ActionManager.getInstance(), 0));
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) BuckModule(com.facebook.buck.intellij.ideabuck.config.BuckModule) JComponent(javax.swing.JComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 2 with AnActionEvent

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

the class InplaceEditingLayer method startEditing.

public void startEditing(@Nullable InplaceContext inplaceContext) {
    try {
        List<RadComponent> selection = myDesigner.getSurfaceArea().getSelection();
        if (selection.size() != 1) {
            return;
        }
        myRadComponent = selection.get(0);
        myProperties = myRadComponent.getInplaceProperties();
        if (myProperties.isEmpty()) {
            myRadComponent = null;
            myProperties = null;
            return;
        }
        myInplaceComponent = new JPanel(new GridLayoutManager(myProperties.size(), 2));
        myInplaceComponent.setBorder(new LineMarginBorder(5, 5, 5, 5));
        new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                finishEditing(false);
            }
        }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myInplaceComponent);
        myEditors = new ArrayList<>();
        JComponent componentToFocus = null;
        Font font = null;
        if (inplaceContext == null) {
            inplaceContext = new InplaceContext();
        }
        int row = 0;
        for (Property property : myProperties) {
            JLabel label = new JLabel(property.getName() + ":");
            if (font == null) {
                font = label.getFont().deriveFont(Font.BOLD);
            }
            label.setFont(font);
            myInplaceComponent.add(label, new GridConstraints(row, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, 0, 0, null, null, null));
            PropertyEditor editor = property.getEditor();
            myEditors.add(editor);
            JComponent component = editor.getComponent(myRadComponent, myDesigner, property.getValue(myRadComponent), inplaceContext);
            myInplaceComponent.add(component, new GridConstraints(row++, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, 0, null, null, null));
            if (componentToFocus == null) {
                componentToFocus = editor.getPreferredFocusedComponent();
            }
        }
        for (PropertyEditor editor : myEditors) {
            editor.addPropertyEditorListener(myEditorListener);
        }
        Rectangle bounds = myRadComponent.getBounds(this);
        Dimension size = myInplaceComponent.getPreferredSize();
        myPreferredWidth = Math.max(size.width, bounds.width);
        myInplaceComponent.setBounds(bounds.x, bounds.y, myPreferredWidth, size.height);
        add(myInplaceComponent);
        myDesigner.getSurfaceArea().addSelectionListener(mySelectionListener);
        if (componentToFocus == null) {
            componentToFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myInplaceComponent);
        }
        if (componentToFocus == null) {
            componentToFocus = myInplaceComponent;
        }
        if (componentToFocus.requestFocusInWindow()) {
            myFocusWatcher.install(myInplaceComponent);
        } else {
            grabFocus();
            final JComponent finalComponentToFocus = componentToFocus;
            ApplicationManager.getApplication().invokeLater(() -> {
                finalComponentToFocus.requestFocusInWindow();
                myFocusWatcher.install(myInplaceComponent);
            });
        }
        enableEvents(AWTEvent.MOUSE_EVENT_MASK);
        repaint();
    } catch (Throwable e) {
        LOG.error(e);
    }
}
Also used : RadComponent(com.intellij.designer.model.RadComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) LineMarginBorder(com.intellij.designer.designSurface.feedbacks.LineMarginBorder) PropertyEditor(com.intellij.designer.propertyTable.PropertyEditor) InplaceContext(com.intellij.designer.propertyTable.InplaceContext) Property(com.intellij.designer.model.Property)

Example 3 with AnActionEvent

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

the class DesignerToolWindow method createActions.

AnAction[] createActions() {
    AnAction expandAll = new AnAction("Expand All", null, AllIcons.Actions.Expandall) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (myTreeBuilder != null) {
                TreeUtil.expandAll(myComponentTree);
            }
        }
    };
    AnAction collapseAll = new AnAction("Collapse All", null, AllIcons.Actions.Collapseall) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (myTreeBuilder != null) {
                TreeUtil.collapseAll(myComponentTree, 1);
            }
        }
    };
    return new AnAction[] { expandAll, collapseAll };
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 4 with AnActionEvent

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

the class AbstractComboBoxAction method createPopupActionGroup.

@NotNull
@Override
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
    DefaultActionGroup actionGroup = new DefaultActionGroup();
    for (final T item : myItems) {
        if (addSeparator(actionGroup, item)) {
            continue;
        }
        AnAction action = new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                if (mySelection != item && selectionChanged(item)) {
                    mySelection = item;
                    AbstractComboBoxAction.this.update(item, myPresentation, false);
                }
            }
        };
        actionGroup.add(action);
        Presentation presentation = action.getTemplatePresentation();
        presentation.setIcon(mySelection == item ? CHECKED : null);
        update(item, presentation, true);
    }
    return actionGroup;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with AnActionEvent

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

the class PyConsoleUtil method createTabCompletionAction.

public static AnAction createTabCompletionAction(PythonConsoleView consoleView) {
    final AnAction runCompletions = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            Editor editor = consoleView.getConsoleEditor();
            if (LookupManager.getActiveLookup(editor) != null) {
                AnAction replace = ActionManager.getInstance().getAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE);
                ActionUtil.performActionDumbAware(replace, e);
                return;
            }
            AnAction completionAction = ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION);
            if (completionAction != null) {
                ActionUtil.performActionDumbAware(completionAction, e);
            }
        }

        @Override
        public void update(AnActionEvent e) {
            Editor editor = consoleView.getConsoleEditor();
            if (LookupManager.getActiveLookup(editor) != null) {
                e.getPresentation().setEnabled(false);
            }
            int offset = editor.getCaretModel().getOffset();
            Document document = editor.getDocument();
            int lineStart = document.getLineStartOffset(document.getLineNumber(offset));
            String textToCursor = document.getText(new TextRange(lineStart, offset));
            e.getPresentation().setEnabled(!CharMatcher.WHITESPACE.matchesAllOf(textToCursor));
        }
    };
    runCompletions.registerCustomShortcutSet(KeyEvent.VK_TAB, 0, consoleView.getConsoleEditor().getComponent());
    runCompletions.getTemplatePresentation().setVisible(false);
    return runCompletions;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)167 AnAction (com.intellij.openapi.actionSystem.AnAction)76 Project (com.intellij.openapi.project.Project)33 NotNull (org.jetbrains.annotations.NotNull)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)27 Nullable (org.jetbrains.annotations.Nullable)21 List (java.util.List)19 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)18 Test (org.junit.Test)16 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)13 SonarTest (org.sonarlint.intellij.SonarTest)13 Presentation (com.intellij.openapi.actionSystem.Presentation)12 JBTable (com.intellij.ui.table.JBTable)12 AnActionButton (com.intellij.ui.AnActionButton)11 Notification (com.intellij.notification.Notification)10 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 ToolbarDecorator (com.intellij.ui.ToolbarDecorator)9