Search in sources :

Example 71 with JBPopup

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

the class HectorComponent method showComponent.

public void showComponent(RelativePoint point) {
    final JBPopup hector = JBPopupFactory.getInstance().createComponentPopupBuilder(this, this).setRequestFocus(true).setMovable(true).setCancelCallback(() -> {
        for (HectorComponentPanel additionalPanel : myAdditionalPanels) {
            if (!additionalPanel.canClose()) {
                return Boolean.FALSE;
            }
        }
        onClose();
        return Boolean.TRUE;
    }).createPopup();
    Disposer.register(myFile.getProject(), new Disposable() {

        @Override
        public void dispose() {
            final JBPopup oldHector = getOldHector();
            if (oldHector != null && !oldHector.isDisposed()) {
                Disposer.dispose(oldHector);
            }
            Disposer.dispose(hector);
        }
    });
    final JBPopup oldHector = getOldHector();
    if (oldHector != null) {
        oldHector.cancel();
    } else {
        myHectorRef = new WeakReference<>(hector);
        hector.show(point);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) HectorComponentPanel(com.intellij.openapi.editor.HectorComponentPanel) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 72 with JBPopup

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

the class DocumentationManager method showInPopup.

private void showInPopup(@NotNull final PsiElement element, boolean requestFocus, PopupUpdateProcessor updateProcessor, final PsiElement originalElement, @Nullable final Runnable closeCallback) {
    final DocumentationComponent component = myTestDocumentationComponent == null ? new DocumentationComponent(this) : myTestDocumentationComponent;
    component.setNavigateCallback(psiElement -> {
        final AbstractPopup jbPopup = (AbstractPopup) getDocInfoHint();
        if (jbPopup != null) {
            final String title = getTitle(psiElement, false);
            jbPopup.setCaption(title);
            AccessibleContextUtil.setName(component, title);
        }
    });
    Processor<JBPopup> pinCallback = popup -> {
        createToolWindow(element, originalElement);
        myToolWindow.setAutoHide(false);
        popup.cancel();
        return false;
    };
    ActionListener actionListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            createToolWindow(element, originalElement);
            final JBPopup hint = getDocInfoHint();
            if (hint != null && hint.isVisible())
                hint.cancel();
        }
    };
    List<Pair<ActionListener, KeyStroke>> actions = ContainerUtil.newSmartList();
    AnAction quickDocAction = ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_JAVADOC);
    for (Shortcut shortcut : quickDocAction.getShortcutSet().getShortcuts()) {
        if (!(shortcut instanceof KeyboardShortcut))
            continue;
        actions.add(Pair.create(actionListener, ((KeyboardShortcut) shortcut).getFirstKeyStroke()));
    }
    boolean hasLookup = LookupManager.getActiveLookup(myEditor) != null;
    final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component).setProject(element.getProject()).addListener(updateProcessor).addUserData(updateProcessor).setKeyboardActions(actions).setDimensionServiceKey(myProject, JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(requestFocus).setCancelOnClickOutside(// otherwise selecting lookup items by mouse would close the doc
    !hasLookup).setTitle(getTitle(element, false)).setCouldPin(pinCallback).setModalContext(false).setCancelCallback(() -> {
        myCloseOnSneeze = false;
        if (closeCallback != null) {
            closeCallback.run();
        }
        if (fromQuickSearch()) {
            ((ChooseByNameBase.JPanelProvider) myPreviouslyFocused.getParent()).unregisterHint();
        }
        Disposer.dispose(component);
        myEditor = null;
        myPreviouslyFocused = null;
        return Boolean.TRUE;
    }).setKeyEventHandler(e -> {
        if (myCloseOnSneeze) {
            closeDocHint();
        }
        if (AbstractPopup.isCloseRequest(e) && getDocInfoHint() != null) {
            closeDocHint();
            return true;
        }
        return false;
    }).createPopup();
    component.setHint(hint);
    if (myEditor == null) {
        // subsequent invocation of javadoc popup from completion will have myEditor == null because of cancel invoked, 
        // so reevaluate the editor for proper popup placement
        Lookup lookup = LookupManager.getInstance(myProject).getActiveLookup();
        myEditor = lookup != null ? lookup.getEditor() : null;
    }
    fetchDocInfo(getDefaultCollector(element, originalElement), component);
    myDocInfoHintRef = new WeakReference<>(hint);
    if (fromQuickSearch() && myPreviouslyFocused != null) {
        ((ChooseByNameBase.JPanelProvider) myPreviouslyFocused.getParent()).registerHint(hint);
    }
}
Also used : Language(com.intellij.lang.Language) com.intellij.openapi.util(com.intellij.openapi.util) AccessibleContextUtil(com.intellij.util.ui.accessibility.AccessibleContextUtil) BaseNavigateToSourceAction(com.intellij.ide.actions.BaseNavigateToSourceAction) Lookup(com.intellij.codeInsight.lookup.Lookup) VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.lang.documentation(com.intellij.lang.documentation) ModalityState(com.intellij.openapi.application.ModalityState) ProjectSettingsService(com.intellij.openapi.roots.ui.configuration.ProjectSettingsService) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) ShowQuickDocInfoAction(com.intellij.codeInsight.documentation.actions.ShowQuickDocInfoAction) Logger(com.intellij.openapi.diagnostic.Logger) Extensions(com.intellij.openapi.extensions.Extensions) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) ScrollingUtil(com.intellij.ui.ScrollingUtil) ParameterInfoController(com.intellij.codeInsight.hint.ParameterInfoController) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) LookupManager(com.intellij.codeInsight.lookup.LookupManager) PreviewManager(com.intellij.openapi.preview.PreviewManager) OrderEntry(com.intellij.openapi.roots.OrderEntry) Content(com.intellij.ui.content.Content) AbstractPopup(com.intellij.ui.popup.AbstractPopup) LookupEx(com.intellij.codeInsight.lookup.LookupEx) BrowserUtil(com.intellij.ide.BrowserUtil) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IdeFocusManager.getGlobalInstance(com.intellij.openapi.wm.IdeFocusManager.getGlobalInstance) com.intellij.psi(com.intellij.psi) WindowManagerEx(com.intellij.openapi.wm.ex.WindowManagerEx) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) ActionListener(java.awt.event.ActionListener) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) PopupUpdateProcessor(com.intellij.ui.popup.PopupUpdateProcessor) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) ToolWindowId(com.intellij.openapi.wm.ToolWindowId) Project(com.intellij.openapi.project.Project) PopupPositionManager(com.intellij.ui.popup.PopupPositionManager) WeakReference(java.lang.ref.WeakReference) DataManager(com.intellij.ide.DataManager) LibraryUtil(com.intellij.openapi.roots.libraries.LibraryUtil) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ChooseByNameBase(com.intellij.ide.util.gotoByName.ChooseByNameBase) Editor(com.intellij.openapi.editor.Editor) ActionEvent(java.awt.event.ActionEvent) JBPopup(com.intellij.openapi.ui.popup.JBPopup) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) LanguageDocumentation(com.intellij.lang.LanguageDocumentation) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) CommandProcessor(com.intellij.openapi.command.CommandProcessor) SymbolPresentationUtil(com.intellij.psi.presentation.java.SymbolPresentationUtil) HintManagerImpl(com.intellij.codeInsight.hint.HintManagerImpl) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) AbstractPopup(com.intellij.ui.popup.AbstractPopup) ActionEvent(java.awt.event.ActionEvent) ActionListener(java.awt.event.ActionListener) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) Lookup(com.intellij.codeInsight.lookup.Lookup) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 73 with JBPopup

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

