Search in sources :

Example 6 with DumbAwareAction

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

the class SearchEverywhereAction method initSearchActions.

private void initSearchActions(JBPopup balloon, MySearchTextField searchTextField) {
    final JTextField editor = searchTextField.getTextEditor();
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            jumpNextGroup(true);
        }
    }.registerCustomShortcutSet(CustomShortcutSet.fromString("TAB"), editor, balloon);
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            jumpNextGroup(false);
        }
    }.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), editor, balloon);
    final AnAction escape = ActionManager.getInstance().getAction("EditorEscape");
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (myBalloon != null && myBalloon.isVisible()) {
                myBalloon.cancel();
            }
            if (myPopup != null && myPopup.isVisible()) {
                myPopup.cancel();
            }
        }
    }.registerCustomShortcutSet(escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), editor, balloon);
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final int index = myList.getSelectedIndex();
            if (index != -1) {
                doNavigate(index);
            }
        }
    }.registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER", "shift ENTER"), editor, balloon);
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final PropertiesComponent storage = PropertiesComponent.getInstance(e.getProject());
            final String[] values = storage.getValues(SE_HISTORY_KEY);
            if (values != null) {
                if (values.length > myHistoryIndex) {
                    final List<String> data = StringUtil.split(values[myHistoryIndex], "\t");
                    myHistoryItem = new HistoryItem(data.get(0), data.get(1), data.get(2));
                    myHistoryIndex++;
                    editor.setText(myHistoryItem.pattern);
                    editor.setCaretPosition(myHistoryItem.pattern.length());
                    editor.moveCaretPosition(0);
                }
            }
        }

        @Override
        public void update(AnActionEvent e) {
            e.getPresentation().setEnabled(editor.getCaretPosition() == 0);
        }
    }.registerCustomShortcutSet(CustomShortcutSet.fromString("LEFT"), editor, balloon);
}
Also used : JBList(com.intellij.ui.components.JBList) List(java.util.List) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 7 with DumbAwareAction

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

the class ScopesChooser method fillActionGroup.

