Search in sources :

Example 11 with PopupStep

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

the class ExternalJavaDocAction method showExternalJavadoc.

public static void showExternalJavadoc(PsiElement element, PsiElement originalElement, String docUrl, DataContext dataContext) {
    DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
    if (provider instanceof ExternalDocumentationHandler && ((ExternalDocumentationHandler) provider).handleExternal(element, originalElement)) {
        return;
    }
    Project project = dataContext.getData(CommonDataKeys.PROJECT);
    final Component contextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        List<String> urls;
        if (StringUtil.isEmptyOrSpaces(docUrl)) {
            urls = ReadAction.compute(() -> provider.getUrlFor(element, originalElement));
        } else {
            urls = Collections.singletonList(docUrl);
        }
        if (provider instanceof ExternalDocumentationProvider && urls != null && urls.size() > 1) {
            for (String url : urls) {
                List<String> thisUrlList = Collections.singletonList(url);
                String doc = ((ExternalDocumentationProvider) provider).fetchExternalDocumentation(project, element, thisUrlList);
                if (doc != null) {
                    urls = thisUrlList;
                    break;
                }
            }
        }
        final List<String> finalUrls = urls;
        ApplicationManager.getApplication().invokeLater(() -> {
            if (ContainerUtil.isEmpty(finalUrls)) {
                if (element != null && provider instanceof ExternalDocumentationProvider) {
                    ExternalDocumentationProvider externalDocumentationProvider = (ExternalDocumentationProvider) provider;
                    if (externalDocumentationProvider.canPromptToConfigureDocumentation(element)) {
                        externalDocumentationProvider.promptToConfigureDocumentation(element);
                    }
                }
            } else if (finalUrls.size() == 1) {
                BrowserUtil.browse(finalUrls.get(0));
            } else {
                JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>("Choose external documentation root", ArrayUtil.toStringArray(finalUrls)) {

                    @Override
                    public PopupStep onChosen(final String selectedValue, final boolean finalChoice) {
                        BrowserUtil.browse(selectedValue);
                        return FINAL_CHOICE;
                    }
                }).showInBestPositionFor(DataManager.getInstance().getDataContext(contextComponent));
            }
        }, ModalityState.NON_MODAL);
    });
}
Also used : Project(com.intellij.openapi.project.Project) ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) ExternalDocumentationHandler(com.intellij.lang.documentation.ExternalDocumentationHandler) ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 12 with PopupStep

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

the class ExportHTMLAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>(InspectionsBundle.message("inspection.action.export.popup.title"), HTML, XML) {

        @Override
        public PopupStep onChosen(final String selectedValue, final boolean finalChoice) {
            return doFinalStep(() -> exportHTML(Comparing.strEqual(selectedValue, HTML)));
        }
    });
    InspectionResultsView.showPopup(e, popup);
}
Also used : ListPopup(com.intellij.openapi.ui.popup.ListPopup) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 13 with PopupStep

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

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

the class XDebuggerSmartStepIntoHandler method doSmartStepInto.

private static <V extends XSmartStepIntoVariant> void doSmartStepInto(final XSmartStepIntoHandler<V> handler, XSourcePosition position, final XDebugSession session, Editor editor) {
    List<V> variants = handler.computeSmartStepVariants(position);
    if (variants.isEmpty()) {
        session.stepInto();
        return;
    } else if (variants.size() == 1) {
        session.smartStepInto(handler, variants.get(0));
        return;
    }
    ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<V>(handler.getPopupTitle(position), variants) {

        @Override
        public Icon getIconFor(V aValue) {
            return aValue.getIcon();
        }

        @NotNull
        @Override
        public String getTextFor(V value) {
            return value.getText();
        }

        @Override
        public PopupStep onChosen(V selectedValue, boolean finalChoice) {
            session.smartStepInto(handler, selectedValue);
            return FINAL_CHOICE;
        }
    });
    DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine());
}
Also used : ListPopup(com.intellij.openapi.ui.popup.ListPopup) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 15 with PopupStep

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

the class CopyrightProfilesPanel method createActions.

