use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class PerFileConfigurableBase method createValueAction.
@NotNull
protected final AnAction createValueAction(@Nullable Object target, @NotNull Value<T> value) {
return new ComboBoxAction() {
void updateText() {
String text = renderValue(value.get(), StringUtil.notNullize(getNullValueText(target)));
getTemplatePresentation().setText(StringUtil.shortenTextWithEllipsis(text, 40, 0));
}
@Override
public void update(AnActionEvent e) {
updateText();
}
@NotNull
@Override
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
throw new UnsupportedOperationException();
}
@Override
protected ComboBoxButton createComboBoxButton(Presentation presentation) {
return new ComboBoxButton(presentation) {
protected JBPopup createPopup(Runnable onDispose) {
JBPopup popup = createValueEditorPopup(target, value.get(), onDispose, getDataContext(), o -> {
value.set(o);
updateText();
}, value::commit);
popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight()));
return popup;
}
@Nullable
@Override
public String getToolTipText() {
boolean cellEditor = UIUtil.uiParents(this, true).take(4).filter(JBTable.class).first() != null;
return cellEditor ? null : getToolTipFor(value.get());
}
};
}
};
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class MultipleFilesHyperlinkInfo method navigate.
@Override
public void navigate(@NotNull final Project project, @Nullable RelativePoint hyperlinkLocationPoint) {
List<PsiFile> currentFiles = new ArrayList<>();
AccessToken accessToken = ReadAction.start();
try {
for (VirtualFile file : myVirtualFiles) {
if (!file.isValid())
continue;
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile != null) {
// Sources may be downloaded.
PsiElement navigationElement = psiFile.getNavigationElement();
if (navigationElement instanceof PsiFile) {
currentFiles.add((PsiFile) navigationElement);
continue;
}
currentFiles.add(psiFile);
}
}
} finally {
accessToken.finish();
}
if (currentFiles.isEmpty())
return;
if (currentFiles.size() == 1) {
new OpenFileHyperlinkInfo(myProject, currentFiles.get(0).getVirtualFile(), myLineNumber).navigate(project);
} else {
final JBList list = new JBList(currentFiles);
int width = WindowManager.getInstance().getFrame(project).getSize().width;
list.setCellRenderer(new GotoFileCellRenderer(width));
JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Target File").setItemChoosenCallback(() -> {
VirtualFile file = ((PsiFile) list.getSelectedValue()).getVirtualFile();
new OpenFileHyperlinkInfo(myProject, file, myLineNumber).navigate(project);
}).createPopup();
if (hyperlinkLocationPoint != null) {
popup.show(hyperlinkLocationPoint);
} else {
popup.showInFocusCenter();
}
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class NavigationUtil method getPsiElementPopup.
@NotNull
public static <T extends PsiElement> JBPopup getPsiElementPopup(@NotNull T[] elements, @NotNull final PsiElementListCellRenderer<T> renderer, @Nullable final String title, @NotNull final PsiElementProcessor<T> processor, @Nullable final T selection) {
assert elements.length > 0 : "Attempted to show a navigation popup with zero elements";
final JList list = new JBList(elements);
HintUpdateSupply.installSimpleHintUpdateSupply(list);
list.setCellRenderer(renderer);
list.setFont(EditorUtil.getEditorFont());
if (selection != null) {
list.setSelectedValue(selection, true);
}
final Runnable runnable = () -> {
int[] ids = list.getSelectedIndices();
if (ids == null || ids.length == 0)
return;
for (Object element : list.getSelectedValues()) {
if (element != null) {
processor.execute((T) element);
}
}
};
PopupChooserBuilder builder = new PopupChooserBuilder(list);
if (title != null) {
builder.setTitle(title);
}
renderer.installSpeedSearch(builder, true);
JBPopup popup = builder.setItemChoosenCallback(runnable).createPopup();
builder.getScrollPane().setBorder(null);
builder.getScrollPane().setViewportBorder(null);
hidePopupIfDumbModeStarts(popup, elements[0].getProject());
return popup;
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class DocumentationManager method closeDocHint.
private void closeDocHint() {
JBPopup hint = getDocInfoHint();
if (hint == null) {
return;
}
myCloseOnSneeze = false;
hint.cancel();
Component toFocus = myPreviouslyFocused;
hint.cancel();
if (toFocus != null) {
IdeFocusManager.getInstance(myProject).requestFocus(toFocus, true);
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class QuickDocOnMouseOverManager method processMouseMove.
private void processMouseMove(@NotNull EditorMouseEvent e) {
if (!myApplicationActive || !myEnabled || e.getArea() != EditorMouseEventArea.EDITING_AREA) {
// Skip if the mouse is not at the editing area.
closeQuickDocIfPossible();
return;
}
if (e.getMouseEvent().getModifiers() != 0) {
// wants to navigate via Ctrl+click or perform quick evaluate by Alt+click.
return;
}
Editor editor = e.getEditor();
if (editor.getComponent().getClientProperty(EditorImpl.IGNORE_MOUSE_TRACKING) != null) {
return;
}
if (editor.isOneLineMode()) {
// Don't want auto quick doc to mess at, say, editor used for debugger condition.
return;
}
Project project = editor.getProject();
if (project == null) {
return;
}
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
JBPopup hint = documentationManager.getDocInfoHint();
if (hint != null) {
// Skip the event if the control is shown because of explicit 'show quick doc' action call.
DocumentationManager manager = getDocManager();
if (manager == null || !manager.isCloseOnSneeze()) {
return;
}
// Skip the event if the mouse is under the opened quick doc control.
Point hintLocation = hint.getLocationOnScreen();
Dimension hintSize = hint.getSize();
int mouseX = e.getMouseEvent().getXOnScreen();
int mouseY = e.getMouseEvent().getYOnScreen();
if (mouseX >= hintLocation.x && mouseX <= hintLocation.x + hintSize.width && mouseY >= hintLocation.y && mouseY <= hintLocation.y + hintSize.height) {
return;
}
}
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null) {
closeQuickDocIfPossible();
return;
}
Point point = e.getMouseEvent().getPoint();
if (editor instanceof EditorEx && ((EditorEx) editor).getFoldingModel().getFoldingPlaceholderAt(point) != null) {
closeQuickDocIfPossible();
return;
}
VisualPosition visualPosition = editor.xyToVisualPosition(point);
if (editor.getSoftWrapModel().isInsideOrBeforeSoftWrap(visualPosition)) {
closeQuickDocIfPossible();
return;
}
int mouseOffset = editor.logicalPositionToOffset(editor.visualToLogicalPosition(visualPosition));
PsiElement elementUnderMouse = psiFile.findElementAt(mouseOffset);
if (elementUnderMouse == null || elementUnderMouse instanceof PsiWhiteSpace || elementUnderMouse instanceof PsiPlainText) {
closeQuickDocIfPossible();
return;
}
if (elementUnderMouse.equals(SoftReference.dereference(myActiveElements.get(editor))) && (// Request to show documentation for the target component has been already queued.
!myAlarm.isEmpty() || // Documentation for the target component is being shown.
hint != null)) {
return;
}
allowUpdateFromContext(project, false);
closeQuickDocIfPossible();
myActiveElements.put(editor, new WeakReference<>(elementUnderMouse));
myAlarm.cancelAllRequests();
if (myCurrentRequest != null)
myCurrentRequest.cancel();
myCurrentRequest = new MyShowQuickDocRequest(documentationManager, editor, mouseOffset, elementUnderMouse);
myAlarm.addRequest(myCurrentRequest, EditorSettingsExternalizable.getInstance().getQuickDocOnMouseOverElementDelayMillis());
}
Aggregations