Search in sources :

Example 1 with ListPopup

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

the class AbstractComboBoxAction method createComboBoxButton.

@Override
protected ComboBoxButton createComboBoxButton(Presentation presentation) {
    if (myShowDisabledActions) {
        return new ComboBoxButton(presentation) {

            @Override
            protected JBPopup createPopup(Runnable onDispose) {
                ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, createPopupActionGroup(this), getDataContext(), true, onDispose, getMaxRows());
                popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight()));
                return popup;
            }
        };
    }
    return super.createComboBoxButton(presentation);
}
Also used : ListPopup(com.intellij.openapi.ui.popup.ListPopup)

Example 2 with ListPopup

use of com.intellij.openapi.ui.popup.ListPopup 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 ListPopup

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

the class MorphAction method actionPerformed.

protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    Processor<ComponentItem> processor = selectedValue -> {
        Runnable runnable = () -> {
            for (RadComponent c : selection) {
                if (!morphComponent(editor, c, selectedValue))
                    break;
            }
            editor.refreshAndSave(true);
        };
        CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable, UIDesignerBundle.message("morph.component.command"), null);
        IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
            IdeFocusManager.getGlobalInstance().requestFocus(editor.getGlassLayer(), true);
        });
        return true;
    };
    PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastMorphComponent, processor, UIDesignerBundle.message("morph.component.title"));
    step.hideNonAtomic();
    if (selection.size() == 1) {
        step.hideComponentClass(selection.get(0).getComponentClassName());
    }
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
    FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
}
Also used : PsiType(com.intellij.psi.PsiType) UIDesignerBundle(com.intellij.uiDesigner.UIDesignerBundle) RadAtomicComponent(com.intellij.uiDesigner.radComponents.RadAtomicComponent) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) ChangeFieldTypeFix(com.intellij.uiDesigner.quickFixes.ChangeFieldTypeFix) ArrayList(java.util.ArrayList) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) Palette(com.intellij.uiDesigner.palette.Palette) PsiElementFactory(com.intellij.psi.PsiElementFactory) IProperty(com.intellij.uiDesigner.lw.IProperty) Logger(com.intellij.openapi.diagnostic.Logger) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) BindingProperty(com.intellij.uiDesigner.propertyInspector.properties.BindingProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ListPopup(com.intellij.openapi.ui.popup.ListPopup) List(java.util.List) IComponent(com.intellij.uiDesigner.lw.IComponent) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Processor(com.intellij.util.Processor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PsiField(com.intellij.psi.PsiField) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) NotNull(org.jetbrains.annotations.NotNull) InsertComponentProcessor(com.intellij.uiDesigner.designSurface.InsertComponentProcessor) FormInspectionUtil(com.intellij.uiDesigner.inspections.FormInspectionUtil) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ListPopup(com.intellij.openapi.ui.popup.ListPopup)

Example 4 with ListPopup

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

the class CreateListenerAction method actionPerformed.

protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    final DefaultActionGroup actionGroup = prepareActionGroup(selection);
    final JComponent selectedComponent = selection.get(0).getDelegee();
    final DataContext context = DataManager.getInstance().getDataContext(selectedComponent);
    final JBPopupFactory factory = JBPopupFactory.getInstance();
    final ListPopup popup = factory.createActionGroupPopup(UIDesignerBundle.message("create.listener.title"), actionGroup, context, JBPopupFactory.ActionSelectionAid.NUMBERING, true);
    FormEditingUtil.showPopupUnderComponent(popup, selection.get(0));
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ListPopup(com.intellij.openapi.ui.popup.ListPopup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Example 5 with ListPopup

use of com.intellij.openapi.ui.popup.ListPopup 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)

Aggregations

ListPopup (com.intellij.openapi.ui.popup.ListPopup)49 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)11 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)10 NotNull (org.jetbrains.annotations.NotNull)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)7 Project (com.intellij.openapi.project.Project)7 PopupStep (com.intellij.openapi.ui.popup.PopupStep)7 DataContext (com.intellij.openapi.actionSystem.DataContext)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)4 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)4 MouseEvent (java.awt.event.MouseEvent)4 ArrayList (java.util.ArrayList)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)3 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nullable (org.jetbrains.annotations.Nullable)3 JBScrollPane (com.intellij.ui.components.JBScrollPane)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 java.awt (java.awt)2