Search in sources :

Example 16 with DumbAwareAction

use of com.intellij.openapi.project.DumbAwareAction 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 17 with DumbAwareAction

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

the class KeymapPanel method createEditActionGroup.

@NotNull
private DefaultActionGroup createEditActionGroup(@NotNull final String actionId) {
    DefaultActionGroup group = new DefaultActionGroup();
    final ShortcutRestrictions restrictions = ActionShortcutRestrictions.getInstance().getForActionId(actionId);
    if (restrictions.allowKeyboardShortcut) {
        group.add(new DumbAwareAction("Add Keyboard Shortcut") {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                Keymap keymapSelected = myEditor.getModel().getSelected();
                assert keymapSelected != null;
                addKeyboardShortcut(actionId, restrictions, keymapSelected, KeymapPanel.this, myQuickLists);
                repaintLists();
                currentKeymapChanged();
            }
        });
    }
    if (restrictions.allowMouseShortcut) {
        group.add(new DumbAwareAction("Add Mouse Shortcut") {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                Keymap keymapSelected = myEditor.getModel().getSelected();
                assert keymapSelected != null;
                addMouseShortcut(actionId, restrictions, keymapSelected, KeymapPanel.this, myQuickLists);
                repaintLists();
                currentKeymapChanged();
            }
        });
    }
    if (Registry.is("actionSystem.enableAbbreviations") && restrictions.allowAbbreviation) {
        group.add(new DumbAwareAction("Add Abbreviation") {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                String abbr = Messages.showInputDialog("Enter new abbreviation:", "Abbreviation", null);
                if (abbr != null) {
                    AbbreviationManager.getInstance().register(abbr, myActionsTree.getSelectedActionId());
                    repaintLists();
                }
            }

            @Override
            public void update(@NotNull AnActionEvent e) {
                e.getPresentation().setEnabledAndVisible(myActionsTree.getSelectedActionId() != null);
            }
        });
    }
    group.addSeparator();
    Keymap keymap = myEditor.getModel().getSelected();
    assert keymap != null;
    for (final Shortcut shortcut : keymap.getShortcuts(actionId)) {
        group.add(new DumbAwareAction("Remove " + KeymapUtil.getShortcutText(shortcut)) {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                Keymap keymap = createKeymapCopyIfNeeded();
                keymap.removeShortcut(actionId, shortcut);
                if (StringUtil.startsWithChar(actionId, '$')) {
                    keymap.removeShortcut(KeyMapBundle.message("editor.shortcut", actionId.substring(1)), shortcut);
                }
                repaintLists();
                currentKeymapChanged();
            }
        });
    }
    if (Registry.is("actionSystem.enableAbbreviations")) {
        for (final String abbreviation : AbbreviationManager.getInstance().getAbbreviations(actionId)) {
            group.addAction(new DumbAwareAction("Remove Abbreviation '" + abbreviation + "'") {

                @Override
                public void actionPerformed(@NotNull AnActionEvent e) {
                    AbbreviationManager.getInstance().remove(abbreviation, actionId);
                    repaintLists();
                }
            });
        }
    }
    group.add(new Separator());
    group.add(new DumbAwareAction("Reset Shortcuts") {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            ((KeymapImpl) createKeymapCopyIfNeeded()).clearOwnActionsId(actionId);
            currentKeymapChanged();
            repaintLists();
        }

        @Override
        public void update(@NotNull AnActionEvent e) {
            e.getPresentation().setVisible(((KeymapImpl) myEditor.getModel().getSelected()).hasOwnActionId(actionId));
        }
    });
    return group;
}
Also used : KeymapImpl(com.intellij.openapi.keymap.impl.KeymapImpl) ActionShortcutRestrictions(com.intellij.openapi.keymap.impl.ActionShortcutRestrictions) ShortcutRestrictions(com.intellij.openapi.keymap.impl.ShortcutRestrictions) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with DumbAwareAction

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

the class KeymapPanel method createToolbarPanel.

