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);
}
}
}
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);
}
}
}
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);
}
}
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;
}
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);
}
Aggregations