Search in sources :

Example 66 with AnAction

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

the class LineTooltipRenderer method show.

@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull final Point p, final boolean alignToRight, @NotNull final TooltipGroup group, @NotNull final HintHint hintHint) {
    if (myText == null)
        return null;
    //setup text
    myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
    final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);
    final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
    final JComponent contentComponent = editor.getContentComponent();
    final JComponent editorComponent = editor.getComponent();
    if (!editorComponent.isShowing())
        return null;
    final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    final JEditorPane pane = IdeTooltipManager.initPane(new Html(myText).setKeepFont(true), hintHint, layeredPane);
    hintHint.setContentActive(isActiveHtml(myText));
    if (!hintHint.isAwtTooltip()) {
        correctLocation(editor, pane, p, alignToRight, expanded, myCurrentWidth);
    }
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
    scrollPane.setBorder(null);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setOpaque(hintHint.isOpaqueAllowed());
    scrollPane.getViewport().setOpaque(hintHint.isOpaqueAllowed());
    scrollPane.setBackground(hintHint.getTextBackground());
    scrollPane.getViewport().setBackground(hintHint.getTextBackground());
    scrollPane.setViewportBorder(null);
    if (hintHint.isRequestFocus()) {
        pane.setFocusable(true);
    }
    final Ref<AnAction> actionRef = new Ref<>();
    final LightweightHint hint = new LightweightHint(scrollPane) {

        @Override
        public void hide() {
            onHide(pane);
            super.hide();
            final AnAction action = actionRef.get();
            if (action != null) {
                action.unregisterCustomShortcutSet(contentComponent);
            }
        }
    };
    actionRef.set(new AnAction() {

        // an action to expand description when tooltip was shown after mouse move; need to unregister from editor component
        {
            registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)), contentComponent);
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            // The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut.
            hintHint.setRequestFocus(ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent));
            expand(hint, editor, p, pane, alignToRight, group, hintHint);
        }
    });
    pane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            myActiveLink = true;
            if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                myActiveLink = false;
                return;
            }
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                final URL url = e.getURL();
                if (url != null) {
                    BrowserUtil.browse(url);
                    hint.hide();
                    return;
                }
                final String description = e.getDescription();
                if (description != null && handle(description, editor)) {
                    hint.hide();
                    return;
                }
                if (!expanded) {
                    expand(hint, editor, p, pane, alignToRight, group, hintHint);
                } else {
                    stripDescription();
                    hint.hide();
                    TooltipController.getInstance().showTooltip(editor, new Point(p.x - 3, p.y - 3), createRenderer(myText, 0), false, group, hintHint);
                }
            }
        }
    });
    // This listener makes hint transparent for mouse events. It means that hint is closed
    // by MousePressed and this MousePressed goes into the underlying editor component.
    pane.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (!myActiveLink) {
                MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
                hint.hide();
                contentComponent.dispatchEvent(newMouseEvent);
            }
        }

        @Override
        public void mouseExited(final MouseEvent e) {
            if (!expanded) {
                hint.hide();
            }
        }
    });
    hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
    return hint;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Html(com.intellij.util.ui.Html) LightweightHint(com.intellij.ui.LightweightHint) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) URL(java.net.URL) KeyEvent(java.awt.event.KeyEvent) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) Ref(com.intellij.openapi.util.Ref) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 67 with AnAction

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

the class KeymapGenerator method main.

