Search in sources :

Example 1 with CustomShortcutSet

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

the class GroovyCreateClassDialog method createCenterPanel.

@Override
@Nullable
protected JComponent createCenterPanel() {
    myPackageTextField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            PsiNameHelper nameHelper = PsiNameHelper.getInstance(myProject);
            String packageName = getPackageName();
            getOKAction().setEnabled(nameHelper.isQualifiedName(packageName) || packageName != null && packageName.isEmpty());
        }
    });
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            myPackageChooseButton.doClick();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myPackageTextField);
    return myContentPane;
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CustomShortcutSet

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

the class GrTypeComboBox method registerUpDownHint.

public static void registerUpDownHint(JComponent component, final GrTypeComboBox combo) {
    final AnAction arrow = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (e.getInputEvent() instanceof KeyEvent) {
                final int code = ((KeyEvent) e.getInputEvent()).getKeyCode();
                scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0, combo);
            }
        }
    };
    final KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK), null);
    final KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK), null);
    arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), component);
}
Also used : KeyEvent(java.awt.event.KeyEvent) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 3 with CustomShortcutSet

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

the class IpnbCodeSourcePanel method createViewPanel.

@Override
protected JComponent createViewPanel() {
    final JPanel panel = new JPanel(new BorderLayout());
    panel.setBackground(UIUtil.isUnderDarcula() ? IpnbEditorUtil.getBackground() : Gray._247);
    myEditor = IpnbEditorUtil.createPythonCodeEditor(myProject, this);
    Disposer.register(myParent.getFileEditor(), new Disposable() {

        @Override
        public void dispose() {
            EditorFactory.getInstance().releaseEditor(myEditor);
        }
    });
    final JComponent component = myEditor.getComponent();
    final JComponent contentComponent = myEditor.getContentComponent();
    new IpnbRunCellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("shift ENTER")), contentComponent);
    new IpnbRunCellInplaceAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl ENTER")), contentComponent);
    contentComponent.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final int keyCode = e.getKeyCode();
            final Container parent = myParent.getParent();
            if (keyCode == KeyEvent.VK_ESCAPE && parent instanceof IpnbFilePanel) {
                getIpnbCodePanel().setEditing(false);
                parent.repaint();
                UIUtil.requestFocus(getIpnbCodePanel().getFileEditor().getIpnbFilePanel());
            }
        }

        private void updateVisibleArea(boolean up) {
            final IpnbFileEditor fileEditor = myParent.getFileEditor();
            final IpnbFilePanel ipnbPanel = fileEditor.getIpnbFilePanel();
            final Rectangle rect = ipnbPanel.getVisibleRect();
            final Rectangle cellBounds = IpnbCodeSourcePanel.this.getIpnbCodePanel().getBounds();
            final JScrollPane scrollPane = fileEditor.getScrollPane();
            final int y = cellBounds.y + myEditor.visualPositionToXY(myEditor.getCaretModel().getVisualPosition()).y;
            int delta = myEditor.getLineHeight() * 2;
            if (y <= rect.getY() && up) {
                scrollPane.getVerticalScrollBar().setValue(y);
            }
            if (y + delta > rect.getY() + rect.getHeight() && !up) {
                scrollPane.getVerticalScrollBar().setValue(y - rect.height + delta);
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            final int keyCode = e.getKeyCode();
            final Container parent = myParent.getParent();
            final int height = myEditor.getLineHeight() * Math.max(myEditor.getDocument().getLineCount(), 1) + 10;
            contentComponent.setPreferredSize(new Dimension(parent.getWidth() - 300, height));
            panel.setPreferredSize(new Dimension(parent.getWidth() - 300, height));
            myParent.revalidate();
            myParent.repaint();
            panel.revalidate();
            panel.repaint();
            if (parent instanceof IpnbFilePanel) {
                IpnbFilePanel ipnbFilePanel = (IpnbFilePanel) parent;
                ipnbFilePanel.revalidate();
                ipnbFilePanel.repaint();
                if (keyCode == KeyEvent.VK_ENTER && InputEvent.CTRL_MASK == e.getModifiers()) {
                    IpnbRunCellBaseAction.runCell(ipnbFilePanel, false);
                } else if (keyCode == KeyEvent.VK_ENTER && InputEvent.SHIFT_DOWN_MASK == e.getModifiersEx()) {
                    IpnbRunCellBaseAction.runCell(ipnbFilePanel, true);
                } else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_PAGE_DOWN || keyCode == KeyEvent.VK_PAGE_UP) {
                    updateVisibleArea(keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_PAGE_UP);
                }
            }
        }
    });
    contentComponent.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (InputEvent.CTRL_DOWN_MASK == e.getModifiersEx())
                return;
            final Container ipnbFilePanel = myParent.getParent();
            if (ipnbFilePanel instanceof IpnbFilePanel) {
                ((IpnbFilePanel) ipnbFilePanel).setSelectedCell(myParent, true);
                myParent.switchToEditing();
            }
            UIUtil.requestFocus(contentComponent);
        }
    });
    panel.add(component);
    contentComponent.addHierarchyListener(new HierarchyListener() {

        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            final Container parent = myParent.getParent();
            if (parent != null) {
                final int height = myEditor.getLineHeight() * Math.max(myEditor.getDocument().getLineCount(), 1) + 10;
                contentComponent.setPreferredSize(new Dimension(parent.getWidth() - 300, height));
                panel.setPreferredSize(new Dimension(parent.getWidth() - 300, height));
            }
        }
    });
    contentComponent.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {

        @Override
        public void ancestorResized(HierarchyEvent e) {
            final Container parent = myParent.getParent();
            final Component component = e.getChanged();
            if (parent != null && component instanceof IpnbFilePanel) {
                final int height = myEditor.getLineHeight() * Math.max(myEditor.getDocument().getLineCount(), 1) + 10;
                contentComponent.setPreferredSize(new Dimension(parent.getWidth() - 300, height));
                panel.setPreferredSize(new Dimension(parent.getWidth() - 300, height));
                panel.revalidate();
                panel.repaint();
                parent.repaint();
            }
        }
    });
    return panel;
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) EditorMouseAdapter(com.intellij.openapi.editor.event.EditorMouseAdapter) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)