the class HighlightImportedElementsHandler method selectTargets.

@Override
protected void selectTargets(final List<PsiMember> targets, final Consumer<List<PsiMember>> selectionConsumer) {
    if (targets.isEmpty()) {
        selectionConsumer.consume(Collections.<PsiMember>emptyList());
        return;
    }
    if (targets.size() == 1) {
        selectionConsumer.consume(Collections.singletonList(targets.get(0)));
        return;
    }
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        selectionConsumer.consume(targets);
        return;
    }
    Collections.sort(targets, new PsiMemberComparator());
    final List<Object> model = new ArrayList<>();
    model.add(CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"));
    model.addAll(targets);
    final JList list = new JBList(model);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final ListCellRenderer renderer = new NavigationItemListCellRenderer();
    list.setCellRenderer(renderer);
    final PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setFilteringEnabled(o -> {
        if (o instanceof PsiMember) {
            final PsiMember member = (PsiMember) o;
            return member.getName();
        }
        return o.toString();
    });
    if (myImportStatic) {
        builder.setTitle(CodeInsightBundle.message("highlight.imported.members.chooser.title"));
    } else {
        builder.setTitle(CodeInsightBundle.message("highlight.imported.classes.chooser.title"));
    }
    builder.setItemChoosenCallback(() -> {
        final int index = list.getSelectedIndex();
        if (index == 0) {
            selectionConsumer.consume(targets);
        } else {
            selectionConsumer.consume(Collections.singletonList(targets.get(index - 1)));
        }
    });
    final JBPopup popup = builder.createPopup();
    popup.showInBestPositionFor(myEditor);
}
Also used : NavigationItemListCellRenderer(com.intellij.ide.util.NavigationItemListCellRenderer) NavigationItemListCellRenderer(com.intellij.ide.util.NavigationItemListCellRenderer) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 74 with JBPopup

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

