Search in sources :

Example 1 with ListSeparator

use of com.intellij.openapi.ui.popup.ListSeparator in project intellij-community by JetBrains.

the class CompoundRunConfigurationSettingsEditor method createEditor.

@NotNull
@Override
protected JComponent createEditor() {
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myList);
    return decorator.disableUpDownActions().setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final List<RunConfiguration> all = new ArrayList<>();
            for (ConfigurationType type : myRunManager.getConfigurationFactories()) {
                if (!(type instanceof UnknownConfigurationType)) {
                    for (RunnerAndConfigurationSettings settings : myRunManager.getConfigurationSettingsList(type)) {
                        all.add(settings.getConfiguration());
                    }
                }
            }
            final List<RunConfiguration> configurations = ContainerUtil.filter(all, configuration -> !mySnapshot.getSetToRun().contains(configuration) && canBeAdded(configuration, mySnapshot));
            JBPopupFactory.getInstance().createListPopup(new MultiSelectionListPopupStep<RunConfiguration>(null, configurations) {

                @Nullable
                @Override
                public ListSeparator getSeparatorAbove(RunConfiguration value) {
                    int i = configurations.indexOf(value);
                    if (i < 1)
                        return null;
                    RunConfiguration previous = configurations.get(i - 1);
                    return value.getType() != previous.getType() ? new ListSeparator() : null;
                }

                @Override
                public Icon getIconFor(RunConfiguration value) {
                    return value.getType().getIcon();
                }

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

                @NotNull
                @Override
                public String getTextFor(RunConfiguration value) {
                    return value.getName();
                }

                @Override
                public PopupStep<?> onChosen(List<RunConfiguration> selectedValues, boolean finalChoice) {
                    myList.clearSelection();
                    myModel.addAll(selectedValues);
                    return FINAL_CHOICE;
                }
            }).showUnderneathOf(decorator.getActionsPanel());
        }
    }).setEditAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            int index = myList.getSelectedIndex();
            if (index == -1)
                return;
            RunConfiguration configuration = myModel.get(index);
            RunConfigurationSelector selector = RunConfigurationSelector.KEY.getData(DataManager.getInstance().getDataContext(button.getContextComponent()));
            if (selector != null) {
                selector.select(configuration);
            }
        }
    }).setToolbarPosition(ActionToolbarPosition.TOP).createPanel();
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) UnknownConfigurationType(com.intellij.execution.configurations.UnknownConfigurationType) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) ArrayList(java.util.ArrayList) RunConfigurationSelector(com.intellij.execution.impl.RunConfigurationSelector) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) UnknownConfigurationType(com.intellij.execution.configurations.UnknownConfigurationType) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) List(java.util.List) MultiSelectionListPopupStep(com.intellij.openapi.ui.popup.MultiSelectionListPopupStep) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ListSeparator

use of com.intellij.openapi.ui.popup.ListSeparator in project intellij-community by JetBrains.

the class PluginDescriptorChooser method show.

public static void show(final Project project, final Editor editor, final PsiFile file, final Consumer<DomFileElement<IdeaPlugin>> consumer) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    assert module != null;
    List<DomFileElement<IdeaPlugin>> elements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, module.getModuleWithDependentsScope());
    elements = ContainerUtil.filter(elements, element -> {
        VirtualFile virtualFile = element.getFile().getVirtualFile();
        return virtualFile != null && ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile);
    });
    elements = findAppropriateIntelliJModule(module.getName(), elements);
    if (elements.isEmpty()) {
        HintManager.getInstance().showErrorHint(editor, "Cannot find plugin descriptor");
        return;
    }
    if (elements.size() == 1) {
        consumer.consume(elements.get(0));
        return;
    }
    final BaseListPopupStep<PluginDescriptorCandidate> popupStep = new BaseListPopupStep<PluginDescriptorCandidate>("Choose Plugin Descriptor", createCandidates(module, elements)) {

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

        @Override
        public Icon getIconFor(PluginDescriptorCandidate candidate) {
            return candidate.getIcon();
        }

        @NotNull
        @Override
        public String getTextFor(PluginDescriptorCandidate candidate) {
            return candidate.getText();
        }

        @Nullable
        @Override
        public ListSeparator getSeparatorAbove(PluginDescriptorCandidate candidate) {
            final String separatorText = candidate.getSeparatorText();
            if (separatorText != null) {
                return new ListSeparator(separatorText);
            }
            return null;
        }

        @Override
        public PopupStep onChosen(PluginDescriptorCandidate selectedValue, boolean finalChoice) {
            consumer.consume(selectedValue.myDomFileElement);
            return FINAL_CHOICE;
        }
    };
    JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor);
}
Also used : IncludedXmlTag(com.intellij.xml.util.IncludedXmlTag) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) ContainerUtil(com.intellij.util.containers.ContainerUtil) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Comparing(com.intellij.openapi.util.Comparing) Extensions(org.jetbrains.idea.devkit.dom.Extensions) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) EmptyIcon(com.intellij.util.ui.EmptyIcon) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) DomFileElement(com.intellij.util.xml.DomFileElement) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable) ModulesAlphaComparator(com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator) List(java.util.List) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) DomService(com.intellij.util.xml.DomService) Function(com.intellij.util.Function) PopupStep(com.intellij.openapi.ui.popup.PopupStep) HintManager(com.intellij.codeInsight.hint.HintManager) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) DomFileElement(com.intellij.util.xml.DomFileElement) Module(com.intellij.openapi.module.Module)

