Search in sources :

Example 56 with JBPopup

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

the class PerFileConfigurableBase method createValueAction.

@NotNull
protected final AnAction createValueAction(@Nullable Object target, @NotNull Value<T> value) {
    return new ComboBoxAction() {

        void updateText() {
            String text = renderValue(value.get(), StringUtil.notNullize(getNullValueText(target)));
            getTemplatePresentation().setText(StringUtil.shortenTextWithEllipsis(text, 40, 0));
        }

        @Override
        public void update(AnActionEvent e) {
            updateText();
        }

        @NotNull
        @Override
        protected DefaultActionGroup createPopupActionGroup(JComponent button) {
            throw new UnsupportedOperationException();
        }

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

                protected JBPopup createPopup(Runnable onDispose) {
                    JBPopup popup = createValueEditorPopup(target, value.get(), onDispose, getDataContext(), o -> {
                        value.set(o);
                        updateText();
                    }, value::commit);
                    popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight()));
                    return popup;
                }

                @Nullable
                @Override
                public String getToolTipText() {
                    boolean cellEditor = UIUtil.uiParents(this, true).take(4).filter(JBTable.class).first() != null;
                    return cellEditor ? null : getToolTipFor(value.get());
                }
            };
        }
    };
}
Also used : ComboBoxAction(com.intellij.openapi.actionSystem.ex.ComboBoxAction) JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with JBPopup

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

the class MultipleFilesHyperlinkInfo method navigate.

@Override
public void navigate(@NotNull final Project project, @Nullable RelativePoint hyperlinkLocationPoint) {
    List<PsiFile> currentFiles = new ArrayList<>();
    AccessToken accessToken = ReadAction.start();
    try {
        for (VirtualFile file : myVirtualFiles) {
            if (!file.isValid())
                continue;
            PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
            if (psiFile != null) {
                // Sources may be downloaded.
                PsiElement navigationElement = psiFile.getNavigationElement();
                if (navigationElement instanceof PsiFile) {
                    currentFiles.add((PsiFile) navigationElement);
                    continue;
                }
                currentFiles.add(psiFile);
            }
        }
    } finally {
        accessToken.finish();
    }
    if (currentFiles.isEmpty())
        return;
    if (currentFiles.size() == 1) {
        new OpenFileHyperlinkInfo(myProject, currentFiles.get(0).getVirtualFile(), myLineNumber).navigate(project);
    } else {
        final JBList list = new JBList(currentFiles);
        int width = WindowManager.getInstance().getFrame(project).getSize().width;
        list.setCellRenderer(new GotoFileCellRenderer(width));
        JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Target File").setItemChoosenCallback(() -> {
            VirtualFile file = ((PsiFile) list.getSelectedValue()).getVirtualFile();
            new OpenFileHyperlinkInfo(myProject, file, myLineNumber).navigate(project);
        }).createPopup();
        if (hyperlinkLocationPoint != null) {
            popup.show(hyperlinkLocationPoint);
        } else {
            popup.showInFocusCenter();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) GotoFileCellRenderer(com.intellij.ide.util.gotoByName.GotoFileCellRenderer) AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) JBList(com.intellij.ui.components.JBList) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 58 with JBPopup

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

Example 59 with JBPopup

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

the class DocumentationManager method closeDocHint.

