mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 15:06:56 +07:00
[spellchecker] added extension point for specifying additional built-in dictionaries
Used in Rider to show and edit R# spell checker user words GitOrigin-RevId: b1ee8bdf064364800a712400af1c3e7095f306ac
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8aa10bdf3d
commit
86c8fa3545
@@ -7,6 +7,7 @@
|
||||
<extensionPoint name="spellchecker.dictionary.customDictionaryProvider" interface="com.intellij.spellchecker.dictionary.CustomDictionaryProvider" dynamic="true"/>
|
||||
<extensionPoint name="spellchecker.dictionary.runtimeDictionaryProvider" interface="com.intellij.spellchecker.dictionary.RuntimeDictionaryProvider" dynamic="true"/>
|
||||
<extensionPoint name="spellchecker.dictionary.checker" interface="com.intellij.spellchecker.dictionary.DictionaryChecker" dynamic="true"/>
|
||||
<extensionPoint name="spellchecker.builtInDictionariesProvider" interface="com.intellij.spellchecker.settings.BuiltInDictionariesProvider" dynamic="true"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.spellchecker.settings
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
|
||||
abstract class BuiltInDictionariesProvider {
|
||||
abstract fun getDictionaries(): List<BuiltInDictionary>
|
||||
|
||||
companion object {
|
||||
val EP_NAME = ExtensionPointName.create<BuiltInDictionariesProvider>("com.intellij.spellchecker.builtInDictionariesProvider")
|
||||
|
||||
fun getAll(): List<BuiltInDictionariesProvider> {
|
||||
return EP_NAME.extensionList
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.spellchecker.settings
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
|
||||
interface BuiltInDictionary {
|
||||
fun openDictionaryInEditor(project: Project)
|
||||
val name: String
|
||||
}
|
||||
@@ -35,14 +35,19 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
private final CustomDictionariesTableView myCustomDictionariesTableView;
|
||||
private final List<String> removedDictionaries = new ArrayList<>();
|
||||
private final List<String> defaultDictionaries;
|
||||
private final Map<String, BuiltInDictionary> builtInDictionaries;
|
||||
|
||||
public CustomDictionariesPanel(@NotNull SpellCheckerSettings settings, @NotNull Project project, @NotNull SpellCheckerManager manager) {
|
||||
mySettings = settings;
|
||||
myManager = manager;
|
||||
defaultDictionaries = project.isDefault() ? new ArrayList<>() : asList(SpellCheckerBundle.message("app.dictionary"), SpellCheckerBundle
|
||||
.message("project.dictionary"));
|
||||
builtInDictionaries = new HashMap<>();
|
||||
BuiltInDictionariesProvider.Companion.getAll().stream()
|
||||
.map(BuiltInDictionariesProvider::getDictionaries).flatMap(List::stream)
|
||||
.forEach(dictionary -> builtInDictionaries.put(dictionary.getName(), dictionary));
|
||||
myCustomDictionariesTableView = new CustomDictionariesTableView(new ArrayList<>(settings.getCustomDictionariesPaths()),
|
||||
defaultDictionaries);
|
||||
defaultDictionaries, builtInDictionaries.keySet().stream().toList());
|
||||
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myCustomDictionariesTableView)
|
||||
.setAddActionName(SpellCheckerBundle.message("add.custom.dictionaries"))
|
||||
.setAddAction(new AnActionButtonRunnable() {
|
||||
@@ -62,7 +67,10 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
removedDictionaries.addAll(myCustomDictionariesTableView.getSelectedObjects());
|
||||
TableUtil.removeSelectedItems(myCustomDictionariesTableView);
|
||||
})
|
||||
.setRemoveActionUpdater(e -> !ContainerUtil.exists(myCustomDictionariesTableView.getSelectedObjects(), defaultDictionaries::contains))
|
||||
.setRemoveActionUpdater(
|
||||
e -> !ContainerUtil.exists(myCustomDictionariesTableView.getSelectedObjects(),
|
||||
x -> defaultDictionaries.contains(x) || builtInDictionaries.containsKey(x))
|
||||
)
|
||||
|
||||
.setEditActionName(SpellCheckerBundle.message("edit.custom.dictionary"))
|
||||
.setEditAction(new AnActionButtonRunnable() {
|
||||
@@ -71,6 +79,11 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
String selectedDictionary = myCustomDictionariesTableView.getSelectedObject();
|
||||
if (selectedDictionary == null) return;
|
||||
|
||||
if(builtInDictionaries.containsKey(selectedDictionary)) {
|
||||
var dictionary = builtInDictionaries.get(selectedDictionary);
|
||||
dictionary.openDictionaryInEditor(project);
|
||||
return;
|
||||
}
|
||||
if (defaultDictionaries.contains(selectedDictionary)) {
|
||||
selectedDictionary = selectedDictionary.equals(SpellCheckerBundle.message("app.dictionary"))
|
||||
? myManager.getAppDictionaryPath$intellij_spellchecker()
|
||||
@@ -112,7 +125,7 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
|
||||
Set<String> newPaths = new HashSet<>();
|
||||
for (String t : collection) {
|
||||
if (!defaultDictionaries.contains(t)) {
|
||||
if (!defaultDictionaries.contains(t) && !builtInDictionaries.containsKey(t)) {
|
||||
newPaths.add(t);
|
||||
}
|
||||
}
|
||||
@@ -121,14 +134,14 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
|
||||
public void reset() {
|
||||
myCustomDictionariesTableView.getListTableModel()
|
||||
.setItems(new ArrayList<>(ContainerUtil.concat(defaultDictionaries, mySettings.getCustomDictionariesPaths())));
|
||||
.setItems(new ArrayList<>(ContainerUtil.concat(defaultDictionaries, builtInDictionaries.keySet().stream().toList(), mySettings.getCustomDictionariesPaths())));
|
||||
removedDictionaries.clear();
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
List<String> oldPaths = mySettings.getCustomDictionariesPaths();
|
||||
List<String> newPaths = new ArrayList<>(ContainerUtil.filter(myCustomDictionariesTableView.getItems(), dict -> {
|
||||
return !defaultDictionaries.contains(dict);
|
||||
return !defaultDictionaries.contains(dict) && !builtInDictionaries.containsKey(dict);
|
||||
}));
|
||||
mySettings.setCustomDictionariesPaths(newPaths);
|
||||
myManager.updateBundledDictionaries(ContainerUtil.filter(oldPaths, o -> !newPaths.contains(o)));
|
||||
@@ -143,9 +156,11 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
final TableCellRenderer myTypeRenderer;
|
||||
|
||||
private CustomDictionariesTableView(@NotNull List<String> dictionaries,
|
||||
@NotNull List<String> defaultDictionaries) {
|
||||
myTypeRenderer = createTypeRenderer(defaultDictionaries);
|
||||
@NotNull List<String> defaultDictionaries,
|
||||
@NotNull List<String> builtInDictionaries) {
|
||||
myTypeRenderer = createTypeRenderer(defaultDictionaries, builtInDictionaries);
|
||||
var items = new ArrayList<>(defaultDictionaries);
|
||||
items.addAll(builtInDictionaries);
|
||||
items.addAll(dictionaries);
|
||||
setModelAndUpdateColumns(new ListTableModel<>(createDictionaryColumnInfos(), items, 0));
|
||||
setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN);
|
||||
@@ -155,7 +170,8 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
setTableHeader(null);
|
||||
}
|
||||
|
||||
private static TableCellRenderer createTypeRenderer(List<String> defaultDictionaries) {
|
||||
private static TableCellRenderer createTypeRenderer(List<String> defaultDictionaries,
|
||||
@NotNull List<String> builtInDictionaries) {
|
||||
return new TableCellRenderer() {
|
||||
final SimpleColoredComponent myLabel = new SimpleColoredComponent();
|
||||
|
||||
@@ -170,7 +186,7 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
myLabel.clear();
|
||||
myLabel.append((String)value, SimpleTextAttributes.REGULAR_ATTRIBUTES);
|
||||
String type;
|
||||
if (defaultDictionaries.contains(value)) {
|
||||
if (defaultDictionaries.contains(value) || builtInDictionaries.contains(value)) {
|
||||
type = SpellCheckerBundle.message("built.in.dictionary");
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user