Example 4 with CustomShortcutSet

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

the class ValueHint method createInspectTree.

public static InspectDebuggerTree createInspectTree(final NodeDescriptorImpl descriptor, Project project) {
    final InspectDebuggerTree tree = new InspectDebuggerTree(project);
    final AnAction setValueAction = ActionManager.getInstance().getAction(DebuggerActions.SET_VALUE);
    setValueAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)), tree);
    Disposer.register(tree, new Disposable() {

        @Override
        public void dispose() {
            setValueAction.unregisterCustomShortcutSet(tree);
        }
    });
    tree.setInspectDescriptor(descriptor);
    DebuggerContextImpl context = DebuggerManagerEx.getInstanceEx(project).getContext();
    tree.rebuild(context);
    return tree;
}
Also used : Disposable(com.intellij.openapi.Disposable) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) InspectDebuggerTree(com.intellij.debugger.ui.impl.InspectDebuggerTree) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 5 with CustomShortcutSet

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

the class CaptureConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    myTableModel = new MyTableModel();
    JBTable table = new JBTable(myTableModel);
    table.setColumnSelectionAllowed(false);
    TableColumnModel columnModel = table.getColumnModel();
    TableUtil.setupCheckboxColumn(columnModel.getColumn(MyTableModel.ENABLED_COLUMN));
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
    decorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            myTableModel.addRow();
        }
    });
    decorator.setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.removeSelectedItems(table);
        }
    });
    decorator.setMoveUpAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsUp(table);
        }
    });
    decorator.setMoveDownAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsDown(table);
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() == 1;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> {
                try {
                    int idx = myTableModel.add(c.clone());
                    table.getSelectionModel().setSelectionInterval(idx, idx);
                } catch (CloneNotSupportedException ex) {
                    LOG.error(ex);
                }
            });
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Enable Selected", "Enable Selected", PlatformIcons.SELECT_ALL_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = true);
            table.repaint();
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Disable Selected", "Disable Selected", PlatformIcons.UNSELECT_ALL_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = false);
            table.repaint();
        }
    });
    new DumbAwareAction("Toggle") {

        @Override
        public void update(@NotNull AnActionEvent e) {
            e.getPresentation().setEnabled(table.getSelectedRowCount() == 1);
        }

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = !c.myEnabled);
            table.repaint();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), table);
    decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, true) {

                @Override
                public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
                    return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
                }

                @Override
                public boolean isFileSelectable(VirtualFile file) {
                    return file.getFileType() == StdFileTypes.XML;
                }
            };
            descriptor.setDescription("Please select a file to import.");
            descriptor.setTitle("Import Capture Points");
            VirtualFile[] files = FileChooser.chooseFiles(descriptor, e.getProject(), null);
            if (ArrayUtil.isEmpty(files))
                return;
            table.getSelectionModel().clearSelection();
            for (VirtualFile file : files) {
                try {
                    Document document = JDOMUtil.loadDocument(file.getInputStream());
                    List<Element> children = document.getRootElement().getChildren();
                    children.forEach(element -> {
                        int idx = myTableModel.addIfNeeded(XmlSerializer.deserialize(element, CapturePoint.class));
                        table.getSelectionModel().addSelectionInterval(idx, idx);
                    });
                } catch (Exception ex) {
                    final String msg = ex.getLocalizedMessage();
                    Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
                }
            }
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Capture Points to File...", "", "xml"), e.getProject()).save(null, null);
            if (wrapper == null)
                return;
            Element rootElement = new Element("capture-points");
            selectedCapturePoints(table).forEach(c -> {
                try {
                    CapturePoint clone = c.clone();
                    clone.myEnabled = false;
                    rootElement.addContent(XmlSerializer.serialize(clone));
                } catch (CloneNotSupportedException ex) {
                    LOG.error(ex);
                }
            });
            try {
                JDOMUtil.write(rootElement, wrapper.getFile());
            } catch (Exception ex) {
                final String msg = ex.getLocalizedMessage();
                Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
            }
        }

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }
    });
    BorderLayoutPanel panel = JBUI.Panels.simplePanel();
    panel.addToCenter(decorator.createPanel());
    myCaptureVariables = new JCheckBox(DebuggerBundle.message("label.capture.configurable.capture.variables"));
    panel.addToBottom(myCaptureVariables);
    return panel;
}
Also used : JVMNameUtil(com.intellij.debugger.engine.JVMNameUtil) JavaDebuggerSupport(com.intellij.debugger.ui.JavaDebuggerSupport) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) Document(org.jdom.Document) Nls(org.jetbrains.annotations.Nls) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) JBUI(com.intellij.util.ui.JBUI) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) FileTypes(com.intellij.openapi.fileTypes.FileTypes) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) FileChooserFactory(com.intellij.openapi.fileChooser.FileChooserFactory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Debugger(org.jetbrains.annotations.Debugger) AnnotatedElementsSearch(com.intellij.psi.search.searches.AnnotatedElementsSearch) StreamEx(one.util.streamex.StreamEx) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Registry(com.intellij.openapi.util.registry.Registry) IntStreamEx(one.util.streamex.IntStreamEx) com.intellij.psi(com.intellij.psi) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) XmlSerializer(com.intellij.util.xmlb.XmlSerializer) ArrayUtil(com.intellij.util.ArrayUtil) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) TableColumnModel(javax.swing.table.TableColumnModel) ArrayList(java.util.ArrayList) JDOMUtil(com.intellij.openapi.util.JDOMUtil) AbstractTableModel(javax.swing.table.AbstractTableModel) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) PlatformIcons(com.intellij.util.PlatformIcons) DecompiledLocalVariable(com.intellij.debugger.jdi.DecompiledLocalVariable) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) ItemRemovable(com.intellij.util.ui.ItemRemovable) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Element(org.jdom.Element) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) TableColumnModel(javax.swing.table.TableColumnModel) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Document(org.jdom.Document) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) List(java.util.List) ArrayList(java.util.ArrayList) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) Nullable(org.jetbrains.annotations.Nullable)

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