mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[spellchecker] review fixes: get rid of layers holder, replaced message with messagePointer
GitOrigin-RevId: 625692a702c87057e54ba47df667851be9298654
This commit is contained in:
committed by
intellij-monorepo-bot
parent
63281c87e8
commit
2b54e307d2
@@ -1,70 +1,34 @@
|
||||
// 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
|
||||
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.spellchecker.dictionary.EditableDictionary
|
||||
import com.intellij.spellchecker.dictionary.ProjectDictionary
|
||||
import com.intellij.spellchecker.settings.DictionaryLayerChangesListener
|
||||
import com.intellij.spellchecker.settings.DictionaryLayersChangesDispatcher
|
||||
import com.intellij.spellchecker.state.AppDictionaryState
|
||||
import com.intellij.spellchecker.state.ProjectDictionaryState
|
||||
import com.intellij.spellchecker.util.SpellCheckerBundle
|
||||
import org.jetbrains.annotations.Nls
|
||||
import java.util.concurrent.ConcurrentMap
|
||||
import java.util.function.Supplier
|
||||
|
||||
interface DictionaryLayersProvider {
|
||||
fun getLayers(project: Project): List<DictionaryLayer>
|
||||
fun startWatchingChanges(project: Project) { }
|
||||
|
||||
companion object {
|
||||
val EP_NAME = ExtensionPointName.create<DictionaryLayersProvider>("com.intellij.spellchecker.dictionaryLayersProvider")
|
||||
@JvmStatic
|
||||
fun getAllLayers(project: Project): Collection<DictionaryLayer> {
|
||||
return project.service<PerProjectDictionaryLayersHolder>().getAllLayers()
|
||||
return EP_NAME.extensionList.flatMap { it.getLayers(project) }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getLayer(project: Project, layerName: String): DictionaryLayer? {
|
||||
return project.service<PerProjectDictionaryLayersHolder>().getLayer(layerName)
|
||||
return EP_NAME.extensionList.flatMap { it.getLayers(project) }.firstOrNull { it.name == layerName }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Service(Service.Level.PROJECT)
|
||||
class PerProjectDictionaryLayersHolder(private val project: Project) {
|
||||
private var layersMap: Map<String, DictionaryLayer> = mapOf()
|
||||
|
||||
init {
|
||||
project.service<DictionaryLayersChangesDispatcher>()
|
||||
.register(object : DictionaryLayerChangesListener {
|
||||
override fun layersChanged() {
|
||||
rebuild()
|
||||
}
|
||||
})
|
||||
DictionaryLayersProvider.EP_NAME.extensionList.forEach{
|
||||
it.startWatchingChanges(project)
|
||||
}
|
||||
rebuild()
|
||||
}
|
||||
|
||||
fun rebuild() {
|
||||
layersMap = DictionaryLayersProvider.EP_NAME.extensionList
|
||||
.flatMap { it.getLayers(project) }
|
||||
.associateBy { it.name }
|
||||
}
|
||||
|
||||
fun getLayer(layerName: String): DictionaryLayer? {
|
||||
return layersMap[layerName]
|
||||
}
|
||||
|
||||
fun getAllLayers(): Collection<DictionaryLayer> {
|
||||
return layersMap.values
|
||||
}
|
||||
}
|
||||
|
||||
interface DictionaryLayer {
|
||||
val dictionary: EditableDictionary
|
||||
val name: @Nls String
|
||||
@@ -78,10 +42,10 @@ class PlatformSettingsDictionaryLayersProvider : DictionaryLayersProvider {
|
||||
|
||||
class ProjectDictionaryLayer(val project: Project) : DictionaryLayer {
|
||||
companion object {
|
||||
val name = SpellCheckerBundle.message("dictionary.name.project.level")
|
||||
val name = SpellCheckerBundle.messagePointer("dictionary.name.project.level")
|
||||
}
|
||||
|
||||
override val name = Companion.name
|
||||
override val name = Companion.name.get()
|
||||
override val dictionary: ProjectDictionary = project.service<ProjectDictionaryState>().projectDictionary
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright 2000-2023 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.components.Service
|
||||
import com.intellij.util.application
|
||||
import com.intellij.util.messages.MessageBusConnection
|
||||
import com.intellij.util.messages.Topic
|
||||
|
||||
@Service(Service.Level.PROJECT)
|
||||
class DictionaryLayersChangesDispatcher {
|
||||
val publisher: DictionaryLayerChangesListener
|
||||
get() = application.messageBus.syncPublisher(DictionaryLayerChangesListener.topic)
|
||||
|
||||
fun register(subscriber: DictionaryLayerChangesListener): MessageBusConnection {
|
||||
val connection = application.messageBus.connect()
|
||||
connection.subscribe(DictionaryLayerChangesListener.topic, subscriber)
|
||||
return connection
|
||||
}
|
||||
}
|
||||
|
||||
interface DictionaryLayerChangesListener {
|
||||
companion object {
|
||||
@Topic.ProjectLevel
|
||||
val topic = Topic(DictionaryLayerChangesListener::class.java)
|
||||
}
|
||||
|
||||
fun layersChanged()
|
||||
}
|
||||
@@ -13,7 +13,7 @@ internal class SettingsTransferActivity : ProjectActivity {
|
||||
if (settings.isSettingsTransferred) {
|
||||
return
|
||||
}
|
||||
if (settings.isUseSingleDictionaryToSave && ProjectDictionaryLayer.name == settings.dictionaryToSave &&
|
||||
if (settings.isUseSingleDictionaryToSave && ProjectDictionaryLayer.name.get() == settings.dictionaryToSave &&
|
||||
project.getService(ProjectDictionaryState::class.java).projectDictionary.words.isEmpty()) {
|
||||
settings.dictionaryToSave = ApplicationDictionaryLayer.name
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class SpellCheckerSettings implements PersistentStateComponent<Elem
|
||||
private static final String RUNTIME_DICTIONARY_ATTR_NAME = "RuntimeDictionary";
|
||||
|
||||
private static final String DICTIONARY_TO_SAVE_ATTR_NAME = "DefaultDictionary";
|
||||
private static final String DEFAULT_DICTIONARY_TO_SAVE = ProjectDictionaryLayer.Companion.getName();
|
||||
private static final String DEFAULT_DICTIONARY_TO_SAVE = ProjectDictionaryLayer.Companion.getName().get();
|
||||
private static final String USE_SINGLE_DICT_ATTR_NAME = "UseSingleDictionary";
|
||||
private static final boolean DEFAULT_USE_SINGLE_DICT = true;
|
||||
private static final String SETTINGS_TRANSFERRED = "transferred";
|
||||
|
||||
Reference in New Issue
Block a user