Search in sources :

Example 11 with ListPopupImpl

use of com.intellij.ui.popup.list.ListPopupImpl in project intellij-community by JetBrains.

the class AddMethodQualifierFix method chooseAndQualify.

private void chooseAndQualify(final Editor editor) {
    final BaseListPopupStep<PsiVariable> step = new BaseListPopupStep<PsiVariable>(QuickFixBundle.message("add.qualifier"), getOrFindCandidates()) {

        @Override
        public PopupStep onChosen(final PsiVariable selectedValue, final boolean finalChoice) {
            if (selectedValue != null && finalChoice) {
                WriteCommandAction.runWriteCommandAction(selectedValue.getProject(), () -> qualify(selectedValue, editor));
            }
            return FINAL_CHOICE;
        }

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

        @Override
        public Icon getIconFor(final PsiVariable aValue) {
            return aValue.getIcon(0);
        }
    };
    final ListPopupImpl popup = new ListPopupImpl(step);
    popup.showInBestPositionFor(editor);
}
Also used : BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl)

Example 12 with ListPopupImpl

use of com.intellij.ui.popup.list.ListPopupImpl in project intellij-community by JetBrains.

the class JvmSmartStepIntoHandler method handleTargets.

protected final boolean handleTargets(SourcePosition position, DebuggerSession session, TextEditor fileEditor, List<SmartStepTarget> targets) {
    if (!targets.isEmpty()) {
        SmartStepTarget firstTarget = targets.get(0);
        if (targets.size() == 1) {
            doStepInto(session, Registry.is("debugger.single.smart.step.force"), firstTarget);
        } else {
            Editor editor = fileEditor.getEditor();
            PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(editor, targets, chosenTarget -> doStepInto(session, true, chosenTarget));
            ListPopupImpl popup = new ListPopupImpl(popupStep);
            DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.STEP_INTO, XDebuggerActions.SMART_STEP_INTO);
            popup.setAdText(DebuggerUIUtil.getSelectionShortcutsAdText(XDebuggerActions.STEP_INTO, XDebuggerActions.SMART_STEP_INTO));
            UIUtil.maybeInstall(popup.getList().getInputMap(JComponent.WHEN_FOCUSED), "selectNextRow", KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
            popup.addListSelectionListener(new ListSelectionListener() {

                public void valueChanged(ListSelectionEvent e) {
                    popupStep.getScopeHighlighter().dropHighlight();
                    if (!e.getValueIsAdjusting()) {
                        final SmartStepTarget selectedTarget = (SmartStepTarget) ((JBList) e.getSource()).getSelectedValue();
                        if (selectedTarget != null) {
                            highlightTarget(popupStep, selectedTarget);
                        }
                    }
                }
            });
            highlightTarget(popupStep, firstTarget);
            DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine());
        }
        return true;
    }
    return false;
}
Also used : ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) Editor(com.intellij.openapi.editor.Editor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 13 with ListPopupImpl

use of com.intellij.ui.popup.list.ListPopupImpl in project intellij-community by JetBrains.

the class NavigationUtil method getPsiElementPopup.

private static JBPopup getPsiElementPopup(final Object[] elements, final Map<PsiElement, GotoRelatedItem> itemsMap, final String title, final boolean showContainingModules, final Processor<Object> processor) {
    final Ref<Boolean> hasMnemonic = Ref.create(false);
    final DefaultPsiElementCellRenderer renderer = new DefaultPsiElementCellRenderer() {

        {
            setFocusBorderEnabled(false);
        }

        @Override
        public String getElementText(PsiElement element) {
            String customName = itemsMap.get(element).getCustomName();
            return (customName != null ? customName : super.getElementText(element));
        }

        @Override
        protected Icon getIcon(PsiElement element) {
            Icon customIcon = itemsMap.get(element).getCustomIcon();
            return customIcon != null ? customIcon : super.getIcon(element);
        }

        @Override
        public String getContainerText(PsiElement element, String name) {
            String customContainerName = itemsMap.get(element).getCustomContainerName();
            if (customContainerName != null) {
                return customContainerName;
            }
            PsiFile file = element.getContainingFile();
            return file != null && !getElementText(element).equals(file.getName()) ? "(" + file.getName() + ")" : null;
        }

        @Override
        protected DefaultListCellRenderer getRightCellRenderer(Object value) {
            return showContainingModules ? super.getRightCellRenderer(value) : null;
        }

        @Override
        protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
            final GotoRelatedItem item = (GotoRelatedItem) value;
            Color color = list.getForeground();
            final SimpleTextAttributes nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
            final String name = item.getCustomName();
            if (name == null)
                return false;
            renderer.append(name, nameAttributes);
            renderer.setIcon(item.getCustomIcon());
            return true;
        }

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            final JPanel component = (JPanel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (!hasMnemonic.get())
                return component;
            final JPanel panelWithMnemonic = new JPanel(new BorderLayout());
            final int mnemonic = getMnemonic(value, itemsMap);
            final JLabel label = new JLabel("");
            if (mnemonic != -1) {
                label.setText(mnemonic + ".");
                label.setDisplayedMnemonicIndex(0);
            }
            label.setPreferredSize(new JLabel("8.").getPreferredSize());
            final JComponent leftRenderer = (JComponent) component.getComponents()[0];
            component.remove(leftRenderer);
            panelWithMnemonic.setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 0));
            panelWithMnemonic.setBackground(leftRenderer.getBackground());
            label.setBackground(leftRenderer.getBackground());
            panelWithMnemonic.add(label, BorderLayout.WEST);
            panelWithMnemonic.add(leftRenderer, BorderLayout.CENTER);
            component.add(panelWithMnemonic);
            return component;
        }
    };
    final ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<Object>(title, Arrays.asList(elements)) {

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

        @Override
        public String getIndexedString(Object value) {
            if (value instanceof GotoRelatedItem) {
                //noinspection ConstantConditions
                return ((GotoRelatedItem) value).getCustomName();
            }
            PsiElement element = (PsiElement) value;
            if (!element.isValid())
                return "INVALID";
            return renderer.getElementText(element) + " " + renderer.getContainerText(element, null);
        }

        @Override
        public PopupStep onChosen(Object selectedValue, boolean finalChoice) {
            processor.process(selectedValue);
            return super.onChosen(selectedValue, finalChoice);
        }
    }) {
    };
    popup.getList().setCellRenderer(new PopupListElementRenderer(popup) {

        Map<Object, String> separators = new HashMap<>();

        {
            final ListModel model = popup.getList().getModel();
            String current = null;
            boolean hasTitle = false;
            for (int i = 0; i < model.getSize(); i++) {
                final Object element = model.getElementAt(i);
                final GotoRelatedItem item = itemsMap.get(element);
                if (item != null && !StringUtil.equals(current, item.getGroup())) {
                    current = item.getGroup();
                    separators.put(element, current);
                    if (!hasTitle && !StringUtil.isEmpty(current)) {
                        hasTitle = true;
                    }
                }
            }
            if (!hasTitle) {
                separators.remove(model.getElementAt(0));
            }
        }

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            final Component component = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            final String separator = separators.get(value);
            if (separator != null) {
                JPanel panel = new JPanel(new BorderLayout());
                panel.add(component, BorderLayout.CENTER);
                final SeparatorWithText sep = new SeparatorWithText() {

                    @Override
                    protected void paintComponent(Graphics g) {
                        g.setColor(new JBColor(Color.WHITE, UIUtil.getSeparatorColor()));
                        g.fillRect(0, 0, getWidth(), getHeight());
                        super.paintComponent(g);
                    }
                };
                sep.setCaption(separator);
                panel.add(sep, BorderLayout.NORTH);
                return panel;
            }
            return component;
        }
    });
    popup.setMinimumSize(new Dimension(200, -1));
    for (Object item : elements) {
        final int mnemonic = getMnemonic(item, itemsMap);
        if (mnemonic != -1) {
            final Action action = createNumberAction(mnemonic, popup, itemsMap, processor);
            popup.registerAction(mnemonic + "Action", KeyStroke.getKeyStroke(String.valueOf(mnemonic)), action);
            popup.registerAction(mnemonic + "Action", KeyStroke.getKeyStroke("NUMPAD" + String.valueOf(mnemonic)), action);
            hasMnemonic.set(true);
        }
    }
    return popup;
}
Also used : PopupListElementRenderer(com.intellij.ui.popup.list.PopupListElementRenderer) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PsiFile(com.intellij.psi.PsiFile) JBColor(com.intellij.ui.JBColor) PsiElement(com.intellij.psi.PsiElement) JBColor(com.intellij.ui.JBColor) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) SeparatorWithText(com.intellij.ui.SeparatorWithText) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem)

