Search in sources :

Example 6 with CustomShortcutSet

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

the class ContentEntryTreeEditor method setupExcludedAction.

protected void setupExcludedAction() {
    ToggleExcludedStateAction toggleExcludedAction = new ToggleExcludedStateAction(myTree, this);
    myEditingActionsGroup.add(toggleExcludedAction);
    toggleExcludedAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK)), myTree);
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) ToggleExcludedStateAction(com.intellij.openapi.roots.ui.configuration.actions.ToggleExcludedStateAction)

Example 7 with CustomShortcutSet

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

the class ContentEntryTreeEditor method createEditingActions.

protected void createEditingActions() {
    for (final ModuleSourceRootEditHandler<?> editor : myEditHandlers) {
        ToggleSourcesStateAction action = new ToggleSourcesStateAction(myTree, this, editor);
        CustomShortcutSet shortcutSet = editor.getMarkRootShortcutSet();
        if (shortcutSet != null) {
            action.registerCustomShortcutSet(shortcutSet, myTree);
        }
        myEditingActionsGroup.add(action);
    }
    setupExcludedAction();
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) ToggleSourcesStateAction(com.intellij.openapi.roots.ui.configuration.actions.ToggleSourcesStateAction)

Example 8 with CustomShortcutSet

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

the class ScrollingUtil method installActions.

public static void installActions(final JTable table, final boolean cycleScrolling, JComponent focusParent) {
    ActionMap actionMap = table.getActionMap();
    actionMap.put(SCROLLUP_ACTION_ID, new MoveAction(SCROLLUP_ACTION_ID, table, cycleScrolling));
    actionMap.put(SCROLLDOWN_ACTION_ID, new MoveAction(SCROLLDOWN_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_PREVIOUS_ROW_ACTION_ID, new MoveAction(SELECT_PREVIOUS_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_NEXT_ROW_ACTION_ID, new MoveAction(SELECT_NEXT_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_LAST_ROW_ACTION_ID, new MoveAction(SELECT_LAST_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_FIRST_ROW_ACTION_ID, new MoveAction(SELECT_FIRST_ROW_ACTION_ID, table, cycleScrolling));
    maybeInstallDefaultShortcuts(table);
    JComponent target = focusParent == null ? table : focusParent;
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveHome(table);
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), table);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveEnd(table);
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)), table);
    if (!(focusParent instanceof JTextComponent)) {
        new MyScrollingAction(table) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                moveHome(table);
            }
        }.registerCustomShortcutSet(CommonShortcuts.getMoveHome(), target);
        new MyScrollingAction(table) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                moveEnd(table);
            }
        }.registerCustomShortcutSet(CommonShortcuts.getMoveEnd(), target);
    }
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveDown(table, e.getModifiers(), cycleScrolling);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMoveDown(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveUp(table, e.getModifiers(), cycleScrolling);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMoveUp(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            movePageUp(table);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMovePageUp(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            movePageDown(table);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMovePageDown(), target);
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) JTextComponent(javax.swing.text.JTextComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent)

Example 9 with CustomShortcutSet

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

the class CreateClassDialog method createNorthPanel.

@Override
protected JComponent createNorthPanel() {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.insets = JBUI.insets(4, 8);
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.anchor = GridBagConstraints.WEST;
    if (myClassNameEditable) {
        gbConstraints.weightx = 0;
        gbConstraints.gridwidth = 1;
        panel.add(myInformationLabel, gbConstraints);
        gbConstraints.insets = JBUI.insets(4, 8);
        gbConstraints.gridx = 1;
        gbConstraints.weightx = 1;
        gbConstraints.gridwidth = 1;
        gbConstraints.fill = GridBagConstraints.HORIZONTAL;
        gbConstraints.anchor = GridBagConstraints.WEST;
        panel.add(myTfClassName, gbConstraints);
        myTfClassName.getDocument().addDocumentListener(new DocumentAdapter() {

            @Override
            protected void textChanged(DocumentEvent e) {
                getOKAction().setEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(myTfClassName.getText()));
            }
        });
        getOKAction().setEnabled(StringUtil.isNotEmpty(myClassName));
    }
    gbConstraints.gridx = 0;
    gbConstraints.gridy = 2;
    gbConstraints.weightx = 0;
    gbConstraints.gridwidth = 1;
    panel.add(myPackageLabel, gbConstraints);
    gbConstraints.gridx = 1;
    gbConstraints.weightx = 1;
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            myPackageComponent.getButton().doClick();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myPackageComponent.getChildComponent());
    JPanel _panel = new JPanel(new BorderLayout());
    _panel.add(myPackageComponent, BorderLayout.CENTER);
    panel.add(_panel, gbConstraints);
    gbConstraints.gridy = 3;
    gbConstraints.gridx = 0;
    gbConstraints.gridwidth = 2;
    gbConstraints.insets.top = 12;
    gbConstraints.anchor = GridBagConstraints.WEST;
    gbConstraints.fill = GridBagConstraints.NONE;
    final JBLabel label = new JBLabel(RefactoringBundle.message("target.destination.folder"));
    panel.add(label, gbConstraints);
    gbConstraints.gridy = 4;
    gbConstraints.gridx = 0;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.insets.top = 4;
    panel.add(myDestinationCB, gbConstraints);
    final boolean isMultipleSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject).size() > 1;
    myDestinationCB.setVisible(isMultipleSourceRoots);
    label.setVisible(isMultipleSourceRoots);
    label.setLabelFor(myDestinationCB);
    return panel;
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) JBLabel(com.intellij.ui.components.JBLabel) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 10 with CustomShortcutSet

use of com.intellij.openapi.actionSystem.CustomShortcutSet 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)

Aggregations

CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)23 AnAction (com.intellij.openapi.actionSystem.AnAction)13 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)13 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)3 KeyEvent (java.awt.event.KeyEvent)3 Disposable (com.intellij.openapi.Disposable)2 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)2 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)2 Project (com.intellij.openapi.project.Project)2 DialogBuilder (com.intellij.openapi.ui.DialogBuilder)2 FrameWrapper (com.intellij.openapi.ui.FrameWrapper)2 Messages (com.intellij.openapi.ui.Messages)2 TreePath (javax.swing.tree.TreePath)2