private void fillActionGroup(final DefaultActionGroup group, final List<NamedScope> scopes, final List<Descriptor> defaultDescriptors, final InspectionProfileImpl inspectionProfile, final Set<String> excludedScopeNames) {
    for (final NamedScope scope : scopes) {
        final String scopeName = scope.getName();
        if (excludedScopeNames.contains(scopeName)) {
            continue;
        }
        group.add(new DumbAwareAction(scopeName) {

            @Override
            public void actionPerformed(final AnActionEvent e) {
                for (final Descriptor defaultDescriptor : defaultDescriptors) {
                    inspectionProfile.addScope(defaultDescriptor.getToolWrapper().createCopy(), scope, defaultDescriptor.getLevel(), true, getEventProject(e));
                }
                onScopeAdded();
            }
        });
    }
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) Descriptor(com.intellij.codeInspection.ex.Descriptor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 8 with DumbAwareAction

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

the class DialogWrapper method init.

protected void init() {
    ensureEventDispatchThread();
    myErrorText = new ErrorText(getErrorTextAlignment());
    myErrorText.setVisible(false);
    final ComponentAdapter resizeListener = new ComponentAdapter() {

        private int myHeight;

        @Override
        public void componentResized(ComponentEvent event) {
            int height = !myErrorText.isVisible() ? 0 : event.getComponent().getHeight();
            if (height != myHeight) {
                myHeight = height;
                myResizeInProgress = true;
                myErrorText.setMinimumSize(new Dimension(0, height));
                JRootPane root = myPeer.getRootPane();
                if (root != null) {
                    root.validate();
                }
                if (myActualSize != null && !shouldAddErrorNearButtons()) {
                    myPeer.setSize(myActualSize.width, myActualSize.height + height);
                }
                myErrorText.revalidate();
                myResizeInProgress = false;
            }
        }
    };
    myErrorText.myLabel.addComponentListener(resizeListener);
    Disposer.register(myDisposable, new Disposable() {

        @Override
        public void dispose() {
            myErrorText.myLabel.removeComponentListener(resizeListener);
        }
    });
    final JPanel root = new JPanel(createRootLayout());
    //{
    //  @Override
    //  public void paint(Graphics g) {
    //    if (ApplicationManager.getApplication() != null) {
    //      UISettings.setupAntialiasing(g);
    //    }
    //    super.paint(g);
    //  }
    //};
    myPeer.setContentPane(root);
    final CustomShortcutSet sc = new CustomShortcutSet(SHOW_OPTION_KEYSTROKE);
    final AnAction toggleShowOptions = new DumbAwareAction() {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            expandNextOptionButton();
        }
    };
    toggleShowOptions.registerCustomShortcutSet(sc, root, myDisposable);
    JComponent titlePane = createTitlePane();
    if (titlePane != null) {
        JPanel northSection = new JPanel(new BorderLayout());
        root.add(northSection, BorderLayout.NORTH);
        northSection.add(titlePane, BorderLayout.CENTER);
    }
    JComponent centerSection = new JPanel(new BorderLayout());
    root.add(centerSection, BorderLayout.CENTER);
    root.setBorder(createContentPaneBorder());
    final JComponent n = createNorthPanel();
    if (n != null) {
        centerSection.add(n, BorderLayout.NORTH);
    }
    final JComponent c = createCenterPanel();
    if (c != null) {
        centerSection.add(c, BorderLayout.CENTER);
    }
    final JPanel southSection = new JPanel(new BorderLayout());
    root.add(southSection, BorderLayout.SOUTH);
    southSection.add(myErrorText, BorderLayout.CENTER);
    final JComponent south = createSouthPanel();
    if (south != null) {
        southSection.add(south, BorderLayout.SOUTH);
    }
    MnemonicHelper.init(root);
    if (!postponeValidation()) {
        startTrackingValidation();
    }
    if (SystemInfo.isWindows) {
        installEnterHook(root, myDisposable);
    }
    myErrorTextAlarm.setActivationComponent(root);
}
Also used : Disposable(com.intellij.openapi.Disposable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 9 with DumbAwareAction

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

the class DialogWrapper method createJOptionsButton.

@NotNull
private JButton createJOptionsButton(@NotNull OptionAction action) {
    JBOptionButton optionButton = new JBOptionButton(action, action.getOptions());
    optionButton.setOkToProcessDefaultMnemonics(false);
    optionButton.setOptionTooltipText("Press " + KeymapUtil.getKeystrokeText(SHOW_OPTION_KEYSTROKE) + " to expand or use a mnemonic of a contained action");
    final Set<JBOptionButton.OptionInfo> infos = optionButton.getOptionInfos();
    for (final JBOptionButton.OptionInfo eachInfo : infos) {
        if (eachInfo.getMnemonic() >= 0) {
            final char mnemonic = (char) eachInfo.getMnemonic();
            JRootPane rootPane = getPeer().getRootPane();
            if (rootPane != null) {
                new DumbAwareAction("Show JBOptionButton popup") {

                    @Override
                    public void actionPerformed(AnActionEvent e) {
                        final JBOptionButton buttonToActivate = eachInfo.getButton();
                        buttonToActivate.showPopup(eachInfo.getAction(), true);
                    }
                }.registerCustomShortcutSet(MnemonicHelper.createShortcut(mnemonic), rootPane, myDisposable);
            }
        }
    }
    return optionButton;
}
Also used : JBOptionButton(com.intellij.ui.components.JBOptionButton) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DumbAwareAction

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

the class TemplateListPanel method installPopup.

private void installPopup() {
    final DumbAwareAction rename = new DumbAwareAction("Rename") {

        @Override
        public void update(@NotNull AnActionEvent e) {
            final TemplateGroup templateGroup = getSingleSelectedGroup();
            boolean enabled = templateGroup != null;
            e.getPresentation().setEnabled(enabled);
            e.getPresentation().setVisible(enabled);
            super.update(e);
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            renameGroup();
        }
    };
    rename.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_RENAME).getShortcutSet(), myTree);
    final DefaultActionGroup move = new DefaultActionGroup("Move", true) {

        @Override
        public void update(AnActionEvent e) {
            final Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates();
            boolean enabled = !templates.isEmpty();
            e.getPresentation().setEnabled(enabled);
            e.getPresentation().setVisible(enabled);
            if (enabled) {
                Set<String> oldGroups = getAllGroups(templates);
                removeAll();
                for (TemplateGroup group : getTemplateGroups()) {
                    final String newGroupName = group.getName();
                    if (!oldGroups.contains(newGroupName)) {
                        add(new DumbAwareAction(newGroupName) {

                            @Override
                            public void actionPerformed(@NotNull AnActionEvent e) {
                                moveTemplates(templates, newGroupName);
                            }
                        });
                    }
                }
                addSeparator();
                add(new DumbAwareAction("New group...") {

                    @Override
                    public void actionPerformed(@NotNull AnActionEvent e) {
                        String newName = Messages.showInputDialog(myTree, "Enter the new group name:", "Move to a New Group", null, "", new TemplateGroupInputValidator(null));
                        if (newName != null) {
                            moveTemplates(templates, newName);
                        }
                    }
                });
            }
        }
    };
    final DumbAwareAction changeContext = new DumbAwareAction("Change context...") {

        @Override
        public void update(@NotNull AnActionEvent e) {
            boolean enabled = !getSelectedTemplates().isEmpty();
            e.getPresentation().setEnabled(enabled);
            super.update(e);
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates();
            TemplateContext context = new TemplateContext();
            JPanel contextPanel = LiveTemplateSettingsEditor.createPopupContextPanel(EmptyRunnable.INSTANCE, context);
            DialogBuilder builder = new DialogBuilder(TemplateListPanel.this);
            builder.setCenterPanel(contextPanel);
            builder.setTitle("Change Context Type For Selected Templates");
            int result = builder.show();
            if (result == DialogWrapper.OK_EXIT_CODE) {
                for (TemplateImpl template : templates.keySet()) {
                    myTemplateContext.put(template, context);
                }
            }
            updateTemplateDetails(false, true);
            myTree.repaint();
        }
    };
    final DumbAwareAction revert = new DumbAwareAction("Restore defaults", "Restore default setting for the selected templates", null) {

        @Override
        public void update(@NotNull AnActionEvent e) {
            boolean enabled = false;
            Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates();
            for (TemplateImpl template : templates.keySet()) {
                TemplateImpl defaultTemplate = TemplateSettings.getInstance().getDefaultTemplate(template);
                if (defaultTemplate != null && templatesDiffer(template, defaultTemplate)) {
                    enabled = true;
                }
            }
            e.getPresentation().setEnabled(enabled);
            e.getPresentation().setVisible(enabled);
            super.update(e);
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates();
            for (TemplateImpl template : templates.keySet()) {
                TemplateImpl defaultTemplate = TemplateSettings.getInstance().getDefaultTemplate(template);
                if (defaultTemplate != null) {
                    myTemplateOptions.put(template, defaultTemplate.createOptions());
                    myTemplateContext.put(template, defaultTemplate.createContext());
                    template.resetFrom(defaultTemplate);
                }
            }
            updateTemplateDetails(false, true);
            myTree.repaint();
        }
    };
    myTree.addMouseListener(new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            final DefaultActionGroup group = new DefaultActionGroup();
            group.add(rename);
            group.add(move);
            group.add(changeContext);
            group.add(revert);
            group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));
            group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE));
            ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group).getComponent().show(comp, x, y);
        }
    });
}
Also used : DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)41 NotNull (org.jetbrains.annotations.NotNull)19 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)18 AnAction (com.intellij.openapi.actionSystem.AnAction)8 Nullable (org.jetbrains.annotations.Nullable)8 List (java.util.List)6 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)4 FileChooser (com.intellij.openapi.fileChooser.FileChooser)4 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)4 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)4 Project (com.intellij.openapi.project.Project)4 Messages (com.intellij.openapi.ui.Messages)4 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 JBTable (com.intellij.ui.table.JBTable)4 MouseEvent (java.awt.event.MouseEvent)4 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)3 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3