Example 14 with ListPopupImpl

use of com.intellij.ui.popup.list.ListPopupImpl in project intellij-community by JetBrains.

the class AttachToLocalProcessAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = getEventProject(e);
    if (project == null)
        return;
    XLocalAttachDebuggerProvider[] providers = Extensions.getExtensions(XLocalAttachDebuggerProvider.EP);
    new Task.Backgroundable(project, XDebuggerBundle.message("xdebugger.attach.toLocal.action.collectingProcesses"), true, PerformInBackgroundOption.DEAF) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            ProcessInfo[] processList = OSProcessUtil.getProcessList();
            List<AttachItem> items = collectAttachItems(project, processList, indicator, providers);
            ApplicationManager.getApplication().invokeLater(() -> {
                if (project.isDisposed()) {
                    return;
                }
                ProcessListStep step = new ProcessListStep(items, project);
                final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step);
                final JList mainList = ((ListPopupImpl) popup).getList();
                ListSelectionListener listener = event -> {
                    if (event.getValueIsAdjusting())
                        return;
                    Object item = ((JList) event.getSource()).getSelectedValue();
                    if (item == null) {
                        item = mainList.getSelectedValue();
                    }
                    if (item instanceof AttachItem) {
                        String debuggerName = ((AttachItem) item).getSelectedDebugger().getDebuggerDisplayName();
                        debuggerName = StringUtil.shortenTextWithEllipsis(debuggerName, 50, 0);
                        ((ListPopupImpl) popup).setCaption(XDebuggerBundle.message("xdebugger.attach.toLocal.popup.title", debuggerName));
                    }
                };
                popup.addListSelectionListener(listener);
                // force first valueChanged event
                listener.valueChanged(new ListSelectionEvent(mainList, mainList.getMinSelectionIndex(), mainList.getMaxSelectionIndex(), false));
                popup.showCenteredInCurrentWindow(project);
            });
        }
    }.queue();
}
Also used : Task(com.intellij.openapi.progress.Task) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) Project(com.intellij.openapi.project.Project) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) XLocalAttachDebuggerProvider(com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider)

Example 15 with ListPopupImpl

use of com.intellij.ui.popup.list.ListPopupImpl 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

ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)16 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)10 Project (com.intellij.openapi.project.Project)5 PopupStep (com.intellij.openapi.ui.popup.PopupStep)5 NotNull (org.jetbrains.annotations.NotNull)4 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 PopupListElementRenderer (com.intellij.ui.popup.list.PopupListElementRenderer)3 ActionEvent (java.awt.event.ActionEvent)3 ListSelectionEvent (javax.swing.event.ListSelectionEvent)3 ListSelectionListener (javax.swing.event.ListSelectionListener)3 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 XExpression (com.intellij.xdebugger.XExpression)2 PsiElementListCellRenderer (com.intellij.ide.util.PsiElementListCellRenderer)1 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 Disposable (com.intellij.openapi.Disposable)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1