Search in sources :

Example 51 with AnActionEvent

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

the class ChangeSignatureDialogBase method createOptionsPanel.

protected JComponent createOptionsPanel() {
    final JPanel panel = new JPanel(new BorderLayout());
    if (myAllowDelegation) {
        myDelegationPanel = createDelegationPanel();
        panel.add(myDelegationPanel, BorderLayout.WEST);
    }
    myPropagateParamChangesButton = new AnActionButton(RefactoringBundle.message("changeSignature.propagate.parameters.title"), null, AllIcons.Hierarchy.Caller) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Ref<CallerChooserBase<Method>> chooser = new Ref<>();
            Consumer<Set<Method>> callback = callers -> {
                myMethodsToPropagateParameters = callers;
                myParameterPropagationTreeToReuse = chooser.get().getTree();
            };
            try {
                String message = RefactoringBundle.message("changeSignature.parameter.caller.chooser");
                chooser.set(createCallerChooser(message, myParameterPropagationTreeToReuse, callback));
            } catch (ProcessCanceledException ex) {
                // user cancelled initial callers search, don't show dialog
                return;
            }
            chooser.get().show();
        }
    };
    final JPanel result = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP));
    result.add(panel);
    return result;
}
Also used : Ref(com.intellij.openapi.util.Ref) Consumer(com.intellij.util.Consumer) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout)

Example 52 with AnActionEvent

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

the class ConfigureTasksActivationDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            ProjectItem projectItem = (ProjectItem) projectCombobox.getSelectedItem();
            if (projectItem == null)
                return;
            final ExternalProjectInfo projectData = ProjectDataManager.getInstance().getExternalProjectData(myProject, myProjectSystemId, projectItem.myProjectSettings.getExternalProjectPath());
            if (projectData == null || projectData.getExternalProjectStructure() == null)
                return;
            final List<ProjectPopupItem> popupItems = ContainerUtil.newArrayList();
            for (DataNode<ModuleData> moduleDataNode : ExternalSystemApiUtil.findAllRecursively(projectData.getExternalProjectStructure(), ProjectKeys.MODULE)) {
                if (moduleDataNode.isIgnored())
                    continue;
                final List<String> tasks = ContainerUtil.map(ExternalSystemApiUtil.findAll(moduleDataNode, ProjectKeys.TASK), node -> node.getData().getName());
                if (!tasks.isEmpty()) {
                    popupItems.add(new ProjectPopupItem(moduleDataNode.getData(), tasks));
                }
            }
            final ChooseProjectStep projectStep = new ChooseProjectStep(popupItems);
            final List<ProjectPopupItem> projectItems = projectStep.getValues();
            ListPopupStep step = projectItems.size() == 1 ? (ListPopupStep) projectStep.onChosen(projectItems.get(0), false) : projectStep;
            assert step != null;
            JBPopupFactory.getInstance().createListPopup(step).show(ObjectUtils.notNull(button.getPreferredPopupPoint(), RelativePoint.getSouthEastOf(projectCombobox)));
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            List<TaskActivationEntry> tasks = findSelectedTasks();
            myTaskActivator.removeTasks(tasks);
            updateTree(null);
        }
    }).setMoveUpAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            moveAction(-1);
        }
    }).setMoveUpActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            return isMoveActionEnabled(-1);
        }
    }).setMoveDownAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            moveAction(+1);
        }
    }).setMoveDownActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            return isMoveActionEnabled(+1);
        }
    }).setToolbarPosition(ActionToolbarPosition.RIGHT).setToolbarBorder(IdeBorderFactory.createEmptyBorder());
    tasksPanel.add(decorator.createPanel());
    return contentPane;
}
Also used : BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListPopupStep(com.intellij.openapi.ui.popup.ListPopupStep) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData)

Example 53 with AnActionEvent

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

