From 7dace1831d17d1c82719c6b91155478ccf50e42e Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Fri, 14 Feb 2025 22:21:14 +0100 Subject: [PATCH] [spellchecker] IJPL-969 Project-level dictionary file is named after a current user: issues sharing it GitOrigin-RevId: 669815ed85c2c8d9310801c7f2305367b3496bb1 --- .../resources/META-INF/SpellCheckerPlugin.xml | 2 ++ .../messages/SpellCheckerBundle.properties | 10 ++++---- .../spellchecker/SpellCheckerManager.kt | 25 +++++++++++++++---- .../dictionary/ProjectDictionary.java | 4 +-- .../settings/CustomDictionariesPanel.java | 4 +-- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/spellchecker/resources/META-INF/SpellCheckerPlugin.xml b/spellchecker/resources/META-INF/SpellCheckerPlugin.xml index 09f18d4087e7..4d24612e6efc 100644 --- a/spellchecker/resources/META-INF/SpellCheckerPlugin.xml +++ b/spellchecker/resources/META-INF/SpellCheckerPlugin.xml @@ -36,6 +36,8 @@ + diff --git a/spellchecker/resources/messages/SpellCheckerBundle.properties b/spellchecker/resources/messages/SpellCheckerBundle.properties index 254c03635266..e31a9bdff1ee 100644 --- a/spellchecker/resources/messages/SpellCheckerBundle.properties +++ b/spellchecker/resources/messages/SpellCheckerBundle.properties @@ -1,6 +1,6 @@ change.to.title=Fix typo change.to.tooltip=Replace with ''{0}'' -rename.to=Typo: Rename to... +rename.to=Typo: Rename to\u2026 proofread=Proofreading spelling=Spelling spellchecking.inspection.name=Typo @@ -17,15 +17,15 @@ entered.word.0.is.correct.you.no.need.to.add.this.in.list=The word ''{0}'' is al process.code=Process code process.literals=Process literals process.comments=Process comments -link.to.inspection.settings=Configure 'Spelling' inspection... +link.to.inspection.settings=Configure 'Spelling' inspection\u2026 add.dictionary.description=Custom dictionaries (plain text word lists{0}): custom.dictionary.title=Custom Dictionary -add.custom.dictionaries=Add custom dictionaries -edit.custom.dictionary=Edit custom dictionary +add.custom.dictionaries=Add Custom Dictionaries +edit.custom.dictionary=Edit Custom Dictionary dictionary.not.found.title=Dictionary Is Not Found dictionary.not.found=Dictionary is not found at path {0} dictionary.unsupported.format.title=Unsupported Format -dictionary.unsupported.format=Dictionary file {0} has unsupported format +dictionary.unsupported.format=Dictionary file {0} has an unsupported format dictionary.unsupported.language.title=Unsupported Language dictionary.unsupported.language=Dictionary file {0} language is not currently supported, use the Hunspell plugin instead remove.custom.dictionaries=Remove custom dictionaries diff --git a/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.kt b/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.kt index cb09d7dfdc6f..bf89152c7ca0 100644 --- a/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.kt +++ b/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.kt @@ -55,11 +55,14 @@ class SpellCheckerManager @Internal constructor(@Internal val project: Project, private var projectDictionary: ProjectDictionary? = null private var appDictionary: EditableDictionary? = null - internal val projectDictionaryPath: String by lazy { + @get:Internal + val projectDictionaryPath: String by lazy { val projectStoreDir = project.takeIf { !it.isDefault }?.stateStore?.directoryStorePath - projectStoreDir?.toAbsolutePath()?.resolve(PROJECT_DICTIONARY_PATH)?.toString() ?: "" + projectStoreDir?.toAbsolutePath()?.resolve(getProjectDictionaryPath())?.toString() ?: "" } - internal val appDictionaryPath: String by lazy { + + @get:Internal + val appDictionaryPath: String by lazy { PathManager.getOptionsPath() + File.separator + CACHED_DICTIONARY_FILE } @@ -96,7 +99,7 @@ class SpellCheckerManager @Internal constructor(@Internal val project: Project, companion object { private const val MAX_METRICS = 1 - private val PROJECT_DICTIONARY_PATH = "dictionaries${File.separator}${System.getProperty("user.name").replace('.', '_')}.xml" + private const val CACHED_DICTIONARY_FILE = "spellchecker-dictionary.xml" @JvmStatic @@ -209,7 +212,8 @@ class SpellCheckerManager @Internal constructor(@Internal val project: Project, val dictionaryState = project.service() dictionaryState.addProjectDictListener { restartInspections() } projectDictionary = dictionaryState.projectDictionary - projectDictionary!!.setActiveName(System.getProperty("user.name")) + projectDictionary!!.setActiveName(getProjectDictionaryName()) + spellChecker.addModifiableDictionary(projectDictionary!!) } @@ -459,4 +463,15 @@ private class StreamLoader(private val name: String, private val loaderClass: Cl } override fun getName() = name +} + +private fun getProjectDictionaryPath(): String { + return "dictionaries${File.separator}${getProjectDictionaryName().replace('.', '_')}.xml" +} + +internal fun getProjectDictionaryName(): String { + return if (Registry.`is`("spellchecker.use.standard.project.dictionary.name")) + ProjectDictionary.DEFAULT_CURRENT_DICT_NAME + else + System.getProperty("user.name") } \ No newline at end of file diff --git a/spellchecker/src/com/intellij/spellchecker/dictionary/ProjectDictionary.java b/spellchecker/src/com/intellij/spellchecker/dictionary/ProjectDictionary.java index 8071d4ca198a..8bb26b9ae634 100644 --- a/spellchecker/src/com/intellij/spellchecker/dictionary/ProjectDictionary.java +++ b/spellchecker/src/com/intellij/spellchecker/dictionary/ProjectDictionary.java @@ -12,7 +12,7 @@ import java.util.Objects; import java.util.Set; public final class ProjectDictionary implements EditableDictionary { - private static final @NonNls String DEFAULT_CURRENT_USER_NAME = "default.user"; + public static final @NonNls String DEFAULT_CURRENT_DICT_NAME = "project"; private static final String DEFAULT_PROJECT_DICTIONARY_NAME = "project"; private String activeName; private Set dictionaries; @@ -74,7 +74,7 @@ public final class ProjectDictionary implements EditableDictionary { private @NotNull EditableDictionary ensureCurrentUserDictionary() { if (activeName == null) { - activeName = DEFAULT_CURRENT_USER_NAME; + activeName = DEFAULT_CURRENT_DICT_NAME; } EditableDictionary result = getDictionaryByName(activeName); if (result == null) { diff --git a/spellchecker/src/com/intellij/spellchecker/settings/CustomDictionariesPanel.java b/spellchecker/src/com/intellij/spellchecker/settings/CustomDictionariesPanel.java index 2a4636d11529..fd969b632836 100644 --- a/spellchecker/src/com/intellij/spellchecker/settings/CustomDictionariesPanel.java +++ b/spellchecker/src/com/intellij/spellchecker/settings/CustomDictionariesPanel.java @@ -86,8 +86,8 @@ public final class CustomDictionariesPanel extends JPanel { } if (defaultDictionaries.contains(selectedDictionary)) { selectedDictionary = selectedDictionary.equals(SpellCheckerBundle.message("app.dictionary")) - ? myManager.getAppDictionaryPath$intellij_spellchecker() - : myManager.getProjectDictionaryPath$intellij_spellchecker(); + ? myManager.getAppDictionaryPath() + : myManager.getProjectDictionaryPath(); } manager.openDictionaryInEditor(selectedDictionary); }