private void closeDocHint() {
    JBPopup hint = getDocInfoHint();
    if (hint == null) {
        return;
    }
    myCloseOnSneeze = false;
    hint.cancel();
    Component toFocus = myPreviouslyFocused;
    hint.cancel();
    if (toFocus != null) {
        IdeFocusManager.getInstance(myProject).requestFocus(toFocus, true);
    }
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 60 with JBPopup

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

the class QuickDocOnMouseOverManager method processMouseMove.

private void processMouseMove(@NotNull EditorMouseEvent e) {
    if (!myApplicationActive || !myEnabled || e.getArea() != EditorMouseEventArea.EDITING_AREA) {
        // Skip if the mouse is not at the editing area.
        closeQuickDocIfPossible();
        return;
    }
    if (e.getMouseEvent().getModifiers() != 0) {
        // wants to navigate via Ctrl+click or perform quick evaluate by Alt+click.
        return;
    }
    Editor editor = e.getEditor();
    if (editor.getComponent().getClientProperty(EditorImpl.IGNORE_MOUSE_TRACKING) != null) {
        return;
    }
    if (editor.isOneLineMode()) {
        // Don't want auto quick doc to mess at, say, editor used for debugger condition.
        return;
    }
    Project project = editor.getProject();
    if (project == null) {
        return;
    }
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    JBPopup hint = documentationManager.getDocInfoHint();
    if (hint != null) {
        // Skip the event if the control is shown because of explicit 'show quick doc' action call.
        DocumentationManager manager = getDocManager();
        if (manager == null || !manager.isCloseOnSneeze()) {
            return;
        }
        // Skip the event if the mouse is under the opened quick doc control.
        Point hintLocation = hint.getLocationOnScreen();
        Dimension hintSize = hint.getSize();
        int mouseX = e.getMouseEvent().getXOnScreen();
        int mouseY = e.getMouseEvent().getYOnScreen();
        if (mouseX >= hintLocation.x && mouseX <= hintLocation.x + hintSize.width && mouseY >= hintLocation.y && mouseY <= hintLocation.y + hintSize.height) {
            return;
        }
    }
    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (psiFile == null) {
        closeQuickDocIfPossible();
        return;
    }
    Point point = e.getMouseEvent().getPoint();
    if (editor instanceof EditorEx && ((EditorEx) editor).getFoldingModel().getFoldingPlaceholderAt(point) != null) {
        closeQuickDocIfPossible();
        return;
    }
    VisualPosition visualPosition = editor.xyToVisualPosition(point);
    if (editor.getSoftWrapModel().isInsideOrBeforeSoftWrap(visualPosition)) {
        closeQuickDocIfPossible();
        return;
    }
    int mouseOffset = editor.logicalPositionToOffset(editor.visualToLogicalPosition(visualPosition));
    PsiElement elementUnderMouse = psiFile.findElementAt(mouseOffset);
    if (elementUnderMouse == null || elementUnderMouse instanceof PsiWhiteSpace || elementUnderMouse instanceof PsiPlainText) {
        closeQuickDocIfPossible();
        return;
    }
    if (elementUnderMouse.equals(SoftReference.dereference(myActiveElements.get(editor))) && (// Request to show documentation for the target component has been already queued.
    !myAlarm.isEmpty() || // Documentation for the target component is being shown.
    hint != null)) {
        return;
    }
    allowUpdateFromContext(project, false);
    closeQuickDocIfPossible();
    myActiveElements.put(editor, new WeakReference<>(elementUnderMouse));
    myAlarm.cancelAllRequests();
    if (myCurrentRequest != null)
        myCurrentRequest.cancel();
    myCurrentRequest = new MyShowQuickDocRequest(documentationManager, editor, mouseOffset, elementUnderMouse);
    myAlarm.addRequest(myCurrentRequest, EditorSettingsExternalizable.getInstance().getQuickDocOnMouseOverElementDelayMillis());
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Project(com.intellij.openapi.project.Project) VisualPosition(com.intellij.openapi.editor.VisualPosition) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Aggregations

JBPopup (com.intellij.openapi.ui.popup.JBPopup)76 Project (com.intellij.openapi.project.Project)21 NotNull (org.jetbrains.annotations.NotNull)20 RelativePoint (com.intellij.ui.awt.RelativePoint)19 JBList (com.intellij.ui.components.JBList)18 PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)15 Editor (com.intellij.openapi.editor.Editor)13 PsiElement (com.intellij.psi.PsiElement)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Nullable (org.jetbrains.annotations.Nullable)8 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)7 Ref (com.intellij.openapi.util.Ref)7 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)6 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)6 AbstractPopup (com.intellij.ui.popup.AbstractPopup)6 ActionEvent (java.awt.event.ActionEvent)6 List (java.util.List)6 javax.swing (javax.swing)6 Disposable (com.intellij.openapi.Disposable)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)5