mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Spellchecker:(minor refactoring)load/remove methods are simplified
This commit is contained in:
@@ -318,42 +318,31 @@ public class SpellCheckerManager implements Disposable {
|
||||
}
|
||||
|
||||
private void removeCustomDictionaries(@NotNull String path) {
|
||||
path = toSystemDependentName(path);
|
||||
if (spellChecker.isDictionaryLoad(path)) {
|
||||
spellChecker.removeDictionary(path);
|
||||
final String systemDependentPath = toSystemDependentName(path);
|
||||
if (locatedInDictFolders(path)) {
|
||||
spellChecker.removeDictionariesRecursively(systemDependentPath);
|
||||
mySettings.getDictionaryFoldersPaths().removeIf(dict -> isAncestor(systemDependentPath, dict, false));
|
||||
mySettings.getDisabledDictionariesPaths().removeIf(dict -> isAncestor(systemDependentPath, dict, false));
|
||||
restartInspections();
|
||||
}
|
||||
else if (locatedInDictFolders(path)) {
|
||||
spellChecker.removeDictionariesRecursively(path);
|
||||
restartInspections();
|
||||
}
|
||||
if (mySettings.getDictionaryFoldersPaths().contains(path)) {
|
||||
mySettings.getDictionaryFoldersPaths().remove(path);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCustomDictionaries(@NotNull VirtualFile file) {
|
||||
final String path = toSystemDependentName(file.getPath());
|
||||
if (!locatedInDictFolders(path)) return;
|
||||
|
||||
if (file.isDirectory()) {
|
||||
visitChildrenRecursively(file, new VirtualFileVisitor() {
|
||||
@Override
|
||||
public boolean visitFile(@NotNull VirtualFile file) {
|
||||
final boolean isDirectory = file.isDirectory();
|
||||
final String path = file.getPath();
|
||||
if (!isDirectory && isDic(path)) {
|
||||
loadDictionary(path);
|
||||
restartInspections();
|
||||
}
|
||||
return isDirectory;
|
||||
visitChildrenRecursively(file, new VirtualFileVisitor() {
|
||||
@Override
|
||||
public boolean visitFile(@NotNull VirtualFile file) {
|
||||
final boolean isDirectory = file.isDirectory();
|
||||
final String path = file.getPath();
|
||||
if (!isDirectory && isDic(path)) {
|
||||
loadDictionary(path);
|
||||
restartInspections();
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (isDic(path)) {
|
||||
loadDictionary(path);
|
||||
restartInspections();
|
||||
}
|
||||
return isDirectory;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isDic(String path) {
|
||||
|
||||
@@ -213,7 +213,7 @@ public class BaseSpellChecker implements SpellCheckerEngine {
|
||||
public void removeDictionariesRecursively(@NotNull String directory) {
|
||||
bundledDictionaries.stream()
|
||||
.map(Dictionary::getName)
|
||||
.filter(dict -> isAncestor(directory, dict, true) && isDictionaryLoad(dict))
|
||||
.filter(dict -> isAncestor(directory, dict, false) && isDictionaryLoad(dict))
|
||||
.forEach(this::removeDictionary);
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ public class SpellCheckerSettingsPane implements Disposable {
|
||||
|
||||
optionalChooserComponent.apply();
|
||||
pathsChooserComponent.apply();
|
||||
settings.setDictionaryFoldersPaths(pathsChooserComponent.getValues());
|
||||
settings.setDictionaryFoldersPaths(new ArrayList<>(pathsChooserComponent.getValues()));
|
||||
|
||||
final HashSet<String> disabledDictionaries = new HashSet<>();
|
||||
final HashSet<String> bundledDisabledDictionaries = new HashSet<>();
|
||||
|
||||
@@ -27,11 +27,13 @@ import com.intellij.spellchecker.settings.SpellCheckerSettings;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.util.io.FileUtil.createTempDirectory;
|
||||
import static com.intellij.openapi.vfs.VfsUtil.findFileByIoFile;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
|
||||
private static final String TEST_DIC = "test.dic";
|
||||
@@ -51,7 +53,7 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
|
||||
settings = SpellCheckerSettings.getInstance(getProject());
|
||||
spellCheckerManager = SpellCheckerManager.getInstance(getProject());
|
||||
oldPaths = settings.getDictionaryFoldersPaths();
|
||||
settings.setDictionaryFoldersPaths(Collections.singletonList(getTestDictDirectory()));
|
||||
settings.setDictionaryFoldersPaths(new ArrayList<>(singletonList(getTestDictDirectory())));
|
||||
spellCheckerManager.fullConfigurationReload();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user