Search in sources :

Example 1 with BaseListPopupStep

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

the class AnnotateCapitalizationIntention method invoke.

@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
    final PsiModifierListOwner modifierListOwner = getElement(editor, file);
    if (modifierListOwner == null)
        throw new IncorrectOperationException();
    BaseListPopupStep<Nls.Capitalization> step = new BaseListPopupStep<Nls.Capitalization>(null, Nls.Capitalization.Title, Nls.Capitalization.Sentence) {

        @Override
        public PopupStep onChosen(final Nls.Capitalization selectedValue, boolean finalChoice) {
            new WriteCommandAction.Simple(project) {

                @Override
                protected void run() throws Throwable {
                    String nls = Nls.class.getName();
                    PsiAnnotation annotation = JavaPsiFacade.getInstance(project).getElementFactory().createAnnotationFromText("@" + nls + "(capitalization = " + nls + ".Capitalization." + selectedValue.toString() + ")", modifierListOwner);
                    new AddAnnotationFix(Nls.class.getName(), modifierListOwner, annotation.getParameterList().getAttributes()).applyFix();
                }
            }.execute();
            return FINAL_CHOICE;
        }
    };
    JBPopupFactory.getInstance().createListPopup(step).showInBestPositionFor(editor);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Nls(org.jetbrains.annotations.Nls) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) IncorrectOperationException(com.intellij.util.IncorrectOperationException) AddAnnotationFix(com.intellij.codeInsight.intention.AddAnnotationFix)

Example 2 with BaseListPopupStep

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

the class FormSpellCheckingInspection method checkStringDescriptor.

@Override
protected void checkStringDescriptor(Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
    final String value = descriptor.getResolvedValue();
    if (value == null) {
        return;
    }
    final SpellCheckerManager manager = SpellCheckerManager.getInstance(module.getProject());
    PlainTextSplitter.getInstance().split(value, TextRange.allOf(value), textRange -> {
        final String word = textRange.substring(value);
        if (manager.hasProblem(word)) {
            final List<String> suggestions = manager.getSuggestions(word);
            if (!suggestions.isEmpty() && prop instanceof IntroStringProperty) {
                EditorQuickFixProvider changeToProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, final RadComponent component1) {
                        return new PopupQuickFix<String>(editor, "Change to...", component1) {

                            @Override
                            public void run() {
                                ListPopup popup = JBPopupFactory.getInstance().createListPopup(getPopupStep());
                                popup.showUnderneathOf(component1.getDelegee());
                            }

                            @Override
                            public ListPopupStep<String> getPopupStep() {
                                return new BaseListPopupStep<String>("Select Replacement", suggestions) {

                                    @Override
                                    public PopupStep onChosen(String selectedValue, boolean finalChoice) {
                                        FormInspectionUtil.updateStringPropertyValue(editor, component1, (IntroStringProperty) prop, descriptor, selectedValue);
                                        return FINAL_CHOICE;
                                    }
                                };
                            }
                        };
                    }
                };
                EditorQuickFixProvider acceptProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, RadComponent component1) {
                        return new QuickFix(editor, "Save '" + word + "' to dictionary", component1) {

                            @Override
                            public void run() {
                                manager.acceptWordAsCorrect(word, editor.getProject());
                            }
                        };
                    }
                };
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'", changeToProvider, acceptProvider);
            } else {
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'");
            }
        }
    });
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor)

Example 3 with BaseListPopupStep

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

the class ModuleChooserUtil method selectModule.