private JPanel createToolbarPanel() {
    final JPanel panel = new JPanel(new GridBagLayout());
    DefaultActionGroup group = new DefaultActionGroup();
    final JComponent toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent();
    final CommonActionsManager commonActionsManager = CommonActionsManager.getInstance();
    final TreeExpander treeExpander = new TreeExpander() {

        @Override
        public void expandAll() {
            TreeUtil.expandAll(myActionsTree.getTree());
        }

        @Override
        public boolean canExpand() {
            return true;
        }

        @Override
        public void collapseAll() {
            TreeUtil.collapseAll(myActionsTree.getTree(), 0);
        }

        @Override
        public boolean canCollapse() {
            return true;
        }
    };
    group.add(commonActionsManager.createExpandAllAction(treeExpander, myActionsTree.getTree()));
    group.add(commonActionsManager.createCollapseAllAction(treeExpander, myActionsTree.getTree()));
    group.add(new AnAction("Edit Shortcut", "Edit Shortcut", AllIcons.ToolbarDecorator.Edit) {

        {
            registerCustomShortcutSet(CommonShortcuts.ENTER, myActionsTree.getTree());
        }

        @Override
        public void update(@NotNull AnActionEvent e) {
            final String actionId = myActionsTree.getSelectedActionId();
            e.getPresentation().setEnabled(actionId != null);
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            editSelection(e.getInputEvent(), false);
        }
    });
    panel.add(toolbar, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
    group = new DefaultActionGroup();
    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    actionToolbar.setReservePlaceAutoPopupIcon(false);
    final JComponent searchToolbar = actionToolbar.getComponent();
    final Alarm alarm = new Alarm();
    myFilterComponent = new FilterComponent("KEYMAP", 5) {

        @Override
        public void filter() {
            alarm.cancelAllRequests();
            alarm.addRequest(() -> {
                if (!myFilterComponent.isShowing())
                    return;
                myTreeExpansionMonitor.freeze();
                myFilteringPanel.setShortcut(null);
                final String filter = getFilter();
                myActionsTree.filter(filter, myQuickLists);
                final JTree tree = myActionsTree.getTree();
                TreeUtil.expandAll(tree);
                if (filter == null || filter.length() == 0) {
                    TreeUtil.collapseAll(tree, 0);
                    myTreeExpansionMonitor.restore();
                } else {
                    myTreeExpansionMonitor.unfreeze();
                }
            }, 300);
        }
    };
    myFilterComponent.reset();
    panel.add(myFilterComponent, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
    group.add(new DumbAwareAction(KeyMapBundle.message("filter.shortcut.action.text"), KeyMapBundle.message("filter.shortcut.action.text"), AllIcons.Actions.ShortcutFilter) {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            myFilterComponent.reset();
            //noinspection ConstantConditions
            myActionsTree.reset(myEditor.getModel().getSelected(), myQuickLists);
            myFilteringPanel.showPopup(searchToolbar);
        }
    });
    group.add(new DumbAwareAction(KeyMapBundle.message("filter.clear.action.text"), KeyMapBundle.message("filter.clear.action.text"), AllIcons.Actions.GC) {

        @Override
        public void update(AnActionEvent event) {
            boolean enabled = null != myFilteringPanel.getShortcut();
            Presentation presentation = event.getPresentation();
            presentation.setEnabled(enabled);
            presentation.setIcon(enabled ? AllIcons.Actions.Cancel : EmptyIcon.ICON_16);
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            myTreeExpansionMonitor.freeze();
            myFilteringPanel.setShortcut(null);
            //clear filtering
            myActionsTree.filter(null, myQuickLists);
            TreeUtil.collapseAll(myActionsTree.getTree(), 0);
            myTreeExpansionMonitor.restore();
        }
    });
    panel.add(searchToolbar, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
    return panel;
}
Also used : TreeExpander(com.intellij.ide.TreeExpander) FilterComponent(com.intellij.ui.FilterComponent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Alarm(com.intellij.util.Alarm) CommonActionsManager(com.intellij.ide.CommonActionsManager)

Example 19 with DumbAwareAction

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

the class ToolWindowContentUi method toggleContentPopup.

public void toggleContentPopup() {
    if (myShouldNotShowPopup) {
        myShouldNotShowPopup = false;
        return;
    }
    final Ref<AnAction> selected = Ref.create();
    final Ref<AnAction> selectedTab = Ref.create();
    final Content[] contents = myManager.getContents();
    final Content selectedContent = myManager.getSelectedContent();
    final AnAction[] actions = new AnAction[contents.length];
    for (int i = 0; i < actions.length; i++) {
        final Content content = contents[i];
        if (content instanceof TabbedContent) {
            final TabbedContent tabbedContent = (TabbedContent) content;
            final List<Pair<String, JComponent>> tabs = ((TabbedContent) content).getTabs();
            final AnAction[] tabActions = new AnAction[tabs.size()];
            for (int j = 0; j < tabActions.length; j++) {
                final int index = j;
                tabActions[j] = new DumbAwareAction(tabs.get(index).first) {

                    @Override
                    public void actionPerformed(@NotNull AnActionEvent e) {
                        myManager.setSelectedContent(tabbedContent);
                        tabbedContent.selectContent(index);
                    }
                };
            }
            final DefaultActionGroup group = new DefaultActionGroup(tabActions);
            group.getTemplatePresentation().setText(((TabbedContent) content).getTitlePrefix());
            group.setPopup(true);
            actions[i] = group;
            if (content == selectedContent) {
                selected.set(group);
                final int selectedIndex = ContentUtilEx.getSelectedTab(tabbedContent);
                if (selectedIndex != -1) {
                    selectedTab.set(tabActions[selectedIndex]);
                }
            }
        } else {
            actions[i] = new DumbAwareAction() {

                {
                    getTemplatePresentation().setText(content.getTabName(), false);
                }

                @Override
                public void actionPerformed(@NotNull AnActionEvent e) {
                    myManager.setSelectedContent(content, true, true);
                }
            };
            if (content == selectedContent) {
                selected.set(actions[i]);
            }
        }
    }
    final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, new DefaultActionGroup(actions), DataManager.getInstance().getDataContext(myManager.getComponent()), false, true, true, null, -1, action -> action == selected.get() || action == selectedTab.get());
    getCurrentLayout().showContentPopup(popup);
    if (selectedContent instanceof TabbedContent) {
        new Alarm(Alarm.ThreadToUse.SWING_THREAD, popup).addRequest(() -> popup.handleSelect(true), 30);
    }
}
Also used : ListPopup(com.intellij.openapi.ui.popup.ListPopup) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Alarm(com.intellij.util.Alarm) Pair(com.intellij.openapi.util.Pair)

Example 20 with DumbAwareAction

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

the class QuickChangeLookAndFeel method fillActions.

protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) {
    LafManager lafMan = LafManager.getInstance();
    UIManager.LookAndFeelInfo[] lfs = lafMan.getInstalledLookAndFeels();
    UIManager.LookAndFeelInfo current = lafMan.getCurrentLookAndFeel();
    for (UIManager.LookAndFeelInfo lf : lfs) {
        group.add(new DumbAwareAction(lf.getName(), "", lf == current ? ourCurrentAction : ourNotCurrentAction) {

            public void actionPerformed(AnActionEvent e) {
                switchLafAndUpdateUI(lafMan, lf);
            }
        });
    }
}
Also used : LafManager(com.intellij.ide.ui.LafManager) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

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