Search in sources :

Example 21 with JBPopup

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

the class ShowSiblingsAction method performForContext.

@Override
public void performForContext(@NotNull DataContext dataContext, final boolean invokedByShortcut) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
    if (project == null)
        return;
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    final Editor editor = getEditor(dataContext);
    PsiElement element = getElement(project, file, editor, CommonDataKeys.PSI_ELEMENT.getData(dataContext));
    if (element == null && file == null)
        return;
    PsiFile containingFile = element != null ? element.getContainingFile() : file;
    if (containingFile == null || !containingFile.getViewProvider().isPhysical())
        return;
    if (editor != null) {
        PsiReference ref = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
        if (element == null && ref != null) {
            element = TargetElementUtil.getInstance().adjustReference(ref);
        }
    }
    final PsiElement[] superElements = findSuperElements(element);
    if (superElements.length == 0)
        return;
    final boolean isMethod = superElements[0] instanceof PsiMethod;
    NavigatablePsiElement[] navigatablePsiElements = ContainerUtil.findAllAsArray(superElements, NavigatablePsiElement.class);
    final JBPopup popup = PsiElementListNavigator.navigateOrCreatePopup(navigatablePsiElements, "Choose super " + (isMethod ? "method" : "class or interface"), "Super " + (isMethod ? "methods" : "classes/interfaces"), isMethod ? new MethodCellRenderer(false) : new PsiClassListCellRenderer(), null, objects -> showSiblings(invokedByShortcut, project, editor, file, editor != null, (PsiElement) objects[0]));
    if (popup != null) {
        if (editor != null) {
            popup.showInBestPositionFor(editor);
        } else {
            popup.showCenteredInCurrentWindow(project);
        }
    }
}
Also used : MethodCellRenderer(com.intellij.ide.util.MethodCellRenderer) Project(com.intellij.openapi.project.Project) PsiClassListCellRenderer(com.intellij.ide.util.PsiClassListCellRenderer) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 22 with JBPopup

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

the class AddModuleDependencyFix method invoke.

@Override
public void invoke(@NotNull Project project, @Nullable Editor editor, PsiFile file) {
    if (myModules.size() == 1) {
        addDependencyOnModule(project, editor, ContainerUtil.getFirstItem(myModules));
    } else {
        JBList<Module> list = new JBList<>(myModules);
        list.setCellRenderer(new ModuleListCellRenderer());
        JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle(QuickFixBundle.message("orderEntry.fix.choose.module.to.add.dependency.on")).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> addDependencyOnModule(project, editor, list.getSelectedValue())).createPopup();
        if (editor != null) {
            popup.showInBestPositionFor(editor);
        } else {
            popup.showCenteredInCurrentWindow(project);
        }
    }
}
Also used : ModuleListCellRenderer(com.intellij.application.options.ModuleListCellRenderer) JBList(com.intellij.ui.components.JBList) Module(com.intellij.openapi.module.Module) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 23 with JBPopup

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

the class JavaExternalDocumentationTest method getDocumentationText.

public static String getDocumentationText(@NotNull PsiFile psiFile, int caretPosition) throws InterruptedException {
    Project project = psiFile.getProject();
    Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
    assertNotNull(document);
    Editor editor = EditorFactory.getInstance().createEditor(document, project);
    try {
        if (caretPosition >= 0) {
            editor.getCaretModel().moveToOffset(caretPosition);
        }
        DocumentationManager documentationManager = DocumentationManager.getInstance(project);
        MockDocumentationComponent documentationComponent = new MockDocumentationComponent(documentationManager);
        try {
            documentationManager.setDocumentationComponent(documentationComponent);
            documentationManager.showJavaDocInfo(editor, psiFile, false);
            waitTillDone(documentationManager.getLastAction());
            return documentationComponent.getText();
        } finally {
            JBPopup hint = documentationComponent.getHint();
            if (hint != null)
                Disposer.dispose(hint);
            Disposer.dispose(documentationComponent);
        }
    } finally {
        EditorFactory.getInstance().releaseEditor(editor);
    }
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 24 with JBPopup

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

the class FocusManagerImpl method getFocusedDescendantFor.

@Override
public Component getFocusedDescendantFor(Component comp) {
    final Component focused = getFocusOwner();
    if (focused == null)
        return null;
    if (focused == comp || SwingUtilities.isDescendingFrom(focused, comp))
        return focused;
    List<JBPopup> popups = FocusTrackback.getChildPopups(comp);
    for (JBPopup each : popups) {
        if (each.isFocused())
            return focused;
    }
    return null;
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 25 with JBPopup

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

the class StackingPopupDispatcherImpl method dispatchKeyEvent.

@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
    final boolean closeRequest = AbstractPopup.isCloseRequest(e);
    JBPopup popup = closeRequest ? findPopup() : getFocusedPopup();
    return popup != null && popup.dispatchKeyEvent(e);
}
Also used : 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