Search in sources :

Example 81 with AnAction

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

the class FindUIHelper method registerAction.

private void registerAction(String actionName, boolean replace, FindDialog findDialog) {
    AnAction action = ActionManager.getInstance().getAction(actionName);
    JRootPane findDialogRootComponent = ((JDialog) (findDialog.getWindow())).getRootPane();
    new AnAction() {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            myModel.setReplaceState(replace);
            findDialog.updateReplaceVisibility();
        }
    }.registerCustomShortcutSet(action.getShortcutSet(), findDialogRootComponent);
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 82 with AnAction

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

the class ProjectSdksModel method createAddActions.

public void createAddActions(@NotNull DefaultActionGroup group, @NotNull final JComponent parent, @Nullable final Sdk selectedSdk, @NotNull final Consumer<Sdk> updateTree, @Nullable Condition<SdkTypeId> filter) {
    final SdkType[] types = SdkType.getAllTypes();
    for (final SdkType type : types) {
        if (filter != null && !filter.value(type))
            continue;
        final AnAction addAction = new DumbAwareAction(type.getPresentableName(), null, type.getIconForAddAction()) {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                doAdd(parent, selectedSdk, type, updateTree);
            }
        };
        group.add(addAction);
    }
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with AnAction

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

the class ProjectWindowActionGroup method findWindowActionsWithProjectName.

private List<ProjectWindowAction> findWindowActionsWithProjectName(String projectName) {
    List<ProjectWindowAction> result = null;
    final AnAction[] children = getChildren(null);
    for (AnAction child : children) {
        if (!(child instanceof ProjectWindowAction)) {
            continue;
        }
        final ProjectWindowAction windowAction = (ProjectWindowAction) child;
        if (projectName.equals(windowAction.getProjectName())) {
            if (result == null) {
                result = new ArrayList<>();
            }
            result.add(windowAction);
        }
    }
    if (result == null) {
        return Collections.emptyList();
    }
    return result;
}
Also used : AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 84 with AnAction

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

the class UnwrapHandler method showPopup.

private static void showPopup(final List<AnAction> options, Editor editor) {
    final ScopeHighlighter highlighter = new ScopeHighlighter(editor);
    DefaultListModel<String> m = new DefaultListModel<>();
    for (AnAction a : options) {
        m.addElement(((MyUnwrapAction) a).getName());
    }
    final JList list = new JBList(m);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setVisibleRowCount(options.size());
    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int index = list.getSelectedIndex();
            if (index < 0)
                return;
            MyUnwrapAction a = (MyUnwrapAction) options.get(index);
            List<PsiElement> toExtract = new ArrayList<>();
            PsiElement wholeRange = a.collectAffectedElements(toExtract);
            highlighter.highlight(wholeRange, toExtract);
        }
    });
    PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
    builder.setTitle(CodeInsightBundle.message("unwrap.popup.title")).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
        MyUnwrapAction a = (MyUnwrapAction) options.get(list.getSelectedIndex());
        a.actionPerformed(null);
    }).addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            highlighter.dropHighlight();
        }
    });
    JBPopup popup = builder.createPopup();
    popup.showInBestPositionFor(editor);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) ListSelectionListener(javax.swing.event.ListSelectionListener) JBList(com.intellij.ui.components.JBList) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) List(java.util.List) PsiElement(com.intellij.psi.PsiElement)

Example 85 with AnAction

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

the class RunLineMarkerProvider method getLineMarkerInfo.

@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
    List<RunLineMarkerContributor> contributors = RunLineMarkerContributor.EXTENSION.allForLanguage(element.getLanguage());
    Icon icon = null;
    List<Info> infos = null;
    for (RunLineMarkerContributor contributor : contributors) {
        Info info = contributor.getInfo(element);
        if (info == null) {
            continue;
        }
        if (icon == null) {
            icon = info.icon;
        }
        if (infos == null) {
            infos = new SmartList<>();
        }
        infos.add(info);
    }
    if (icon == null)
        return null;
    if (infos.size() > 1) {
        Collections.sort(infos, COMPARATOR);
        final Info first = infos.get(0);
        for (Iterator<Info> it = infos.iterator(); it.hasNext(); ) {
            Info info = it.next();
            if (info != first && first.shouldReplace(info)) {
                it.remove();
            }
        }
    }
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    for (Info info : infos) {
        for (AnAction action : info.actions) {
            actionGroup.add(new LineMarkerActionWrapper(element, action));
        }
        if (info != infos.get(infos.size() - 1)) {
            actionGroup.add(new Separator());
        }
    }
    List<Info> finalInfos = infos;
    Function<PsiElement, String> tooltipProvider = element1 -> {
        final StringBuilder tooltip = new StringBuilder();
        for (Info info : finalInfos) {
            if (info.tooltipProvider != null) {
                String string = info.tooltipProvider.apply(element1);
                if (string == null)
                    continue;
                if (tooltip.length() != 0) {
                    tooltip.append("\n");
                }
                tooltip.append(string);
            }
        }
        return tooltip.length() == 0 ? null : tooltip.toString();
    };
    return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, tooltipProvider, null, GutterIconRenderer.Alignment.CENTER) {

        @Nullable
        @Override
        public GutterIconRenderer createGutterRenderer() {
            return new LineMarkerGutterIconRenderer<PsiElement>(this) {

                @Override
                public AnAction getClickAction() {
                    return null;
                }

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

                @Nullable
                @Override
                public ActionGroup getPopupMenuActions() {
                    return actionGroup;
                }
            };
        }
    };
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Pass(com.intellij.codeHighlighting.Pass) LineMarkerProviderDescriptor(com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor) Nullable(org.jetbrains.annotations.Nullable) SmartList(com.intellij.util.SmartList) Function(com.intellij.util.Function) PsiElement(com.intellij.psi.PsiElement) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) javax.swing(javax.swing) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AnAction (com.intellij.openapi.actionSystem.AnAction)184 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)62 NotNull (org.jetbrains.annotations.NotNull)31 Project (com.intellij.openapi.project.Project)24 Nullable (org.jetbrains.annotations.Nullable)22 ActionManager (com.intellij.openapi.actionSystem.ActionManager)21 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)21 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)13 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)7 Presentation (com.intellij.openapi.actionSystem.Presentation)7 PsiFile (com.intellij.psi.PsiFile)7 ReopenProjectAction (com.intellij.ide.ReopenProjectAction)6 Editor (com.intellij.openapi.editor.Editor)6 Keymap (com.intellij.openapi.keymap.Keymap)6 Ref (com.intellij.openapi.util.Ref)6 List (java.util.List)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5