Search in sources :

Example 16 with PopupChooserBuilder

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

the class InjectLanguageAction method doChooseLanguageToInject.

public static boolean doChooseLanguageToInject(Editor editor, final Processor<Injectable> onChosen) {
    final List<Injectable> injectables = getAllInjectables();
    final JList list = new JBList(injectables);
    list.setCellRenderer(new ColoredListCellRendererWrapper<Injectable>() {

        @Override
        protected void doCustomize(JList list, Injectable language, int index, boolean selected, boolean hasFocus) {
            setIcon(language.getIcon());
            append(language.getDisplayName());
            String description = language.getAdditionalDescription();
            if (description != null) {
                append(description, SimpleTextAttributes.GRAYED_ATTRIBUTES);
            }
        }
    });
    Dimension minSize = new JLabel(PlainTextLanguage.INSTANCE.getDisplayName(), EmptyIcon.ICON_16, SwingConstants.LEFT).getMinimumSize();
    minSize.height *= 4;
    list.setMinimumSize(minSize);
    JBPopup popup = new PopupChooserBuilder(list).setItemChoosenCallback(() -> {
        Injectable value = (Injectable) list.getSelectedValue();
        if (value != null) {
            onChosen.process(value);
            PropertiesComponent.getInstance().setValue(LAST_INJECTED_LANGUAGE, value.getId());
        }
    }).setFilteringEnabled(language -> ((Injectable) language).getDisplayName()).setMinSize(minSize).createPopup();
    final String lastInjected = PropertiesComponent.getInstance().getValue(LAST_INJECTED_LANGUAGE);
    if (lastInjected != null) {
        Injectable injectable = ContainerUtil.find(injectables, injectable1 -> lastInjected.equals(injectable1.getId()));
        list.setSelectedValue(injectable, true);
    }
    popup.showInBestPositionFor(editor);
    return true;
}
Also used : Injectable(com.intellij.psi.injection.Injectable) JBList(com.intellij.ui.components.JBList) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 17 with PopupChooserBuilder

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

the class JumpFromRemoteFileToLocalAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Collection<VirtualFile> files = findLocalFiles(myProject, Urls.newFromVirtualFile(myFile), myFile.getName());
    if (files.isEmpty()) {
        Messages.showErrorDialog(myProject, "Cannot find local file for '" + myFile.getUrl() + "'", CommonBundle.getErrorTitle());
        return;
    }
    if (files.size() == 1) {
        navigateToFile(myProject, ContainerUtil.getFirstItem(files, null));
    } else {
        final JList list = new JBList(files);
        //noinspection unchecked
        list.setCellRenderer(new ColoredListCellRenderer() {

            @Override
            protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
                FileAppearanceService.getInstance().forVirtualFile((VirtualFile) value).customize(this);
            }
        });
        new PopupChooserBuilder(list).setTitle("Select Target File").setMovable(true).setItemChoosenCallback(() -> {
            //noinspection deprecation
            for (Object value : list.getSelectedValues()) {
                navigateToFile(myProject, (VirtualFile) value);
            }
        }).createPopup().showUnderneathOf(e.getInputEvent().getComponent());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HttpVirtualFile(com.intellij.openapi.vfs.impl.http.HttpVirtualFile) JBList(com.intellij.ui.components.JBList) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 18 with PopupChooserBuilder

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

the class ToolWindowsWidget method mouseEntered.

