use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class InjectLanguageAction method doChooseLanguageToInject.
public static boolean doChooseLanguageToInject(Editor editor, final Processor<Injectable> onChosen) {
final List<Injectable> injectables = getAllInjectables();
final JList list = new JBList(injectables);
list.setCellRenderer(new ColoredListCellRendererWrapper<Injectable>() {
@Override
protected void doCustomize(JList list, Injectable language, int index, boolean selected, boolean hasFocus) {
setIcon(language.getIcon());
append(language.getDisplayName());
String description = language.getAdditionalDescription();
if (description != null) {
append(description, SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
}
});
Dimension minSize = new JLabel(PlainTextLanguage.INSTANCE.getDisplayName(), EmptyIcon.ICON_16, SwingConstants.LEFT).getMinimumSize();
minSize.height *= 4;
list.setMinimumSize(minSize);
JBPopup popup = new PopupChooserBuilder(list).setItemChoosenCallback(() -> {
Injectable value = (Injectable) list.getSelectedValue();
if (value != null) {
onChosen.process(value);
PropertiesComponent.getInstance().setValue(LAST_INJECTED_LANGUAGE, value.getId());
}
}).setFilteringEnabled(language -> ((Injectable) language).getDisplayName()).setMinSize(minSize).createPopup();
final String lastInjected = PropertiesComponent.getInstance().getValue(LAST_INJECTED_LANGUAGE);
if (lastInjected != null) {
Injectable injectable = ContainerUtil.find(injectables, injectable1 -> lastInjected.equals(injectable1.getId()));
list.setSelectedValue(injectable, true);
}
popup.showInBestPositionFor(editor);
return true;
}
use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class JumpFromRemoteFileToLocalAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Collection<VirtualFile> files = findLocalFiles(myProject, Urls.newFromVirtualFile(myFile), myFile.getName());
if (files.isEmpty()) {
Messages.showErrorDialog(myProject, "Cannot find local file for '" + myFile.getUrl() + "'", CommonBundle.getErrorTitle());
return;
}
if (files.size() == 1) {
navigateToFile(myProject, ContainerUtil.getFirstItem(files, null));
} else {
final JList list = new JBList(files);
//noinspection unchecked
list.setCellRenderer(new ColoredListCellRenderer() {
@Override
protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
FileAppearanceService.getInstance().forVirtualFile((VirtualFile) value).customize(this);
}
});
new PopupChooserBuilder(list).setTitle("Select Target File").setMovable(true).setItemChoosenCallback(() -> {
//noinspection deprecation
for (Object value : list.getSelectedValues()) {
navigateToFile(myProject, (VirtualFile) value);
}
}).createPopup().showUnderneathOf(e.getInputEvent().getComponent());
}
}
use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class ToolWindowsWidget method mouseEntered.
public void mouseEntered() {
final boolean active = ApplicationManager.getApplication().isActive();
if (!active) {
return;
}
if (myAlarm.getActiveRequestCount() == 0) {
myAlarm.addRequest(() -> {
final IdeFrameImpl frame = UIUtil.getParentOfType(IdeFrameImpl.class, this);
if (frame == null)
return;
List<ToolWindow> toolWindows = new ArrayList<>();
final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(frame.getProject());
for (String id : toolWindowManager.getToolWindowIds()) {
final ToolWindow tw = toolWindowManager.getToolWindow(id);
if (tw.isAvailable() && tw.isShowStripeButton()) {
toolWindows.add(tw);
}
}
Collections.sort(toolWindows, (o1, o2) -> StringUtil.naturalCompare(o1.getStripeTitle(), o2.getStripeTitle()));
final JBList list = new JBList(toolWindows);
list.setCellRenderer(new ListCellRenderer() {
final JBLabel label = new JBLabel();
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final ToolWindow toolWindow = (ToolWindow) value;
label.setText(toolWindow.getStripeTitle());
label.setIcon(toolWindow.getIcon());
label.setBorder(JBUI.Borders.empty(4, 10));
label.setForeground(UIUtil.getListForeground(isSelected));
label.setBackground(UIUtil.getListBackground(isSelected));
final JPanel panel = new JPanel(new BorderLayout());
panel.add(label, BorderLayout.CENTER);
panel.setBackground(UIUtil.getListBackground(isSelected));
return panel;
}
});
final Dimension size = list.getPreferredSize();
final JComponent c = this;
final Insets padding = UIUtil.getListViewportPadding();
final RelativePoint point = new RelativePoint(c, new Point(-4, -padding.top - padding.bottom - 4 - size.height + (SystemInfo.isMac ? 2 : 0)));
if (popup != null && popup.isVisible()) {
return;
}
list.setSelectedIndex(list.getItemsCount() - 1);
PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
popup = builder.setAutoselectOnMouseMove(true).setRequestFocus(false).setItemChoosenCallback(() -> {
if (popup != null)
popup.closeOk(null);
final Object value = list.getSelectedValue();
if (value instanceof ToolWindow) {
((ToolWindow) value).activate(null, true, true);
}
}).createPopup();
// override default of 15 set when createPopup() is called
list.setVisibleRowCount(30);
popup.show(point);
}, 300);
}
}
use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class BaseGenerateTestSupportMethodAction method chooseAndPerform.
private static void chooseAndPerform(Editor editor, List<TestFramework> frameworks, final Consumer<TestFramework> consumer) {
if (frameworks.size() == 1) {
consumer.consume(frameworks.get(0));
return;
}
final JList list = new JBList(frameworks.toArray(new TestFramework[frameworks.size()]));
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component result = super.getListCellRendererComponent(list, "", index, isSelected, cellHasFocus);
if (value == null)
return result;
TestFramework framework = (TestFramework) value;
setIcon(framework.getIcon());
setText(framework.getName());
return result;
}
});
PopupChooserBuilder builder = new PopupChooserBuilder(list);
builder.setFilteringEnabled(o -> ((TestFramework) o).getName());
builder.setTitle("Choose Framework").setItemChoosenCallback(() -> consumer.consume((TestFramework) list.getSelectedValue())).setMovable(true).createPopup().showInBestPositionFor(editor);
}
use of com.intellij.openapi.ui.popup.PopupChooserBuilder 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;
}
Aggregations