use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class AnnotateCapitalizationIntention method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
final PsiModifierListOwner modifierListOwner = getElement(editor, file);
if (modifierListOwner == null)
throw new IncorrectOperationException();
BaseListPopupStep<Nls.Capitalization> step = new BaseListPopupStep<Nls.Capitalization>(null, Nls.Capitalization.Title, Nls.Capitalization.Sentence) {
@Override
public PopupStep onChosen(final Nls.Capitalization selectedValue, boolean finalChoice) {
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
String nls = Nls.class.getName();
PsiAnnotation annotation = JavaPsiFacade.getInstance(project).getElementFactory().createAnnotationFromText("@" + nls + "(capitalization = " + nls + ".Capitalization." + selectedValue.toString() + ")", modifierListOwner);
new AddAnnotationFix(Nls.class.getName(), modifierListOwner, annotation.getParameterList().getAttributes()).applyFix();
}
}.execute();
return FINAL_CHOICE;
}
};
JBPopupFactory.getInstance().createListPopup(step).showInBestPositionFor(editor);
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class FormSpellCheckingInspection method checkStringDescriptor.
@Override
protected void checkStringDescriptor(Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
final String value = descriptor.getResolvedValue();
if (value == null) {
return;
}
final SpellCheckerManager manager = SpellCheckerManager.getInstance(module.getProject());
PlainTextSplitter.getInstance().split(value, TextRange.allOf(value), textRange -> {
final String word = textRange.substring(value);
if (manager.hasProblem(word)) {
final List<String> suggestions = manager.getSuggestions(word);
if (!suggestions.isEmpty() && prop instanceof IntroStringProperty) {
EditorQuickFixProvider changeToProvider = new EditorQuickFixProvider() {
@Override
public QuickFix createQuickFix(final GuiEditor editor, final RadComponent component1) {
return new PopupQuickFix<String>(editor, "Change to...", component1) {
@Override
public void run() {
ListPopup popup = JBPopupFactory.getInstance().createListPopup(getPopupStep());
popup.showUnderneathOf(component1.getDelegee());
}
@Override
public ListPopupStep<String> getPopupStep() {
return new BaseListPopupStep<String>("Select Replacement", suggestions) {
@Override
public PopupStep onChosen(String selectedValue, boolean finalChoice) {
FormInspectionUtil.updateStringPropertyValue(editor, component1, (IntroStringProperty) prop, descriptor, selectedValue);
return FINAL_CHOICE;
}
};
}
};
}
};
EditorQuickFixProvider acceptProvider = new EditorQuickFixProvider() {
@Override
public QuickFix createQuickFix(final GuiEditor editor, RadComponent component1) {
return new QuickFix(editor, "Save '" + word + "' to dictionary", component1) {
@Override
public void run() {
manager.acceptWordAsCorrect(word, editor.getProject());
}
};
}
};
collector.addError(getID(), component, prop, "Typo in word '" + word + "'", changeToProvider, acceptProvider);
} else {
collector.addError(getID(), component, prop, "Typo in word '" + word + "'");
}
}
});
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class ModuleChooserUtil method selectModule.
public static void selectModule(@NotNull Project project, final Collection<Module> suitableModules, final Function<Module, String> versionProvider, final Consumer<Module> callback, @Nullable DataContext context) {
final List<Module> modules = new ArrayList<>();
final Map<Module, String> versions = new HashMap<>();
for (Module module : suitableModules) {
modules.add(module);
versions.put(module, versionProvider.fun(module));
}
if (modules.size() == 1) {
callback.consume(modules.get(0));
return;
}
Collections.sort(modules, ModulesAlphaComparator.INSTANCE);
BaseListPopupStep<Module> step = new BaseListPopupStep<Module>("Which module to use classpath of?", modules, PlatformIcons.CONTENT_ROOT_ICON_CLOSED) {
@NotNull
@Override
public String getTextFor(Module value) {
return String.format("%s (%s)", value.getName(), versions.get(value));
}
@Override
public String getIndexedString(Module value) {
return value.getName();
}
@Override
public boolean isSpeedSearchEnabled() {
return true;
}
@Override
public PopupStep onChosen(Module selectedValue, boolean finalChoice) {
PropertiesComponent.getInstance(selectedValue.getProject()).setValue(GROOVY_LAST_MODULE, selectedValue.getName());
callback.consume(selectedValue);
return null;
}
};
final String lastModuleName = PropertiesComponent.getInstance(project).getValue(GROOVY_LAST_MODULE);
if (lastModuleName != null) {
int defaultOption = ContainerUtil.indexOf(modules, new Condition<Module>() {
@Override
public boolean value(Module module) {
return module.getName().equals(lastModuleName);
}
});
if (defaultOption >= 0) {
step.setDefaultOptionIndex(defaultOption);
}
}
final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
if (context == null) {
listPopup.showCenteredInCurrentWindow(project);
} else {
listPopup.showInBestPositionFor(context);
}
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class AbstractAddToTestsPatternAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
final LinkedHashSet<PsiElement> classes = new LinkedHashSet<>();
PsiElementProcessor.CollectElements<PsiElement> processor = new PsiElementProcessor.CollectElements<>(classes);
getPatternBasedProducer().collectTestMembers(psiElements, true, true, processor);
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final List<T> patternConfigurations = collectPatternConfigurations(classes, project);
if (patternConfigurations.size() == 1) {
final T configuration = patternConfigurations.get(0);
for (PsiElement aClass : classes) {
getPatterns(configuration).add(getPatternBasedProducer().getQName(aClass));
}
} else {
JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<T>("Choose suite to add", patternConfigurations) {
@Override
public PopupStep onChosen(T configuration, boolean finalChoice) {
for (PsiElement aClass : classes) {
getPatterns(configuration).add(getPatternBasedProducer().getQName(aClass));
}
return FINAL_CHOICE;
}
@Override
public Icon getIconFor(T configuration) {
return configuration.getIcon();
}
@NotNull
@Override
public String getTextFor(T value) {
return value.getName();
}
}).showInBestPositionFor(dataContext);
}
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class ExpressionInputComponent method showHistory.
private void showHistory() {
List<XExpression> expressions = myExpressionEditor.getRecentExpressions();
if (!expressions.isEmpty()) {
ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) {
@Override
public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) {
myExpressionEditor.setExpression(selectedValue);
myExpressionEditor.requestFocusInEditor();
return FINAL_CHOICE;
}
}) {
@Override
protected ListCellRenderer getListElementRenderer() {
return new ColoredListCellRenderer<XExpression>() {
@Override
protected void customizeCellRenderer(@NotNull JList list, XExpression value, int index, boolean selected, boolean hasFocus) {
append(value.getExpression());
}
};
}
};
popup.getList().setFont(EditorUtil.getEditorFont());
popup.showUnderneathOf(myExpressionEditor.getEditorComponent());
}
}
Aggregations