public void mouseEntered() {
    final boolean active = ApplicationManager.getApplication().isActive();
    if (!active) {
        return;
    }
    if (myAlarm.getActiveRequestCount() == 0) {
        myAlarm.addRequest(() -> {
            final IdeFrameImpl frame = UIUtil.getParentOfType(IdeFrameImpl.class, this);
            if (frame == null)
                return;
            List<ToolWindow> toolWindows = new ArrayList<>();
            final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(frame.getProject());
            for (String id : toolWindowManager.getToolWindowIds()) {
                final ToolWindow tw = toolWindowManager.getToolWindow(id);
                if (tw.isAvailable() && tw.isShowStripeButton()) {
                    toolWindows.add(tw);
                }
            }
            Collections.sort(toolWindows, (o1, o2) -> StringUtil.naturalCompare(o1.getStripeTitle(), o2.getStripeTitle()));
            final JBList list = new JBList(toolWindows);
            list.setCellRenderer(new ListCellRenderer() {

                final JBLabel label = new JBLabel();

                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    final ToolWindow toolWindow = (ToolWindow) value;
                    label.setText(toolWindow.getStripeTitle());
                    label.setIcon(toolWindow.getIcon());
                    label.setBorder(JBUI.Borders.empty(4, 10));
                    label.setForeground(UIUtil.getListForeground(isSelected));
                    label.setBackground(UIUtil.getListBackground(isSelected));
                    final JPanel panel = new JPanel(new BorderLayout());
                    panel.add(label, BorderLayout.CENTER);
                    panel.setBackground(UIUtil.getListBackground(isSelected));
                    return panel;
                }
            });
            final Dimension size = list.getPreferredSize();
            final JComponent c = this;
            final Insets padding = UIUtil.getListViewportPadding();
            final RelativePoint point = new RelativePoint(c, new Point(-4, -padding.top - padding.bottom - 4 - size.height + (SystemInfo.isMac ? 2 : 0)));
            if (popup != null && popup.isVisible()) {
                return;
            }
            list.setSelectedIndex(list.getItemsCount() - 1);
            PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
            popup = builder.setAutoselectOnMouseMove(true).setRequestFocus(false).setItemChoosenCallback(() -> {
                if (popup != null)
                    popup.closeOk(null);
                final Object value = list.getSelectedValue();
                if (value instanceof ToolWindow) {
                    ((ToolWindow) value).activate(null, true, true);
                }
            }).createPopup();
            // override default of 15 set when createPopup() is called
            list.setVisibleRowCount(30);
            popup.show(point);
        }, 300);
    }
}
Also used : IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) ArrayList(java.util.ArrayList) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBLabel(com.intellij.ui.components.JBLabel) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 19 with PopupChooserBuilder

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

the class BaseGenerateTestSupportMethodAction method chooseAndPerform.

private static void chooseAndPerform(Editor editor, List<TestFramework> frameworks, final Consumer<TestFramework> consumer) {
    if (frameworks.size() == 1) {
        consumer.consume(frameworks.get(0));
        return;
    }
    final JList list = new JBList(frameworks.toArray(new TestFramework[frameworks.size()]));
    list.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component result = super.getListCellRendererComponent(list, "", index, isSelected, cellHasFocus);
            if (value == null)
                return result;
            TestFramework framework = (TestFramework) value;
            setIcon(framework.getIcon());
            setText(framework.getName());
            return result;
        }
    });
    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setFilteringEnabled(o -> ((TestFramework) o).getName());
    builder.setTitle("Choose Framework").setItemChoosenCallback(() -> consumer.consume((TestFramework) list.getSelectedValue())).setMovable(true).createPopup().showInBestPositionFor(editor);
}
Also used : JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 20 with PopupChooserBuilder

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

the class NavigationUtil method getPsiElementPopup.

@NotNull
public static <T extends PsiElement> JBPopup getPsiElementPopup(@NotNull T[] elements, @NotNull final PsiElementListCellRenderer<T> renderer, @Nullable final String title, @NotNull final PsiElementProcessor<T> processor, @Nullable final T selection) {
    assert elements.length > 0 : "Attempted to show a navigation popup with zero elements";
    final JList list = new JBList(elements);
    HintUpdateSupply.installSimpleHintUpdateSupply(list);
    list.setCellRenderer(renderer);
    list.setFont(EditorUtil.getEditorFont());
    if (selection != null) {
        list.setSelectedValue(selection, true);
    }
    final Runnable runnable = () -> {
        int[] ids = list.getSelectedIndices();
        if (ids == null || ids.length == 0)
            return;
        for (Object element : list.getSelectedValues()) {
            if (element != null) {
                processor.execute((T) element);
            }
        }
    };
    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    if (title != null) {
        builder.setTitle(title);
    }
    renderer.installSpeedSearch(builder, true);
    JBPopup popup = builder.setItemChoosenCallback(runnable).createPopup();
    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);
    hidePopupIfDumbModeStarts(popup, elements[0].getProject());
    return popup;
}
Also used : JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)31 JBList (com.intellij.ui.components.JBList)24 JBPopup (com.intellij.openapi.ui.popup.JBPopup)15 PsiElementListCellRenderer (com.intellij.ide.util.PsiElementListCellRenderer)5 Project (com.intellij.openapi.project.Project)4 Ref (com.intellij.openapi.util.Ref)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 NotNull (org.jetbrains.annotations.NotNull)4 MethodCellRenderer (com.intellij.ide.util.MethodCellRenderer)3 PsiClassListCellRenderer (com.intellij.ide.util.PsiClassListCellRenderer)3 PsiElement (com.intellij.psi.PsiElement)3 JBLabel (com.intellij.ui.components.JBLabel)3 Editor (com.intellij.openapi.editor.Editor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)2 TreeTableView (com.intellij.ui.dualView.TreeTableView)2 UsageView (com.intellij.usages.UsageView)2 Alarm (com.intellij.util.Alarm)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ColumnInfo (com.intellij.util.ui.ColumnInfo)2