public static void selectModule(@NotNull Project project, final Collection<Module> suitableModules, final Function<Module, String> versionProvider, final Consumer<Module> callback, @Nullable DataContext context) {
    final List<Module> modules = new ArrayList<>();
    final Map<Module, String> versions = new HashMap<>();
    for (Module module : suitableModules) {
        modules.add(module);
        versions.put(module, versionProvider.fun(module));
    }
    if (modules.size() == 1) {
        callback.consume(modules.get(0));
        return;
    }
    Collections.sort(modules, ModulesAlphaComparator.INSTANCE);
    BaseListPopupStep<Module> step = new BaseListPopupStep<Module>("Which module to use classpath of?", modules, PlatformIcons.CONTENT_ROOT_ICON_CLOSED) {

        @NotNull
        @Override
        public String getTextFor(Module value) {
            return String.format("%s (%s)", value.getName(), versions.get(value));
        }

        @Override
        public String getIndexedString(Module value) {
            return value.getName();
        }

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

        @Override
        public PopupStep onChosen(Module selectedValue, boolean finalChoice) {
            PropertiesComponent.getInstance(selectedValue.getProject()).setValue(GROOVY_LAST_MODULE, selectedValue.getName());
            callback.consume(selectedValue);
            return null;
        }
    };
    final String lastModuleName = PropertiesComponent.getInstance(project).getValue(GROOVY_LAST_MODULE);
    if (lastModuleName != null) {
        int defaultOption = ContainerUtil.indexOf(modules, new Condition<Module>() {

            @Override
            public boolean value(Module module) {
                return module.getName().equals(lastModuleName);
            }
        });
        if (defaultOption >= 0) {
            step.setDefaultOptionIndex(defaultOption);
        }
    }
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
    if (context == null) {
        listPopup.showCenteredInCurrentWindow(project);
    } else {
        listPopup.showInBestPositionFor(context);
    }
}
Also used : BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListPopup(com.intellij.openapi.ui.popup.ListPopup) Module(com.intellij.openapi.module.Module)

Example 4 with BaseListPopupStep

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

the class AbstractAddToTestsPatternAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
    final LinkedHashSet<PsiElement> classes = new LinkedHashSet<>();
    PsiElementProcessor.CollectElements<PsiElement> processor = new PsiElementProcessor.CollectElements<>(classes);
    getPatternBasedProducer().collectTestMembers(psiElements, true, true, processor);
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final List<T> patternConfigurations = collectPatternConfigurations(classes, project);
    if (patternConfigurations.size() == 1) {
        final T configuration = patternConfigurations.get(0);
        for (PsiElement aClass : classes) {
            getPatterns(configuration).add(getPatternBasedProducer().getQName(aClass));
        }
    } else {
        JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<T>("Choose suite to add", patternConfigurations) {

            @Override
            public PopupStep onChosen(T configuration, boolean finalChoice) {
                for (PsiElement aClass : classes) {
                    getPatterns(configuration).add(getPatternBasedProducer().getQName(aClass));
                }
                return FINAL_CHOICE;
            }

            @Override
            public Icon getIconFor(T configuration) {
                return configuration.getIcon();
            }

            @NotNull
            @Override
            public String getTextFor(T value) {
                return value.getName();
            }
        }).showInBestPositionFor(dataContext);
    }
}
Also used : Project(com.intellij.openapi.project.Project) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PsiElement(com.intellij.psi.PsiElement) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor)

Example 5 with BaseListPopupStep

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

the class ExpressionInputComponent method showHistory.

private void showHistory() {
    List<XExpression> expressions = myExpressionEditor.getRecentExpressions();
    if (!expressions.isEmpty()) {
        ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) {

            @Override
            public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) {
                myExpressionEditor.setExpression(selectedValue);
                myExpressionEditor.requestFocusInEditor();
                return FINAL_CHOICE;
            }
        }) {

            @Override
            protected ListCellRenderer getListElementRenderer() {
                return new ColoredListCellRenderer<XExpression>() {

                    @Override
                    protected void customizeCellRenderer(@NotNull JList list, XExpression value, int index, boolean selected, boolean hasFocus) {
                        append(value.getExpression());
                    }
                };
            }
        };
        popup.getList().setFont(EditorUtil.getEditorFont());
        popup.showUnderneathOf(myExpressionEditor.getEditorComponent());
    }
}
Also used : ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) XExpression(com.intellij.xdebugger.XExpression) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Aggregations

BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)33 PopupStep (com.intellij.openapi.ui.popup.PopupStep)18 NotNull (org.jetbrains.annotations.NotNull)15 ListPopup (com.intellij.openapi.ui.popup.ListPopup)10 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Project (com.intellij.openapi.project.Project)7 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)5 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiFile (com.intellij.psi.PsiFile)4 Nullable (org.jetbrains.annotations.Nullable)3 AllIcons (com.intellij.icons.AllIcons)2 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 Editor (com.intellij.openapi.editor.Editor)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2