use of com.intellij.ui.popup.AbstractPopup 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.AbstractPopup in project intellij-community by JetBrains.
the class DocumentationManager method doFetchDocInfo.
private ActionCallback doFetchDocInfo(final DocumentationComponent component, final DocumentationCollector provider, final boolean cancelRequests, final boolean clearHistory) {
final ActionCallback callback = new ActionCallback();
myLastAction = callback;
boolean wasEmpty = component.isEmpty();
component.startWait();
if (cancelRequests) {
myUpdateDocAlarm.cancelAllRequests();
}
if (wasEmpty) {
component.setText(CodeInsightBundle.message("javadoc.fetching.progress"), null, clearHistory);
final AbstractPopup jbPopup = (AbstractPopup) getDocInfoHint();
if (jbPopup != null) {
jbPopup.setDimensionServiceKey(null);
}
}
ModalityState modality = ModalityState.defaultModalityState();
myUpdateDocAlarm.addRequest(() -> {
if (myProject.isDisposed())
return;
LOG.debug("Started fetching documentation...");
final Throwable[] ex = new Throwable[1];
String text = null;
try {
text = provider.getDocumentation();
} catch (Throwable e) {
LOG.info(e);
ex[0] = e;
}
if (ex[0] != null) {
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
String message = ex[0] instanceof IndexNotReadyException ? "Documentation is not available until indices are built." : CodeInsightBundle.message("javadoc.external.fetch.error.message");
component.setText(message, null, true);
callback.setDone();
});
return;
}
LOG.debug("Documentation fetched successfully:\n", text);
final PsiElement element = ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
@Override
@Nullable
public PsiElement compute() {
return provider.getElement();
}
});
if (element == null) {
LOG.debug("Element for which documentation was requested is not available anymore");
return;
}
final String documentationText = text;
PsiDocumentManager.getInstance(myProject).performLaterWhenAllCommitted(() -> {
if (!element.isValid()) {
LOG.debug("Element for which documentation was requested is not valid");
callback.setDone();
return;
}
if (documentationText == null) {
component.setText(CodeInsightBundle.message("no.documentation.found"), element, true, clearHistory);
} else if (documentationText.isEmpty()) {
component.setText(component.getText(), element, true, clearHistory);
} else {
component.setData(element, documentationText, clearHistory, provider.getEffectiveExternalUrl(), provider.getRef());
}
final AbstractPopup jbPopup = (AbstractPopup) getDocInfoHint();
if (jbPopup == null) {
callback.setDone();
return;
}
jbPopup.setDimensionServiceKey(JAVADOC_LOCATION_AND_SIZE);
jbPopup.setCaption(getTitle(element, false));
// Set panel name so that it is announced by readers when it gets the focus
AccessibleContextUtil.setName(component, getTitle(element, false));
callback.setDone();
}, modality);
}, 10);
return callback;
}
use of com.intellij.ui.popup.AbstractPopup in project intellij-community by JetBrains.
the class ShowUsagesAction method rebuildTable.
private void rebuildTable(@NotNull final UsageViewImpl usageView, @NotNull final List<Usage> usages, @NotNull List<UsageNode> nodes, @NotNull final JTable table, @Nullable final JBPopup popup, @NotNull final UsageViewPresentation presentation, @NotNull final RelativePoint popupPosition, boolean findUsagesInProgress, @NotNull AtomicInteger outOfScopeUsages, @NotNull SearchScope searchScope) {
ApplicationManager.getApplication().assertIsDispatchThread();
boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR);
if (shouldShowMoreSeparator) {
nodes.add(MORE_USAGES_SEPARATOR_NODE);
}
boolean hasOutsideScopeUsages = usages.contains(USAGES_OUTSIDE_SCOPE_SEPARATOR);
if (hasOutsideScopeUsages && !shouldShowMoreSeparator) {
nodes.add(USAGES_OUTSIDE_SCOPE_NODE);
}
String title = presentation.getTabText();
String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator || hasOutsideScopeUsages, nodes.size() - (shouldShowMoreSeparator || hasOutsideScopeUsages ? 1 : 0), findUsagesInProgress);
if (popup != null) {
((AbstractPopup) popup).setCaption(fullTitle);
}
List<UsageNode> data = collectData(usages, nodes, usageView, presentation);
MyModel tableModel = setTableModel(table, usageView, data, outOfScopeUsages, searchScope);
List<UsageNode> existingData = tableModel.getItems();
int row = table.getSelectedRow();
int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row);
if (newSelection < 0 || newSelection >= tableModel.getRowCount()) {
ScrollingUtil.ensureSelectionExists(table);
newSelection = table.getSelectedRow();
} else {
// do not pre-select the usage under caret by default
if (newSelection == 0 && table.getModel().getRowCount() > 1) {
Object valueInTopRow = table.getModel().getValueAt(0, 0);
if (valueInTopRow instanceof UsageNode && usageView.isOriginUsage(((UsageNode) valueInTopRow).getUsage())) {
newSelection++;
}
}
table.getSelectionModel().setSelectionInterval(newSelection, newSelection);
}
ScrollingUtil.ensureIndexIsVisible(table, newSelection, 0);
if (popup != null) {
setSizeAndDimensions(table, popup, popupPosition, data);
}
}
use of com.intellij.ui.popup.AbstractPopup in project intellij-community by JetBrains.
the class QuickDocUtil method getActiveDocComponent.
@Nullable
public static DocumentationComponent getActiveDocComponent(@NotNull Project project) {
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
DocumentationComponent component;
JBPopup hint = documentationManager.getDocInfoHint();
if (hint != null) {
component = (DocumentationComponent) ((AbstractPopup) hint).getComponent();
} else if (documentationManager.hasActiveDockedDocWindow()) {
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.DOCUMENTATION);
Content selectedContent = toolWindow == null ? null : toolWindow.getContentManager().getSelectedContent();
component = selectedContent == null ? null : (DocumentationComponent) selectedContent.getComponent();
} else {
component = null;
}
return component;
}
use of com.intellij.ui.popup.AbstractPopup 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