mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[spellchecker] IJPL-35111 Unable to select a dictionary with no .dic extension
Merge-request: IJ-MR-167000 Merged-by: Ilia Permiashkin <ilia.permiashkin@jetbrains.com> GitOrigin-RevId: f46a369fdd16ca3588dcdac1d68ecc57fdb122fd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9c5ed69c24
commit
f64d9d3e0d
@@ -24,6 +24,8 @@ import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.util.io.FileUtilRt.extensionEquals
|
||||
import com.intellij.openapi.util.io.FileUtilRt.getExtension
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.openapi.vfs.*
|
||||
import com.intellij.project.stateStore
|
||||
@@ -420,8 +422,10 @@ private class CustomDictFileListener(private val project: Project, private val m
|
||||
}
|
||||
}
|
||||
|
||||
private fun isDic(path: String): Boolean {
|
||||
return FileUtilRt.extensionEquals(path, "dic")
|
||||
fun isDic(path: String): Boolean {
|
||||
return extensionEquals(path, "dic") ||
|
||||
extensionEquals(path, "txt") ||
|
||||
getExtension(path, null) == null
|
||||
}
|
||||
|
||||
private fun affectCustomDictionaries(path: String, project: Project): Boolean {
|
||||
|
||||
@@ -22,10 +22,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.util.io.FileUtilRt.extensionEquals;
|
||||
import static com.intellij.spellchecker.SpellCheckerManagerKt.isDic;
|
||||
import static com.intellij.ui.SimpleTextAttributes.GRAY_ATTRIBUTES;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@@ -105,7 +105,7 @@ public final class CustomDictionariesPanel extends JPanel {
|
||||
final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, true) {
|
||||
@Override
|
||||
public boolean isFileSelectable(@Nullable VirtualFile file) {
|
||||
return file != null && extensionEquals(file.getPath(), "dic");
|
||||
return file != null && isDic(file.getName());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ package com.intellij.spellchecker.settings;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.NlsSafe;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.spellchecker.ProjectDictionaryLayer;
|
||||
import com.intellij.spellchecker.util.SPFileUtil;
|
||||
@@ -14,6 +13,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.spellchecker.SpellCheckerManagerKt.isDic;
|
||||
|
||||
@State(name = "SpellCheckerSettings", storages = @Storage(StoragePathMacros.WORKSPACE_FILE))
|
||||
@Service(Service.Level.PROJECT)
|
||||
public final class SpellCheckerSettings implements PersistentStateComponent<Element> {
|
||||
@@ -146,7 +147,7 @@ public final class SpellCheckerSettings implements PersistentStateComponent<Elem
|
||||
myOldDictionaryFoldersPaths.add(element.getAttributeValue(FOLDER_ATTR_NAME + i));
|
||||
}
|
||||
myOldDictionaryFoldersPaths.forEach(folder -> SPFileUtil.processFilesRecursively(folder, file -> {
|
||||
if (FileUtilRt.extensionEquals(file, "dic")) {
|
||||
if (isDic(file)) {
|
||||
myCustomDictionariesPaths.add(file);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo "newword";
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo "<TYPO descr="Typo: In word 'newword'">newword</TYPO>";
|
||||
@@ -0,0 +1 @@
|
||||
newword
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo "newword";
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo "<TYPO descr="Typo: In word 'newword'">newword</TYPO>";
|
||||
@@ -0,0 +1 @@
|
||||
newword
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo "newword";
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo "newword";
|
||||
@@ -0,0 +1 @@
|
||||
newword
|
||||
@@ -1,2 +1,2 @@
|
||||
<?php
|
||||
echo "<TYPO descr="Typo: In word 'newword'">newword</TYPO>";
|
||||
echo "newword";
|
||||
@@ -4,7 +4,6 @@ package com.intellij.spellchecker.dictionary;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -21,9 +20,14 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.util.io.FileUtilRt.extensionEquals;
|
||||
import static com.intellij.spellchecker.SpellCheckerManagerKt.isDic;
|
||||
|
||||
public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
|
||||
private static final String TEST_DIC = "test.dic";
|
||||
private static final String NEW_TEST_DIC = "new_" + TEST_DIC;
|
||||
private static final String TEST_TXT = "test.txt";
|
||||
private static final String TEST_EXTENSIONLESS = "test";
|
||||
private static final String TEST_DIC_AFTER = TEST_DIC + ".after";
|
||||
public static final String TEMP = "temp";
|
||||
private SpellCheckerSettings settings;
|
||||
@@ -45,7 +49,7 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
|
||||
|
||||
List<String> testDictionaries = new ArrayList<>();
|
||||
VfsUtilCore.processFilesRecursively(dictDir, file -> {
|
||||
if (FileUtilRt.extensionEquals(file.getPath(), "dic")) {
|
||||
if (isDic(file.getName())) {
|
||||
testDictionaries.add(PathUtil.toSystemDependentName(file.getPath()));
|
||||
}
|
||||
return true;
|
||||
@@ -88,8 +92,8 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
|
||||
return dictDir.findChild(TEST_DIC_AFTER);
|
||||
}
|
||||
|
||||
private void modifyDictContent(String newContent) throws IOException {
|
||||
WriteAction.run(() -> VfsUtil.saveText(dictDir.findChild(TEST_DIC), newContent));
|
||||
private void modifyDictContent(String dictName, String newContent) throws IOException {
|
||||
WriteAction.run(() -> VfsUtil.saveText(dictDir.findChild(dictName), newContent));
|
||||
}
|
||||
|
||||
private void doBeforeCheck() {
|
||||
@@ -100,9 +104,13 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
|
||||
doTest(Paths.get(getTestName(true), "test.after.php").toString());
|
||||
}
|
||||
|
||||
private void doTest() throws IOException {
|
||||
private void doDictTest() throws IOException {
|
||||
doDictTest(TEST_DIC);
|
||||
}
|
||||
|
||||
private void doDictTest(String dictName) throws IOException {
|
||||
doBeforeCheck();
|
||||
modifyDictContent(VfsUtilCore.loadText(getTestDictionaryAfter()));
|
||||
modifyDictContent(dictName, VfsUtilCore.loadText(getTestDictionaryAfter()));
|
||||
doAfterCheck();
|
||||
}
|
||||
|
||||
@@ -153,23 +161,31 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
|
||||
}
|
||||
|
||||
public void testAddToCustomDic() throws IOException {
|
||||
doTest();
|
||||
doDictTest();
|
||||
}
|
||||
|
||||
public void testAddTxtToCustomDic() throws IOException {
|
||||
doDictTest(TEST_TXT);
|
||||
}
|
||||
|
||||
public void testAddExtensionlessToCustomDic() throws IOException {
|
||||
doDictTest(TEST_EXTENSIONLESS);
|
||||
}
|
||||
|
||||
public void testAddAnotherToCustomDic() throws IOException {
|
||||
doTest();
|
||||
doDictTest();
|
||||
}
|
||||
|
||||
public void testRemoveFromCustomDic() throws IOException {
|
||||
doTest();
|
||||
doDictTest();
|
||||
}
|
||||
|
||||
public void testAddSeveralWords() throws IOException {
|
||||
doTest();
|
||||
doDictTest();
|
||||
}
|
||||
|
||||
public void testModifyDict() throws IOException {
|
||||
doTest();
|
||||
doDictTest();
|
||||
}
|
||||
|
||||
public void testUtf8Dict() throws IOException {
|
||||
@@ -216,6 +232,12 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
|
||||
doAfterCheck();
|
||||
}
|
||||
|
||||
public void testRenameToExtensionless() throws IOException {
|
||||
doBeforeCheck();
|
||||
WriteAction.run(() -> getTestDictionaryFile().rename(this, "test"));
|
||||
doAfterCheck();
|
||||
}
|
||||
|
||||
public void testRenameStillDicExtension() throws IOException {
|
||||
doBeforeCheck();
|
||||
WriteAction.run(() -> getTestDictionaryFile().rename(this, "still.dic"));
|
||||
|
||||
Reference in New Issue
Block a user