@Override
@Nullable
protected ArrayList<AnAction> createActions(boolean fromPopup) {
    ArrayList<AnAction> result = new ArrayList<>();
    result.add(new DumbAwareAction("Add", "Add", IconUtil.getAddIcon()) {

        {
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        @Override
        public void actionPerformed(AnActionEvent event) {
            String name = askForProfileName("Create Copyright Profile", "");
            if (name != null) {
                addProfileNode(new CopyrightProfile(name));
            }
        }
    });
    result.add(new MyDeleteAction());
    result.add(new DumbAwareAction("Copy", "Copy", PlatformIcons.COPY_ICON) {

        {
            registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK)), myTree);
        }

        @Override
        public void actionPerformed(AnActionEvent event) {
            String profileName = askForProfileName("Copy Copyright Profile", "");
            if (profileName == null) {
                return;
            }
            CopyrightProfile clone = new CopyrightProfile();
            clone.copyFrom((CopyrightProfile) getSelectedObject());
            clone.setName(profileName);
            addProfileNode(clone);
        }

        @Override
        public void update(AnActionEvent event) {
            super.update(event);
            event.getPresentation().setEnabled(getSelectedObject() != null);
        }
    });
    result.add(new DumbAwareAction("Import", "Import", PlatformIcons.IMPORT_ICON) {

        @Override
        public void actionPerformed(AnActionEvent event) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withFileFilter(file -> {
                final FileType fileType = file.getFileType();
                return fileType != PlainTextFileType.INSTANCE && (fileType == StdFileTypes.IDEA_MODULE || fileType == StdFileTypes.XML);
            }).withTitle("Choose File Containing Copyright Notice");
            FileChooser.chooseFile(descriptor, myProject, null, file -> {
                final List<CopyrightProfile> profiles = ExternalOptionHelper.loadOptions(VfsUtilCore.virtualToIoFile(file));
                if (profiles == null)
                    return;
                if (!profiles.isEmpty()) {
                    if (profiles.size() == 1) {
                        importProfile(profiles.get(0));
                    } else {
                        JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CopyrightProfile>("Choose profile to import", profiles) {

                            @Override
                            public PopupStep onChosen(final CopyrightProfile selectedValue, boolean finalChoice) {
                                return doFinalStep(() -> importProfile(selectedValue));
                            }

                            @NotNull
                            @Override
                            public String getTextFor(CopyrightProfile value) {
                                return value.getName();
                            }
                        }).showUnderneathOf(myNorthPanel);
                    }
                } else {
                    Messages.showWarningDialog(myProject, "The selected file does not contain any copyright settings.", "Import Failure");
                }
            });
        }

        private void importProfile(CopyrightProfile copyrightProfile) {
            final String profileName = askForProfileName("Import copyright profile", copyrightProfile.getName());
            if (profileName == null)
                return;
            copyrightProfile.setName(profileName);
            addProfileNode(copyrightProfile);
            Messages.showInfoMessage(myProject, "The copyright settings have been successfully imported.", "Import Complete");
        }
    });
    return result;
}
Also used : InputEvent(java.awt.event.InputEvent) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) java.util(java.util) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) HashMap(com.intellij.util.containers.HashMap) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) NonNls(org.jetbrains.annotations.NonNls) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CopyrightManager(com.intellij.copyright.CopyrightManager) Nls(org.jetbrains.annotations.Nls) Project(com.intellij.openapi.project.Project) MasterDetailsComponent(com.intellij.openapi.ui.MasterDetailsComponent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) PlatformIcons(com.intellij.util.PlatformIcons) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) TreePath(javax.swing.tree.TreePath) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) AnAction(com.intellij.openapi.actionSystem.AnAction) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) ExternalOptionHelper(com.maddyhome.idea.copyright.options.ExternalOptionHelper) FileType(com.intellij.openapi.fileTypes.FileType) KeyEvent(java.awt.event.KeyEvent) MasterDetailsStateService(com.intellij.openapi.ui.MasterDetailsStateService) Nullable(org.jetbrains.annotations.Nullable) CommonShortcuts(com.intellij.openapi.actionSystem.CommonShortcuts) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) InputValidator(com.intellij.openapi.ui.InputValidator) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) IconUtil(com.intellij.util.IconUtil) javax.swing(javax.swing) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) FileType(com.intellij.openapi.fileTypes.FileType) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PopupStep (com.intellij.openapi.ui.popup.PopupStep)19 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)18 NotNull (org.jetbrains.annotations.NotNull)14 ListPopup (com.intellij.openapi.ui.popup.ListPopup)7 RelativePoint (com.intellij.ui.awt.RelativePoint)6 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)5 Project (com.intellij.openapi.project.Project)4 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiFile (com.intellij.psi.PsiFile)3 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)3 Nullable (org.jetbrains.annotations.Nullable)3 AllIcons (com.intellij.icons.AllIcons)2 Editor (com.intellij.openapi.editor.Editor)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 javax.swing (javax.swing)2 HintManager (com.intellij.codeInsight.hint.HintManager)1