the class GotoSuperActionHandler method invoke.

@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed(GotoSuperAction.FEATURE_ID);
    PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
    if (element == null)
        return;
    @SuppressWarnings("unchecked") KtDeclaration declaration = PsiTreeUtil.getParentOfType(element, KtNamedFunction.class, KtClass.class, KtProperty.class, KtObjectDeclaration.class);
    if (declaration == null)
        return;
    DeclarationDescriptor descriptor = ResolutionUtils.resolveToDescriptor(declaration, BodyResolveMode.PARTIAL);
    List<PsiElement> superDeclarations = findSuperDeclarations(descriptor);
    if (superDeclarations == null || superDeclarations.isEmpty())
        return;
    if (superDeclarations.size() == 1) {
        Navigatable navigatable = EditSourceUtil.getDescriptor(superDeclarations.get(0));
        if (navigatable != null && navigatable.canNavigate()) {
            navigatable.navigate(true);
        }
    } else {
        String message = getTitle(descriptor);
        PsiElement[] superDeclarationsArray = PsiUtilCore.toPsiElementArray(superDeclarations);
        JBPopup popup = descriptor instanceof ClassDescriptor ? NavigationUtil.getPsiElementPopup(superDeclarationsArray, message) : NavigationUtil.getPsiElementPopup(superDeclarationsArray, new KtFunctionPsiElementCellRenderer(), message);
        popup.showInBestPositionFor(editor);
    }
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) Navigatable(com.intellij.pom.Navigatable)

Example 75 with JBPopup

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

the class NavigationGutterIconRenderer method navigate.

@Override
public void navigate(@Nullable final MouseEvent event, @Nullable final PsiElement elt) {
    final List<PsiElement> list;
    DumbService dumbService = elt != null ? DumbService.getInstance(elt.getProject()) : null;
    if (dumbService != null)
        dumbService.setAlternativeResolveEnabled(true);
    try {
        list = getTargetElements();
    } finally {
        if (dumbService != null)
            dumbService.setAlternativeResolveEnabled(false);
    }
    if (list.isEmpty()) {
        if (myEmptyText != null) {
            if (event != null) {
                final JComponent label = HintUtil.createErrorLabel(myEmptyText);
                label.setBorder(IdeBorderFactory.createEmptyBorder(2, 7, 2, 7));
                JBPopupFactory.getInstance().createBalloonBuilder(label).setFadeoutTime(3000).setFillColor(HintUtil.getErrorColor()).createBalloon().show(new RelativePoint(event), Balloon.Position.above);
            }
        }
        return;
    }
    if (list.size() == 1) {
        PsiNavigateUtil.navigate(list.iterator().next());
    } else {
        if (event != null) {
            final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilCore.toPsiElementArray(list), myCellRenderer.compute(), myPopupTitle);
            popup.show(new RelativePoint(event));
        }
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup) DumbService(com.intellij.openapi.project.DumbService) PsiElement(com.intellij.psi.PsiElement)

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