@Override
public void main(String[] args) {
    ActionManager actionManager = ActionManager.getInstance();
    StringBuilder xml = new StringBuilder();
    xml.append("<Keymaps>\n");
    for (Keymap keymap : KeymapManagerEx.getInstanceEx().getAllKeymaps()) {
        xml.append("  <Keymap name=\"").append(keymap.getPresentableName()).append("\">\n");
        for (String id : keymap.getActionIdList()) {
            String shortcuts = KeymapUtil.getShortcutsText(keymap.getShortcuts(id));
            if (!StringUtil.isEmpty(shortcuts)) {
                AnAction action = actionManager.getAction(id);
                xml.append("    <Action id=\"").append(id).append("\">\n");
                Set<String> addedShortcuts = new THashSet<>();
                for (Shortcut shortcut : keymap.getShortcuts(id)) {
                    // Different shortcuts may have equal display strings (e.g. shift+minus and shift+subtract)
                    // We don't want them do be duplicated for users
                    String shortcutText = KeymapUtil.getShortcutText(shortcut);
                    if (addedShortcuts.add(shortcutText)) {
                        xml.append("      <Shortcut>").append(shortcutText).append("</Shortcut>\n");
                    }
                }
                if (action != null) {
                    String text = action.getTemplatePresentation().getText();
                    if (text != null) {
                        xml.append("      <Text>").append(StringUtil.escapeXml(text)).append("</Text>\n");
                    }
                }
                xml.append("    </Action>\n");
            }
        }
        xml.append("  </Keymap>\n");
    }
    xml.append("</Keymaps>");
    final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllKeymaps.xml";
    File out = new File(path);
    try {
        FileUtil.writeToFile(out, xml.toString());
        System.out.println("Saved to: " + out.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    System.exit(0);
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) Shortcut(com.intellij.openapi.actionSystem.Shortcut) IOException(java.io.IOException) AnAction(com.intellij.openapi.actionSystem.AnAction) File(java.io.File) Keymap(com.intellij.openapi.keymap.Keymap) THashSet(gnu.trove.THashSet)

Example 68 with AnAction

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

the class MergeList method addActions.

private void addActions(@NotNull final FragmentSide side) {
    ChangeList changeList = getChanges(side);
    final FragmentSide originalSide = BRANCH_SIDE;
    for (int i = 0; i < changeList.getCount(); i++) {
        final Change change = changeList.getChange(i);
        if (!change.canHasActions(originalSide))
            continue;
        Icon arrowIcon = side == FragmentSide.SIDE1 ? AllIcons.Diff.ArrowRight : AllIcons.Diff.Arrow;
        AnAction applyAction = new DumbAwareAction(DiffBundle.message("merge.dialog.apply.change.action.name"), null, arrowIcon) {

            @Override
            public void actionPerformed(@Nullable AnActionEvent e) {
                apply(change);
            }
        };
        AnAction ignoreAction = new DumbAwareAction(DiffBundle.message("merge.dialog.ignore.change.action.name"), null, AllIcons.Diff.Remove) {

            @Override
            public void actionPerformed(@Nullable AnActionEvent e) {
                change.removeFromList();
            }
        };
        change.getChangeSide(originalSide).getHighlighterHolder().setActions(new AnAction[] { applyAction, ignoreAction });
    }
}
Also used : FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with AnAction

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

the class JBMovePanel method createButton.

@NotNull
private ActionButton createButton(@NotNull final ButtonType type) {
    final AnAction action;
    switch(type) {
        case LEFT:
            action = new LeftAction();
            break;
        case RIGHT:
            action = new RightAction();
            break;
        case ALL_LEFT:
            action = new AllLeftAction();
            break;
        case ALL_RIGHT:
            action = new AllRightAction();
            break;
        default:
            throw new IllegalArgumentException("Unsupported button type: " + type);
    }
    ActionButton button = createButton(action);
    myButtons.put(type, button);
    return button;
}
Also used : ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with AnAction

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

the class DuplexConsoleActionsTest method testMergedClear.

public void testMergedClear() {
    final ConsoleViewImpl console1 = ConsoleViewImplTest.createConsole();
    final ConsoleViewImpl console2 = ConsoleViewImplTest.createConsole();
    final DuplexConsoleView<ConsoleViewImpl, ConsoleViewImpl> duplexConsoleView = new DuplexConsoleView<>(console1, console2);
    Disposer.register(myDisposable, duplexConsoleView);
    final AnAction clearAction = findAction(duplexConsoleView.createConsoleActions(), "Clear");
    assertNotNull(clearAction);
    console1.print("FooBar", ConsoleViewContentType.NORMAL_OUTPUT);
    console2.print("BazFoo", ConsoleViewContentType.NORMAL_OUTPUT);
    console1.flushDeferredText();
    console2.flushDeferredText();
    clearAction.actionPerformed(AnActionEvent.createFromAnAction(clearAction, null, ActionPlaces.EDITOR_TOOLBAR, DataContext.EMPTY_CONTEXT));
    console1.waitAllRequests();
    console2.waitAllRequests();
    assertEquals(0, console1.getContentSize());
    assertEquals(0, console2.getContentSize());
}
Also used : DuplexConsoleView(com.intellij.execution.console.DuplexConsoleView) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

AnAction (com.intellij.openapi.actionSystem.AnAction)184 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)62 NotNull (org.jetbrains.annotations.NotNull)31 Project (com.intellij.openapi.project.Project)24 Nullable (org.jetbrains.annotations.Nullable)22 ActionManager (com.intellij.openapi.actionSystem.ActionManager)21 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)21 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)13 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)7 Presentation (com.intellij.openapi.actionSystem.Presentation)7 PsiFile (com.intellij.psi.PsiFile)7 ReopenProjectAction (com.intellij.ide.ReopenProjectAction)6 Editor (com.intellij.openapi.editor.Editor)6 Keymap (com.intellij.openapi.keymap.Keymap)6 Ref (com.intellij.openapi.util.Ref)6 List (java.util.List)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5