the class JumpToColorsAndFontsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    // todo handle ColorKey's as well
    Project project = e.getData(CommonDataKeys.PROJECT);
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (project == null || editor == null)
        return;
    Map<TextAttributesKey, Pair<ColorSettingsPage, AttributesDescriptor>> keyMap = ContainerUtil.newHashMap();
    Processor<RangeHighlighterEx> processor = r -> {
        Object tt = r.getErrorStripeTooltip();
        TextAttributesKey key = tt instanceof HighlightInfo ? ObjectUtils.chooseNotNull(((HighlightInfo) tt).forcedTextAttributesKey, ((HighlightInfo) tt).type.getAttributesKey()) : null;
        Pair<ColorSettingsPage, AttributesDescriptor> p = key == null ? null : ColorSettingsPages.getInstance().getAttributeDescriptor(key);
        if (p != null)
            keyMap.put(key, p);
        return true;
    };
    JBIterable<Editor> editors = editor instanceof EditorWindow ? JBIterable.of(editor, ((EditorWindow) editor).getDelegate()) : JBIterable.of(editor);
    for (Editor ed : editors) {
        TextRange selection = EditorUtil.getSelectionInAnyMode(ed);
        MarkupModel forDocument = DocumentMarkupModel.forDocument(ed.getDocument(), project, false);
        if (forDocument != null) {
            ((MarkupModelEx) forDocument).processRangeHighlightersOverlappingWith(selection.getStartOffset(), selection.getEndOffset(), processor);
        }
        ((MarkupModelEx) ed.getMarkupModel()).processRangeHighlightersOverlappingWith(selection.getStartOffset(), selection.getEndOffset(), processor);
        EditorHighlighter highlighter = ed instanceof EditorEx ? ((EditorEx) ed).getHighlighter() : null;
        SyntaxHighlighter syntaxHighlighter = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter) highlighter).getSyntaxHighlighter() : null;
        if (syntaxHighlighter != null) {
            HighlighterIterator iterator = highlighter.createIterator(selection.getStartOffset());
            while (!iterator.atEnd()) {
                for (TextAttributesKey key : syntaxHighlighter.getTokenHighlights(iterator.getTokenType())) {
                    Pair<ColorSettingsPage, AttributesDescriptor> p = key == null ? null : ColorSettingsPages.getInstance().getAttributeDescriptor(key);
                    if (p != null)
                        keyMap.put(key, p);
                }
                if (iterator.getEnd() >= selection.getEndOffset())
                    break;
                iterator.advance();
            }
        }
    }
    if (keyMap.isEmpty()) {
        HintManager.getInstance().showErrorHint(editor, "No text attributes found");
    } else if (keyMap.size() == 1) {
        Pair<ColorSettingsPage, AttributesDescriptor> p = keyMap.values().iterator().next();
        if (!openSettingsAndSelectKey(project, p.first, p.second)) {
            HintManager.getInstance().showErrorHint(editor, "No appropriate settings page found");
        }
    } else {
        ArrayList<Pair<ColorSettingsPage, AttributesDescriptor>> attrs = ContainerUtil.newArrayList(keyMap.values());
        Collections.sort(attrs, (o1, o2) -> StringUtil.naturalCompare(o1.first.getDisplayName() + o1.second.getDisplayName(), o2.first.getDisplayName() + o2.second.getDisplayName()));
        EditorColorsScheme colorsScheme = editor.getColorsScheme();
        JBList<Pair<ColorSettingsPage, AttributesDescriptor>> list = new JBList<>(attrs);
        list.setCellRenderer(new ColoredListCellRenderer<Pair<ColorSettingsPage, AttributesDescriptor>>() {

            @Override
            protected void customizeCellRenderer(@NotNull JList<? extends Pair<ColorSettingsPage, AttributesDescriptor>> list, Pair<ColorSettingsPage, AttributesDescriptor> value, int index, boolean selected, boolean hasFocus) {
                TextAttributes ta = colorsScheme.getAttributes(value.second.getKey());
                Color fg = ObjectUtils.chooseNotNull(ta.getForegroundColor(), colorsScheme.getDefaultForeground());
                Color bg = ObjectUtils.chooseNotNull(ta.getBackgroundColor(), colorsScheme.getDefaultBackground());
                SimpleTextAttributes sa = fromTextAttributes(ta);
                SimpleTextAttributes saOpaque = sa.derive(STYLE_OPAQUE | sa.getStyle(), fg, bg, null);
                SimpleTextAttributes saSelected = REGULAR_ATTRIBUTES.derive(sa.getStyle(), null, null, null);
                SimpleTextAttributes saCur = REGULAR_ATTRIBUTES;
                List<String> split = StringUtil.split(value.first.getDisplayName() + "//" + value.second.getDisplayName(), "//");
                for (int i = 0, len = split.size(); i < len; i++) {
                    boolean last = i == len - 1;
                    saCur = !last ? REGULAR_ATTRIBUTES : selected ? saSelected : saOpaque;
                    if (last)
                        append(" ", saCur);
                    append(split.get(i), saCur);
                    if (last)
                        append(" ", saCur);
                    else
                        append(" > ", GRAYED_ATTRIBUTES);
                }
                Color stripeColor = ta.getErrorStripeColor();
                boolean addStripe = stripeColor != null && stripeColor != saCur.getBgColor();
                boolean addBoxed = ta.getEffectType() == EffectType.BOXED && ta.getEffectColor() != null;
                if (addBoxed) {
                    append("▢" + (addStripe ? "" : " "), saCur.derive(-1, ta.getEffectColor(), null, null));
                }
                if (addStripe) {
                    append(" ", saCur.derive(STYLE_OPAQUE, null, stripeColor, null));
                }
            }
        });
        JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle(StringUtil.notNullize(e.getPresentation().getText())).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
            Pair<ColorSettingsPage, AttributesDescriptor> p = list.getSelectedValue();
            if (p != null && !openSettingsAndSelectKey(project, p.first, p.second)) {
                HintManager.getInstance().showErrorHint(editor, "No appropriate settings page found");
            }
        }).createPopup().showInBestPositionFor(editor);
    }
}
Also used : Settings(com.intellij.openapi.options.ex.Settings) JBIterable(com.intellij.util.containers.JBIterable) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) ContainerUtil(com.intellij.util.containers.ContainerUtil) ColorSettingsPage(com.intellij.openapi.options.colors.ColorSettingsPage) ArrayList(java.util.ArrayList) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) ShowSettingsUtilImpl(com.intellij.ide.actions.ShowSettingsUtilImpl) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) Map(java.util.Map) EffectType(com.intellij.openapi.editor.markup.EffectType) Project(com.intellij.openapi.project.Project) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBList(com.intellij.ui.components.JBList) ColorSettingsPages(com.intellij.openapi.options.colors.ColorSettingsPages) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) StringUtil(com.intellij.openapi.util.text.StringUtil) ActionCallback(com.intellij.openapi.util.ActionCallback) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) AttributesDescriptor(com.intellij.openapi.options.colors.AttributesDescriptor) SettingsDialog(com.intellij.openapi.options.newEditor.SettingsDialog) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) EditorWindow(com.intellij.injected.editor.EditorWindow) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) java.awt(java.awt) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) Processor(com.intellij.util.Processor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Pair(com.intellij.openapi.util.Pair) ObjectUtils(com.intellij.util.ObjectUtils) HintManager(com.intellij.codeInsight.hint.HintManager) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) ArrayList(java.util.ArrayList) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) NotNull(org.jetbrains.annotations.NotNull) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ColorSettingsPage(com.intellij.openapi.options.colors.ColorSettingsPage) Pair(com.intellij.openapi.util.Pair) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) AttributesDescriptor(com.intellij.openapi.options.colors.AttributesDescriptor) TextRange(com.intellij.openapi.util.TextRange) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) EditorWindow(com.intellij.injected.editor.EditorWindow) Project(com.intellij.openapi.project.Project) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) JBList(com.intellij.ui.components.JBList) Editor(com.intellij.openapi.editor.Editor) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

