diff --git a/src/main/kotlin/com/marvinelsen/willow/Model.kt b/src/main/kotlin/com/marvinelsen/willow/Model.kt index 31e5fba..99088da 100644 --- a/src/main/kotlin/com/marvinelsen/willow/Model.kt +++ b/src/main/kotlin/com/marvinelsen/willow/Model.kt @@ -2,10 +2,8 @@ package com.marvinelsen.willow import com.marvinelsen.willow.domain.SearchMode import com.marvinelsen.willow.domain.SqliteDictionary -import com.marvinelsen.willow.ui.DictionaryEntryFx -import com.marvinelsen.willow.ui.SentenceFx -import com.marvinelsen.willow.ui.toDomain -import com.marvinelsen.willow.ui.toFx +import com.marvinelsen.willow.domain.entities.DictionaryEntry +import com.marvinelsen.willow.domain.entities.Sentence import com.marvinelsen.willow.ui.util.ClipboardHelper import javafx.beans.property.BooleanProperty import javafx.beans.property.ObjectProperty @@ -21,12 +19,12 @@ import kotlinx.coroutines.launch class Model( private val dictionary: SqliteDictionary, ) { - private val internalSelectedEntry: ObjectProperty = SimpleObjectProperty() - private val internalSearchResults: ObservableList = FXCollections.observableArrayList() - private val internalWordsBeginning: ObservableList = FXCollections.observableArrayList() - private val internalWordsContaining: ObservableList = FXCollections.observableArrayList() - private val internalCharacters: ObservableList = FXCollections.observableArrayList() - private val internalSentences: ObservableList = FXCollections.observableArrayList() + private val internalSelectedEntry: ObjectProperty = SimpleObjectProperty() + private val internalSearchResults: ObservableList = FXCollections.observableArrayList() + private val internalWordsBeginning: ObservableList = FXCollections.observableArrayList() + private val internalWordsContaining: ObservableList = FXCollections.observableArrayList() + private val internalCharacters: ObservableList = FXCollections.observableArrayList() + private val internalSentences: ObservableList = FXCollections.observableArrayList() private val internalIsSearching: BooleanProperty = SimpleBooleanProperty(false) private val internalIsFindingWordsBeginning: BooleanProperty = SimpleBooleanProperty(false) @@ -39,17 +37,17 @@ class Model( private val internalFinishedFindingCharacters: BooleanProperty = SimpleBooleanProperty(false) private val internalFinishedFindingSentences: BooleanProperty = SimpleBooleanProperty(false) - val selectedEntry: ReadOnlyObjectProperty = internalSelectedEntry + val selectedEntry: ReadOnlyObjectProperty = internalSelectedEntry - val searchResults: ObservableList = + val searchResults: ObservableList = FXCollections.unmodifiableObservableList(internalSearchResults) - val wordsBeginning: ObservableList = + val wordsBeginning: ObservableList = FXCollections.unmodifiableObservableList(internalWordsBeginning) - val wordsContaining: ObservableList = + val wordsContaining: ObservableList = FXCollections.unmodifiableObservableList(internalWordsContaining) - val characters: ObservableList = + val characters: ObservableList = FXCollections.unmodifiableObservableList(internalCharacters) - val sentences: ObservableList = + val sentences: ObservableList = FXCollections.unmodifiableObservableList(internalSentences) val isSearching: ReadOnlyBooleanProperty = internalIsSearching @@ -68,7 +66,7 @@ class Model( fun search(query: String, searchMode: SearchMode) { coroutineScope.launch { internalIsSearching.value = true - internalSearchResults.setAll(dictionary.search(query, searchMode).map { it.toFx() }) + internalSearchResults.setAll(dictionary.search(query, searchMode)) internalIsSearching.value = false } } @@ -78,8 +76,7 @@ class Model( internalIsFindingWordsBeginning.value = true internalWordsBeginning.setAll( dictionary - .findWordsBeginningWith(internalSelectedEntry.value.toDomain()) - .map { it.toFx() } + .findWordsBeginningWith(internalSelectedEntry.value) ) internalIsFindingWordsBeginning.value = false internalFinishedFindingWordsBeginning.value = true @@ -91,8 +88,7 @@ class Model( internalIsFindingWordsContaining.value = true internalWordsContaining.setAll( dictionary - .findWordsContaining(internalSelectedEntry.value.toDomain()) - .map { it.toFx() } + .findWordsContaining(internalSelectedEntry.value) ) internalIsFindingWordsContaining.value = false internalFinishedFindingWordsContaining.value = true @@ -104,8 +100,7 @@ class Model( internalIsFindingCharacters.value = true internalCharacters.setAll( dictionary - .findCharactersOf(internalSelectedEntry.value.toDomain()) - .map { it.toFx() } + .findCharactersOf(internalSelectedEntry.value) ) internalIsFindingCharacters.value = false internalFinishedFindingCharacters.value = true @@ -117,15 +112,14 @@ class Model( internalIsFindingSentences.value = true internalSentences.setAll( dictionary - .findExampleSentencesFor(internalSelectedEntry.value.toDomain()) - .map { it.toFx() } + .findExampleSentencesFor(internalSelectedEntry.value) ) internalIsFindingSentences.value = false internalFinishedFindingSentences.value = true } } - fun selectEntry(entry: DictionaryEntryFx) { + fun selectEntry(entry: DictionaryEntry) { internalWordsBeginning.setAll(emptyList()) internalWordsContaining.setAll(emptyList()) internalCharacters.setAll(emptyList()) @@ -140,10 +134,10 @@ class Model( } fun copyHeadwordOfSelectedEntry() { - ClipboardHelper.copyString(internalSelectedEntry.value.traditionalProperty.value) + ClipboardHelper.copyString(internalSelectedEntry.value.traditional) } fun copyPronunciationOfSelectedEntry() { - ClipboardHelper.copyString(internalSelectedEntry.value.pinyinWithToneMarksProperty.value) + ClipboardHelper.copyString(internalSelectedEntry.value.pinyinWithToneMarks) } } diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/Dictionary.kt b/src/main/kotlin/com/marvinelsen/willow/domain/Dictionary.kt index f56dc5c..1ab4da1 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/Dictionary.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/Dictionary.kt @@ -1,5 +1,8 @@ package com.marvinelsen.willow.domain +import com.marvinelsen.willow.domain.entities.DictionaryEntry +import com.marvinelsen.willow.domain.entities.Sentence + interface Dictionary { suspend fun search(query: String, searchMode: SearchMode): List diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt b/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt index c115e37..f50bbd5 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt @@ -8,6 +8,8 @@ import com.github.houbb.segment.support.segment.impl.Segments import com.github.houbb.segment.support.segment.mode.impl.SegmentModes import com.github.houbb.segment.support.segment.result.impl.SegmentResultHandlers import com.github.houbb.segment.support.tagging.pos.tag.impl.SegmentPosTaggings +import com.marvinelsen.willow.domain.entities.DictionaryEntry +import com.marvinelsen.willow.domain.entities.Sentence import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.json.Json diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt b/src/main/kotlin/com/marvinelsen/willow/domain/entities/DictionaryEntry.kt similarity index 63% rename from src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt rename to src/main/kotlin/com/marvinelsen/willow/domain/entities/DictionaryEntry.kt index b0da205..ad11b91 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/entities/DictionaryEntry.kt @@ -1,4 +1,7 @@ -package com.marvinelsen.willow.domain +package com.marvinelsen.willow.domain.entities + +import com.marvinelsen.willow.domain.entities.definitions.CrossStraitsDefinition +import com.marvinelsen.willow.domain.entities.definitions.MoedictDefinition data class DictionaryEntry( val traditional: String, diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/Sentence.kt b/src/main/kotlin/com/marvinelsen/willow/domain/entities/Sentence.kt similarity index 63% rename from src/main/kotlin/com/marvinelsen/willow/domain/Sentence.kt rename to src/main/kotlin/com/marvinelsen/willow/domain/entities/Sentence.kt index 54cda7b..232465e 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/Sentence.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/entities/Sentence.kt @@ -1,4 +1,4 @@ -package com.marvinelsen.willow.domain +package com.marvinelsen.willow.domain.entities data class Sentence( val traditional: String, diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/CrossStraitsDefinition.kt b/src/main/kotlin/com/marvinelsen/willow/domain/entities/definitions/CrossStraitsDefinition.kt similarity index 72% rename from src/main/kotlin/com/marvinelsen/willow/domain/CrossStraitsDefinition.kt rename to src/main/kotlin/com/marvinelsen/willow/domain/entities/definitions/CrossStraitsDefinition.kt index 6daccaa..ea7fa79 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/CrossStraitsDefinition.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/entities/definitions/CrossStraitsDefinition.kt @@ -1,4 +1,4 @@ -package com.marvinelsen.willow.domain +package com.marvinelsen.willow.domain.entities.definitions import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/MoedictDefinition.kt b/src/main/kotlin/com/marvinelsen/willow/domain/entities/definitions/MoedictDefinition.kt similarity index 88% rename from src/main/kotlin/com/marvinelsen/willow/domain/MoedictDefinition.kt rename to src/main/kotlin/com/marvinelsen/willow/domain/entities/definitions/MoedictDefinition.kt index bd9442b..e1fee97 100644 --- a/src/main/kotlin/com/marvinelsen/willow/domain/MoedictDefinition.kt +++ b/src/main/kotlin/com/marvinelsen/willow/domain/entities/definitions/MoedictDefinition.kt @@ -1,4 +1,4 @@ -package com.marvinelsen.willow.domain +package com.marvinelsen.willow.domain.entities.definitions import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt b/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt deleted file mode 100644 index 196f636..0000000 --- a/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.marvinelsen.willow.ui - -import com.marvinelsen.willow.domain.CrossStraitsDefinition -import com.marvinelsen.willow.domain.DictionaryEntry -import com.marvinelsen.willow.domain.MoedictDefinition -import javafx.beans.property.SimpleStringProperty -import javafx.beans.property.StringProperty -import javafx.collections.FXCollections -import javafx.collections.ObservableList - -data class DictionaryEntryFx( - val traditionalProperty: StringProperty, - val simplifiedProperty: StringProperty, - val pinyinWithToneMarksProperty: StringProperty, - val pinyinWithToneNumbersProperty: StringProperty, - val zhuyinProperty: StringProperty, - val cedictDefinitions: ObservableList>, - val crossStraitsDefinitions: ObservableList, - val moedictDefinitions: ObservableList, -) - -fun DictionaryEntry.toFx() = DictionaryEntryFx( - traditionalProperty = SimpleStringProperty(this.traditional), - simplifiedProperty = SimpleStringProperty(this.simplified), - pinyinWithToneMarksProperty = SimpleStringProperty(this.pinyinWithToneMarks), - pinyinWithToneNumbersProperty = SimpleStringProperty(this.pinyinWithToneNumbers), - zhuyinProperty = SimpleStringProperty(this.zhuyin), - cedictDefinitions = FXCollections.observableList(this.cedictDefinitions), - crossStraitsDefinitions = FXCollections.observableList(this.crossStraitsDefinitions), - moedictDefinitions = FXCollections.observableList(this.moedictDefinitions), -) - -fun DictionaryEntryFx.toDomain() = DictionaryEntry( - traditional = this.traditionalProperty.value, - simplified = this.simplifiedProperty.value, - pinyinWithToneMarks = this.pinyinWithToneMarksProperty.value, - pinyinWithToneNumbers = this.pinyinWithToneNumbersProperty.value, - zhuyin = this.zhuyinProperty.value, - cedictDefinitions = this.cedictDefinitions.toList(), - crossStraitsDefinitions = this.crossStraitsDefinitions.toList(), - moedictDefinitions = this.moedictDefinitions.toList(), -) diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/SentenceFx.kt b/src/main/kotlin/com/marvinelsen/willow/ui/SentenceFx.kt deleted file mode 100644 index 6776e38..0000000 --- a/src/main/kotlin/com/marvinelsen/willow/ui/SentenceFx.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.marvinelsen.willow.ui - -import com.marvinelsen.willow.domain.Sentence -import javafx.beans.property.SimpleStringProperty -import javafx.beans.property.StringProperty - -data class SentenceFx( - val traditionalProperty: StringProperty, - val simplifiedProperty: StringProperty, -) - -fun Sentence.toFx() = SentenceFx( - traditionalProperty = SimpleStringProperty(this.traditional), - simplifiedProperty = SimpleStringProperty(this.simplified), -) - -fun SentenceFx.toDomain() = Sentence( - traditional = this.traditionalProperty.value, - simplified = this.simplifiedProperty.value, -) diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/cells/DictionaryEntryCellFactory.kt b/src/main/kotlin/com/marvinelsen/willow/ui/cells/DictionaryEntryCellFactory.kt index 403e9bf..3ed6277 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/cells/DictionaryEntryCellFactory.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/cells/DictionaryEntryCellFactory.kt @@ -3,7 +3,7 @@ package com.marvinelsen.willow.ui.cells import com.marvinelsen.willow.config.Config import com.marvinelsen.willow.config.Pronunciation import com.marvinelsen.willow.config.Script -import com.marvinelsen.willow.ui.DictionaryEntryFx +import com.marvinelsen.willow.domain.entities.DictionaryEntry import com.marvinelsen.willow.ui.util.createContextMenuForEntry import javafx.application.HostServices import javafx.beans.binding.Bindings @@ -20,9 +20,9 @@ class DictionaryEntryCellFactory( private val resources: ResourceBundle, private val config: Config, private val hostServices: HostServices, -) : Callback, ListCell> { +) : Callback, ListCell> { - override fun call(listView: ListView): ListCell { + override fun call(listView: ListView): ListCell { val entryCell = EntryCell(resources, config, hostServices) entryCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING)) return entryCell @@ -37,7 +37,7 @@ private class EntryCell( private val resources: ResourceBundle, private val config: Config, private val hostServices: HostServices, -) : ListCell() { +) : ListCell() { private val labelHeadword by lazy { Label().apply { @@ -99,7 +99,7 @@ private class EntryCell( text = null } - override fun updateItem(entry: DictionaryEntryFx?, empty: Boolean) { + override fun updateItem(entry: DictionaryEntry?, empty: Boolean) { super.updateItem(entry, empty) if (empty || entry == null) { graphic = null @@ -109,8 +109,8 @@ private class EntryCell( Bindings.createStringBinding( { when (config.script.value!!) { - Script.SIMPLIFIED -> entry.simplifiedProperty.value - Script.TRADITIONAL -> entry.traditionalProperty.value + Script.SIMPLIFIED -> entry.simplified + Script.TRADITIONAL -> entry.traditional } }, config.script @@ -120,9 +120,9 @@ private class EntryCell( Bindings.createStringBinding( { when (config.searchResults.pronunciation.value!!) { - Pronunciation.PINYIN_WITH_TONE_MARKS -> entry.pinyinWithToneMarksProperty.value - Pronunciation.PINYIN_WITH_TONE_NUMBERS -> entry.pinyinWithToneNumbersProperty.value - Pronunciation.ZHUYIN -> entry.zhuyinProperty.value + Pronunciation.PINYIN_WITH_TONE_MARKS -> entry.pinyinWithToneMarks + Pronunciation.PINYIN_WITH_TONE_NUMBERS -> entry.pinyinWithToneNumbers + Pronunciation.ZHUYIN -> entry.zhuyin } }, config.searchResults.pronunciation diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/cells/SentenceCellFactory.kt b/src/main/kotlin/com/marvinelsen/willow/ui/cells/SentenceCellFactory.kt index 6883a76..c6e0d24 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/cells/SentenceCellFactory.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/cells/SentenceCellFactory.kt @@ -2,7 +2,7 @@ package com.marvinelsen.willow.ui.cells import com.marvinelsen.willow.config.Config import com.marvinelsen.willow.config.Script -import com.marvinelsen.willow.ui.SentenceFx +import com.marvinelsen.willow.domain.entities.Sentence import com.marvinelsen.willow.ui.util.createContextMenuForSentence import javafx.application.HostServices import javafx.beans.binding.Bindings @@ -17,9 +17,9 @@ class SentenceCellFactory( private val resources: ResourceBundle, private val config: Config, private val hostServices: HostServices, -) : Callback, ListCell> { +) : Callback, ListCell> { - override fun call(listView: ListView): ListCell { + override fun call(listView: ListView): ListCell { val sentenceCell = SentenceCell(resources, config, hostServices) sentenceCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING)) return sentenceCell @@ -34,7 +34,7 @@ private class SentenceCell( private val resources: ResourceBundle, private val config: Config, private val hostServices: HostServices, -) : ListCell() { +) : ListCell() { private val labelSentence by lazy { Label().apply { @@ -51,7 +51,7 @@ private class SentenceCell( text = null } - override fun updateItem(sentence: SentenceFx?, empty: Boolean) { + override fun updateItem(sentence: Sentence?, empty: Boolean) { super.updateItem(sentence, empty) if (empty || sentence == null) { graphic = null @@ -61,8 +61,8 @@ private class SentenceCell( Bindings.createStringBinding( { when (config.script.value!!) { - Script.SIMPLIFIED -> sentence.simplifiedProperty.value - Script.TRADITIONAL -> sentence.traditionalProperty.value + Script.SIMPLIFIED -> sentence.simplified + Script.TRADITIONAL -> sentence.traditional } }, config.script diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt index ef84eb7..2903430 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt @@ -4,8 +4,8 @@ import com.marvinelsen.willow.Model import com.marvinelsen.willow.config.Config import com.marvinelsen.willow.config.Pronunciation import com.marvinelsen.willow.config.Script -import com.marvinelsen.willow.ui.DictionaryEntryFx -import com.marvinelsen.willow.ui.SentenceFx +import com.marvinelsen.willow.domain.entities.DictionaryEntry +import com.marvinelsen.willow.domain.entities.Sentence import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory import com.marvinelsen.willow.ui.cells.SentenceCellFactory import com.marvinelsen.willow.ui.util.createContextMenuForEntry @@ -60,13 +60,13 @@ class DetailsController( private lateinit var webViewDefinition: WebView @FXML - private lateinit var listViewWordsContaining: ListView + private lateinit var listViewWordsContaining: ListView @FXML - private lateinit var listViewWordsBeginning: ListView + private lateinit var listViewWordsBeginning: ListView @FXML - private lateinit var listViewCharacters: ListView + private lateinit var listViewCharacters: ListView @FXML private lateinit var progressIndicatorCharacters: ProgressIndicator @@ -87,7 +87,7 @@ class DetailsController( private lateinit var labelNoWordsBeginningFound: Label @FXML - private lateinit var listViewSentences: ListView + private lateinit var listViewSentences: ListView @FXML private lateinit var progressIndicatorSentences: ProgressIndicator @@ -114,8 +114,8 @@ class DetailsController( { val selectedEntry = model.selectedEntry.value when (config.script.value!!) { - Script.SIMPLIFIED -> selectedEntry?.simplifiedProperty?.value - Script.TRADITIONAL -> selectedEntry?.traditionalProperty?.value + Script.SIMPLIFIED -> selectedEntry?.simplified + Script.TRADITIONAL -> selectedEntry?.traditional } }, config.script, @@ -139,20 +139,9 @@ class DetailsController( { val selectedEntry = model.selectedEntry.value when (config.details.pronunciation.value!!) { - Pronunciation.PINYIN_WITH_TONE_MARKS -> - selectedEntry - ?.pinyinWithToneMarksProperty - ?.value - - Pronunciation.PINYIN_WITH_TONE_NUMBERS -> - selectedEntry - ?.pinyinWithToneNumbersProperty - ?.value - - Pronunciation.ZHUYIN -> - selectedEntry - ?.zhuyinProperty - ?.value + Pronunciation.PINYIN_WITH_TONE_MARKS -> selectedEntry?.pinyinWithToneMarks + Pronunciation.PINYIN_WITH_TONE_NUMBERS -> selectedEntry?.pinyinWithToneNumbers + Pronunciation.ZHUYIN -> selectedEntry?.zhuyin } }, config.details.pronunciation, @@ -189,7 +178,7 @@ class DetailsController( tabCharacters.disableProperty().bind( Bindings.createBooleanBinding( { - (model.selectedEntry.value?.traditionalProperty?.value?.length ?: 0) < 2 + (model.selectedEntry.value?.traditional?.length ?: 0) < 2 }, model.selectedEntry ) @@ -299,7 +288,7 @@ class DetailsController( } } - private fun createDefinitionHtml(entry: DictionaryEntryFx) = createHTML().html { + private fun createDefinitionHtml(entry: DictionaryEntry) = createHTML().html { body { if (entry.cedictDefinitions.isNotEmpty()) { div(classes = "cedict-definition") { @@ -331,7 +320,7 @@ class DetailsController( } } -private fun DIV.cedictDefinition(entry: DictionaryEntryFx) = ol { +private fun DIV.cedictDefinition(entry: DictionaryEntry) = ol { for (definition in entry.cedictDefinitions) { li { +definition.joinToString(separator = "; ") @@ -339,7 +328,7 @@ private fun DIV.cedictDefinition(entry: DictionaryEntryFx) = ol { } } -private fun DIV.crossStraitsDefinition(entry: DictionaryEntryFx) = ol { +private fun DIV.crossStraitsDefinition(entry: DictionaryEntry) = ol { entry.crossStraitsDefinitions.forEach { definition -> li { span(classes = "definition") { @@ -358,7 +347,7 @@ private fun DIV.crossStraitsDefinition(entry: DictionaryEntryFx) = ol { } } -private fun DIV.moeDefinition(entry: DictionaryEntryFx) = +private fun DIV.moeDefinition(entry: DictionaryEntry) = entry.moedictDefinitions.groupBy { it.type ?: "" }.entries.forEach { (type, definitions) -> if (type != "") { span(classes = "type") { diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchResultsController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchResultsController.kt index abc2456..0c7f876 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchResultsController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchResultsController.kt @@ -2,7 +2,7 @@ package com.marvinelsen.willow.ui.controllers import com.marvinelsen.willow.Model import com.marvinelsen.willow.config.Config -import com.marvinelsen.willow.ui.DictionaryEntryFx +import com.marvinelsen.willow.domain.entities.DictionaryEntry import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory import javafx.application.HostServices import javafx.beans.binding.Bindings @@ -29,7 +29,7 @@ class SearchResultsController( private lateinit var labelNoEntriesFound: Label @FXML - private lateinit var listViewSearchResults: ListView + private lateinit var listViewSearchResults: ListView @FXML @Suppress("UnusedPrivateMember") @@ -45,7 +45,7 @@ class SearchResultsController( .visibleProperty() .bind(Bindings.and(Bindings.isEmpty(model.searchResults), Bindings.not(model.isSearching))) - listViewSearchResults.selectionModel.selectedItemProperty().addListener { _, _, newValue: DictionaryEntryFx? -> + listViewSearchResults.selectionModel.selectedItemProperty().addListener { _, _, newValue: DictionaryEntry? -> if (newValue == null) { return@addListener } diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt b/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt index b24663f..79bb1de 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt @@ -1,7 +1,7 @@ package com.marvinelsen.willow.ui.util -import com.marvinelsen.willow.ui.DictionaryEntryFx -import com.marvinelsen.willow.ui.SentenceFx +import com.marvinelsen.willow.domain.entities.DictionaryEntry +import com.marvinelsen.willow.domain.entities.Sentence import javafx.application.HostServices import javafx.event.EventHandler import javafx.scene.control.ContextMenu @@ -11,24 +11,24 @@ import java.nio.charset.StandardCharsets import java.util.ResourceBundle fun createContextMenuForEntry( - entry: DictionaryEntryFx, + entry: DictionaryEntry, resourceBundle: ResourceBundle, hostServices: HostServices, ) = ContextMenu().apply { val menuItemCopyHeadword = MenuItem(resourceBundle.getString("menubar.edit.copy.headword")).apply { - onAction = EventHandler { ClipboardHelper.copyString(entry.traditionalProperty.value) } + onAction = EventHandler { ClipboardHelper.copyString(entry.traditional) } } val menuItemCopyPronunciation = MenuItem(resourceBundle.getString("menubar.edit.copy.pronunciation")).apply { - onAction = EventHandler { ClipboardHelper.copyString(entry.pinyinWithToneMarksProperty.value) } + onAction = EventHandler { ClipboardHelper.copyString(entry.pinyinWithToneMarks) } } val menuItemSearchOnWeb = MenuItem(resourceBundle.getString("menubar.edit.search-web")).apply { onAction = EventHandler { - val query = URLEncoder.encode(entry.traditionalProperty.value, StandardCharsets.UTF_8) + val query = URLEncoder.encode(entry.traditional, StandardCharsets.UTF_8) hostServices.showDocument("https://duckduckgo.com/?q=$query") } } @@ -37,19 +37,19 @@ fun createContextMenuForEntry( } fun createContextMenuForSentence( - sentence: SentenceFx, + sentence: Sentence, resourceBundle: ResourceBundle, hostServices: HostServices, ) = ContextMenu().apply { val menuItemCopySentence = MenuItem(resourceBundle.getString("menubar.edit.copy.sentence")).apply { - onAction = EventHandler { ClipboardHelper.copyString(sentence.traditionalProperty.value) } + onAction = EventHandler { ClipboardHelper.copyString(sentence.traditional) } } val menuItemSearchOnWeb = MenuItem(resourceBundle.getString("menubar.edit.search-web")).apply { onAction = EventHandler { - val query = URLEncoder.encode(sentence.traditionalProperty.value, StandardCharsets.UTF_8) + val query = URLEncoder.encode(sentence.traditional, StandardCharsets.UTF_8) hostServices.showDocument("https://duckduckgo.com/?q=$query") } }