Example 3 with ListSeparator

use of com.intellij.openapi.ui.popup.ListSeparator in project intellij-community by JetBrains.

the class ListPopupModel method rebuildLists.

private void rebuildLists() {
    myFilteredList.clear();
    mySeparators.clear();
    myFullMatchIndex = -1;
    myStartsWithIndex = -1;
    ListSeparator lastSeparator = null;
    for (Object each : myOriginalList) {
        lastSeparator = ObjectUtils.chooseNotNull(myStep.getSeparatorAbove(each), lastSeparator);
        if (myFilter.shouldBeShowing(each)) {
            addToFiltered(each);
            if (lastSeparator != null) {
                mySeparators.put(each, lastSeparator);
                lastSeparator = null;
            }
        }
    }
}
Also used : ListSeparator(com.intellij.openapi.ui.popup.ListSeparator)

Example 4 with ListSeparator

use of com.intellij.openapi.ui.popup.ListSeparator in project intellij-community by JetBrains.

the class GitPushTargetPanel method showRemoteSelector.

private void showRemoteSelector(@NotNull Component component, @NotNull Point point) {
    List<PopupItem> remotes = getPopupItems();
    if (remotes.size() <= 1) {
        return;
    }
    ListPopup popup = new ListPopupImpl(new BaseListPopupStep<PopupItem>(null, remotes) {

        @Override
        public PopupStep onChosen(@NotNull PopupItem selectedValue, boolean finalChoice) {
            return doFinalStep(() -> {
                if (selectedValue.isDefineRemote()) {
                    showDefineRemoteDialog();
                } else {
                    myRemoteRenderer.updateLinkText(selectedValue.getPresentable());
                    if (myFireOnChangeAction != null && !myTargetEditor.isShowing()) {
                        //fireOnChange only when editing completed
                        myFireOnChangeAction.run();
                    }
                }
            });
        }

        @Nullable
        @Override
        public ListSeparator getSeparatorAbove(PopupItem value) {
            return value.isDefineRemote() ? new ListSeparator() : null;
        }
    }) {

        @Override
        public void cancel(InputEvent e) {
            super.cancel(e);
            if (myTargetEditor.isShowing()) {
                //repaint and force move focus to target editor component
                GitPushTargetPanel.this.repaint();
                IdeFocusManager.getInstance(myProject).requestFocus(myTargetEditor, true);
            }
        }
    };
    popup.show(new RelativePoint(component, point));
}
Also used : ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) ListPopup(com.intellij.openapi.ui.popup.ListPopup) RelativePoint(com.intellij.ui.awt.RelativePoint) Nullable(org.jetbrains.annotations.Nullable) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Aggregations

ListSeparator (com.intellij.openapi.ui.popup.ListSeparator)4 PopupStep (com.intellij.openapi.ui.popup.PopupStep)2 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 HintManager (com.intellij.codeInsight.hint.HintManager)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 UnknownConfigurationType (com.intellij.execution.configurations.UnknownConfigurationType)1 RunConfigurationSelector (com.intellij.execution.impl.RunConfigurationSelector)1 AllIcons (com.intellij.icons.AllIcons)1 Editor (com.intellij.openapi.editor.Editor)1 Module (com.intellij.openapi.module.Module)1 ModuleGrouper (com.intellij.openapi.module.ModuleGrouper)1 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)1 Project (com.intellij.openapi.project.Project)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 ModulesAlphaComparator (com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator)1