Example 54 with AnActionEvent

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

the class JdkListConfigurable method createAddAction.

@Override
public AbstractAddGroup createAddAction() {
    return new AbstractAddGroup(ProjectBundle.message("add.new.jdk.text")) {

        @NotNull
        @Override
        public AnAction[] getChildren(@Nullable final AnActionEvent e) {
            DefaultActionGroup group = new DefaultActionGroup(ProjectBundle.message("add.new.jdk.text"), true);
            myJdksTreeModel.createAddActions(group, myTree, projectJdk -> addJdkNode(projectJdk, true));
            return group.getChildren(null);
        }
    };
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Nullable(org.jetbrains.annotations.Nullable)

Example 55 with AnActionEvent

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

the class MarkAsPlainTextAction method update.

@Override
public void update(AnActionEvent e) {
    EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
    JBIterable<VirtualFile> selectedFiles = typeManager == null ? JBIterable.empty() : JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)).filter(file -> EnforcedPlainTextFileTypeManager.isApplicableFor(file) && !typeManager.isMarkedAsPlainText(file));
    boolean enabled = e.getProject() != null && !selectedFiles.isEmpty();
    e.getPresentation().setEnabledAndVisible(enabled);
    e.getPresentation().setIcon(EnforcedPlainTextFileTypeFactory.ENFORCED_PLAIN_TEXT_ICON);
}
Also used : EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBIterable(com.intellij.util.containers.JBIterable) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) EnforcedPlainTextFileTypeFactory(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeFactory) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager)

Aggregations

AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)130 AnAction (com.intellij.openapi.actionSystem.AnAction)67 Project (com.intellij.openapi.project.Project)27 NotNull (org.jetbrains.annotations.NotNull)25 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 Nullable (org.jetbrains.annotations.Nullable)20 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)15 List (java.util.List)14 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)8 JBTable (com.intellij.ui.table.JBTable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)7 Pair (com.intellij.openapi.util.Pair)7 Logger (com.intellij.openapi.diagnostic.Logger)6 Ref (com.intellij.openapi.util.Ref)6 AnActionButton (com.intellij.ui.AnActionButton)6