use of com.intellij.uiDesigner.quickFixes.PopupQuickFix 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 + "'");
}
}
});
}
Aggregations