use of com.intellij.ui.popup.PopupUpdateProcessor in project intellij-community by JetBrains.
the class ShowImplementationsAction method showImplementations.
protected void showImplementations(@NotNull PsiElement[] impls, @NotNull final Project project, final String text, final Editor editor, final PsiFile file, final PsiElement element, boolean invokedFromEditor, boolean invokedByShortcut) {
if (impls.length == 0)
return;
FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKDEFINITION_FEATURE);
if (LookupManager.getInstance(project).getActiveLookup() != null) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKDEFINITION_LOOKUP_FEATURE);
}
int index = 0;
if (invokedFromEditor && file != null && impls.length > 1) {
final VirtualFile virtualFile = file.getVirtualFile();
final PsiFile containingFile = impls[0].getContainingFile();
if (virtualFile != null && containingFile != null && virtualFile.equals(containingFile.getVirtualFile())) {
final PsiFile secondContainingFile = impls[1].getContainingFile();
if (secondContainingFile != containingFile) {
index = 1;
}
}
}
final Ref<UsageView> usageView = new Ref<>();
final String title = CodeInsightBundle.message("implementation.view.title", text);
JBPopup popup = SoftReference.dereference(myPopupRef);
if (popup != null && popup.isVisible() && popup instanceof AbstractPopup) {
final ImplementationViewComponent component = (ImplementationViewComponent) ((AbstractPopup) popup).getComponent();
((AbstractPopup) popup).setCaption(title);
component.update(impls, index);
updateInBackground(editor, element, component, title, (AbstractPopup) popup, usageView);
if (invokedByShortcut) {
((AbstractPopup) popup).focusPreferredComponent();
}
return;
}
final ImplementationViewComponent component = new ImplementationViewComponent(impls, index);
if (component.hasElementsToShow()) {
final PopupUpdateProcessor updateProcessor = new PopupUpdateProcessor(project) {
@Override
public void updatePopup(Object lookupItemObject) {
final PsiElement element = lookupItemObject instanceof PsiElement ? (PsiElement) lookupItemObject : DocumentationManager.getInstance(project).getElementFromLookup(editor, file);
updateElementImplementations(element, editor, project, file);
}
};
popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()).setProject(project).addListener(updateProcessor).addUserData(updateProcessor).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(invokedFromEditor && LookupManager.getActiveLookup(editor) == null).setTitle(title).setCouldPin(popup1 -> {
usageView.set(component.showInUsageView());
popup1.cancel();
myTaskRef = null;
return false;
}).setCancelCallback(() -> {
ImplementationsUpdaterTask task = SoftReference.dereference(myTaskRef);
if (task != null) {
task.cancelTask();
}
return Boolean.TRUE;
}).createPopup();
updateInBackground(editor, element, component, title, (AbstractPopup) popup, usageView);
PopupPositionManager.positionPopupInBestPosition(popup, editor, DataManager.getInstance().getDataContext());
component.setHint(popup, title);
myPopupRef = new WeakReference<>(popup);
}
}
use of com.intellij.ui.popup.PopupUpdateProcessor in project intellij-community by JetBrains.
the class DocumentationManager method showJavaDocInfo.
public void showJavaDocInfo(final Editor editor, @Nullable final PsiFile file, boolean requestFocus, @Nullable final Runnable closeCallback) {
myEditor = editor;
final Project project = getProject(file);
PsiDocumentManager.getInstance(project).commitAllDocuments();
final PsiElement list = ParameterInfoController.findArgumentList(file, editor.getCaretModel().getOffset(), -1);
PsiElement expressionList = null;
if (list != null) {
LookupEx lookup = LookupManager.getInstance(myProject).getActiveLookup();
if (lookup != null) {
// take completion variants for documentation then
expressionList = null;
} else {
expressionList = list;
}
}
final PsiElement originalElement = getContextElement(editor, file);
PsiElement element = assertSameProject(findTargetElement(editor, file));
if (element == null && expressionList != null) {
element = expressionList;
}
//file == null for text field editor
if (element == null && file == null)
return;
if (element == null) {
// look if we are within a javadoc comment
element = assertSameProject(originalElement);
if (element == null)
return;
PsiComment comment = PsiTreeUtil.getParentOfType(element, PsiComment.class);
if (comment == null)
return;
element = comment instanceof PsiDocCommentBase ? ((PsiDocCommentBase) comment).getOwner() : comment.getParent();
if (element == null)
return;
//if (!(element instanceof PsiDocCommentOwner)) return null;
}
final PopupUpdateProcessor updateProcessor = new PopupUpdateProcessor(project) {
@Override
public void updatePopup(Object lookupIteObject) {
if (lookupIteObject == null) {
return;
}
if (lookupIteObject instanceof PsiElement) {
doShowJavaDocInfo((PsiElement) lookupIteObject, false, this, originalElement, closeCallback);
return;
}
DocumentationProvider documentationProvider = getProviderFromElement(file);
PsiElement element = documentationProvider.getDocumentationElementForLookupItem(PsiManager.getInstance(myProject), lookupIteObject, originalElement);
if (element == null)
return;
if (myEditor != null) {
final PsiFile file = element.getContainingFile();
if (file != null) {
Editor editor = myEditor;
showJavaDocInfo(myEditor, file, false);
myEditor = editor;
}
} else {
doShowJavaDocInfo(element, false, this, originalElement, closeCallback);
}
}
};
doShowJavaDocInfo(element, requestFocus, updateProcessor, originalElement, closeCallback);
}
use of com.intellij.ui.popup.PopupUpdateProcessor 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);
}
}
use of com.intellij.ui.popup.PopupUpdateProcessor in project intellij-community by JetBrains.
the class DocumentationManager method showJavaDocInfo.
public void showJavaDocInfo(@NotNull final PsiElement element, final PsiElement original, final boolean requestFocus, @Nullable Runnable closeCallback) {
if (!element.isValid()) {
return;
}
PopupUpdateProcessor updateProcessor = new PopupUpdateProcessor(element.getProject()) {
@Override
public void updatePopup(Object lookupItemObject) {
if (lookupItemObject instanceof PsiElement) {
doShowJavaDocInfo((PsiElement) lookupItemObject, requestFocus, this, original, null);
}
}
};
doShowJavaDocInfo(element, requestFocus, updateProcessor, original, closeCallback);
}
use of com.intellij.ui.popup.PopupUpdateProcessor in project intellij-community by JetBrains.
the class FileStructurePopup method show.
public void show() {
//final long time = System.currentTimeMillis();
JComponent panel = createCenterPanel();
MnemonicHelper.init(panel);
myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null).setTitle(myTitle).setResizable(true).setModalContext(false).setFocusable(true).setRequestFocus(true).setMovable(true).setBelongsToGlobalPopupStack(true).setCancelKeyEnabled(false).setDimensionServiceKey(null, getDimensionServiceKey(), true).setCancelCallback(() -> myCanClose).createPopup();
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (myPopup.isVisible()) {
final PopupUpdateProcessor updateProcessor = myPopup.getUserData(PopupUpdateProcessor.class);
if (updateProcessor != null) {
final AbstractTreeNode node = getSelectedNode();
updateProcessor.updatePopup(node);
}
}
}
});
Disposer.register(myPopup, this);
Disposer.register(myPopup, new Disposable() {
@Override
public void dispose() {
if (!myTreeHasBuilt.isDone()) {
myTreeHasBuilt.setRejected();
}
}
});
myTree.getEmptyText().setText("Loading...");
myPopup.showCenteredInCurrentWindow(myProject);
((AbstractPopup) myPopup).setShowHints(true);
IdeFocusManager.getInstance(myProject).requestFocus(myTree, true);
Window window = SwingUtilities.windowForComponent(myPopup.getContent());
WindowFocusListener windowFocusListener = new WindowFocusListener() {
@Override
public void windowGainedFocus(WindowEvent e) {
}
@Override
public void windowLostFocus(WindowEvent e) {
myPopup.cancel();
}
};
window.addWindowFocusListener(windowFocusListener);
Disposer.register(myPopup, () -> window.removeWindowFocusListener(windowFocusListener));
ApplicationManager.getApplication().executeOnPooledThread(() -> {
ApplicationManager.getApplication().runReadAction(() -> myFilteringStructure.rebuild());
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
myAbstractTreeBuilder.queueUpdate().doWhenDone(() -> {
myTreeHasBuilt.setDone();
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
if (myAbstractTreeBuilder.isDisposed())
return;
if (selectPsiElement(myInitialPsiElement) == null) {
TreeUtil.ensureSelection(myAbstractTreeBuilder.getTree());
myAbstractTreeBuilder.revalidateTree();
}
});
});
installUpdater();
});
});
}
Aggregations