use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class PluginDescriptorChooser method show.
public static void show(final Project project, final Editor editor, final PsiFile file, final Consumer<DomFileElement<IdeaPlugin>> consumer) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
assert module != null;
List<DomFileElement<IdeaPlugin>> elements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, module.getModuleWithDependentsScope());
elements = ContainerUtil.filter(elements, element -> {
VirtualFile virtualFile = element.getFile().getVirtualFile();
return virtualFile != null && ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile);
});
elements = findAppropriateIntelliJModule(module.getName(), elements);
if (elements.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, "Cannot find plugin descriptor");
return;
}
if (elements.size() == 1) {
consumer.consume(elements.get(0));
return;
}
final BaseListPopupStep<PluginDescriptorCandidate> popupStep = new BaseListPopupStep<PluginDescriptorCandidate>("Choose Plugin Descriptor", createCandidates(module, elements)) {
@Override
public boolean isSpeedSearchEnabled() {
return true;
}
@Override
public Icon getIconFor(PluginDescriptorCandidate candidate) {
return candidate.getIcon();
}
@NotNull
@Override
public String getTextFor(PluginDescriptorCandidate candidate) {
return candidate.getText();
}
@Nullable
@Override
public ListSeparator getSeparatorAbove(PluginDescriptorCandidate candidate) {
final String separatorText = candidate.getSeparatorText();
if (separatorText != null) {
return new ListSeparator(separatorText);
}
return null;
}
@Override
public PopupStep onChosen(PluginDescriptorCandidate selectedValue, boolean finalChoice) {
consumer.consume(selectedValue.myDomFileElement);
return FINAL_CHOICE;
}
};
JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor);
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class DetectionExcludesConfigurable method doAddAction.
private void doAddAction(AnActionButton button) {
final List<FrameworkType> types = new ArrayList<>();
for (FrameworkType type : FrameworkDetectorRegistry.getInstance().getFrameworkTypes()) {
if (!isExcluded(type)) {
types.add(type);
}
}
Collections.sort(types, (o1, o2) -> o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName()));
types.add(0, null);
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<FrameworkType>("Framework to Exclude", types) {
@Override
public Icon getIconFor(FrameworkType value) {
return value != null ? value.getIcon() : null;
}
@NotNull
@Override
public String getTextFor(FrameworkType value) {
return value != null ? value.getPresentableName() : "All Frameworks...";
}
@Override
public boolean hasSubstep(FrameworkType selectedValue) {
return selectedValue != null;
}
@Override
public PopupStep onChosen(final FrameworkType frameworkType, boolean finalChoice) {
if (frameworkType == null) {
return doFinalStep(() -> chooseDirectoryAndAdd(null));
} else {
return addExcludedFramework(frameworkType);
}
}
});
final RelativePoint popupPoint = button.getPreferredPopupPoint();
if (popupPoint != null) {
popup.show(popupPoint);
} else {
popup.showInCenterOf(myMainPanel);
}
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class BaseRunConfigurationAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
final RunnerAndConfigurationSettings existing = context.findExisting();
if (existing == null) {
final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
if (producers.isEmpty())
return;
if (producers.size() > 1) {
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
Collections.sort(producers, ConfigurationFromContext.NAME_COMPARATOR);
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationFromContext>(ExecutionBundle.message("configuration.action.chooser.title"), producers) {
@Override
@NotNull
public String getTextFor(final ConfigurationFromContext producer) {
return childActionName(producer.getConfigurationType(), producer.getConfiguration());
}
@Override
public Icon getIconFor(final ConfigurationFromContext producer) {
return producer.getConfigurationType().getIcon();
}
@Override
public PopupStep onChosen(final ConfigurationFromContext producer, final boolean finalChoice) {
perform(producer, context);
return FINAL_CHOICE;
}
});
final InputEvent event = e.getInputEvent();
if (event instanceof MouseEvent) {
popup.show(new RelativePoint((MouseEvent) event));
} else if (editor != null) {
popup.showInBestPositionFor(editor);
} else {
popup.showInBestPositionFor(dataContext);
}
} else {
perform(producers.get(0), context);
}
return;
}
perform(context);
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class SurroundElementWithAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
final LayoutTreeSelection selection = treeComponent.getSelection();
final CompositePackagingElement<?> parent = selection.getCommonParentElement();
if (parent == null)
return;
final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
if (parentNode == null)
return;
if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
return;
}
final CompositePackagingElementType<?>[] types = PackagingElementFactory.getInstance().getCompositeElementTypes();
final List<PackagingElement<?>> selected = selection.getElements();
if (types.length == 1) {
surroundWith(types[0], parent, selected, treeComponent);
} else {
JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CompositePackagingElementType>("Surround With...", types) {
@Override
public Icon getIconFor(CompositePackagingElementType aValue) {
return aValue.getCreateElementIcon();
}
@NotNull
@Override
public String getTextFor(CompositePackagingElementType value) {
return value.getPresentableName();
}
@Override
public PopupStep onChosen(final CompositePackagingElementType selectedValue, boolean finalChoice) {
return doFinalStep(() -> surroundWith(selectedValue, parent, selected, treeComponent));
}
}).showInBestPositionFor(e.getDataContext());
}
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class StaticImportMethodQuestionAction method chooseAndImport.
private void chooseAndImport(final Editor editor, final Project project) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
doImport(myCandidates.get(0));
return;
}
final BaseListPopupStep<T> step = new BaseListPopupStep<T>(getPopupTitle(), myCandidates) {
@Override
public boolean isAutoSelectionEnabled() {
return false;
}
@Override
public boolean isSpeedSearchEnabled() {
return true;
}
@Override
public PopupStep onChosen(T selectedValue, boolean finalChoice) {
if (selectedValue == null) {
return FINAL_CHOICE;
}
if (finalChoice) {
return doFinalStep(() -> {
PsiDocumentManager.getInstance(project).commitAllDocuments();
LOG.assertTrue(selectedValue.isValid());
doImport(selectedValue);
});
}
return AddImportAction.getExcludesStep(PsiUtil.getMemberQualifiedName(selectedValue), project);
}
@Override
public boolean hasSubstep(T selectedValue) {
return true;
}
@NotNull
@Override
public String getTextFor(T value) {
return getElementPresentableName(value);
}
@Override
public Icon getIconFor(T aValue) {
return aValue.getIcon(0);
}
};
final ListPopupImpl popup = new ListPopupImpl(step) {
final PopupListElementRenderer rightArrow = new PopupListElementRenderer(this);
@Override
protected ListCellRenderer getListElementRenderer() {
return new PsiElementListCellRenderer<T>() {
public String getElementText(T element) {
return getElementPresentableName(element);
}
public String getContainerText(final T element, final String name) {
return PsiClassListCellRenderer.getContainerTextStatic(element);
}
public int getIconFlags() {
return 0;
}
@Nullable
@Override
protected TextAttributes getNavigationItemAttributes(Object value) {
TextAttributes attrs = super.getNavigationItemAttributes(value);
if (value instanceof PsiDocCommentOwner && !((PsiDocCommentOwner) value).isDeprecated()) {
PsiClass psiClass = ((T) value).getContainingClass();
if (psiClass != null && psiClass.isDeprecated()) {
return TextAttributes.merge(attrs, super.getNavigationItemAttributes(psiClass));
}
}
return attrs;
}
@Override
protected DefaultListCellRenderer getRightCellRenderer(final Object value) {
final DefaultListCellRenderer moduleRenderer = super.getRightCellRenderer(value);
return new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JPanel panel = new JPanel(new BorderLayout());
if (moduleRenderer != null) {
Component moduleComponent = moduleRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (!isSelected) {
moduleComponent.setBackground(getBackgroundColor(value));
}
panel.add(moduleComponent, BorderLayout.CENTER);
}
rightArrow.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
Component rightArrowComponent = rightArrow.getNextStepLabel();
panel.add(rightArrowComponent, BorderLayout.EAST);
return panel;
}
};
}
};
}
};
popup.showInBestPositionFor(editor);
}
Aggregations