New Features #1
@ -19,7 +19,7 @@ import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
class Model(
|
||||
class State(
|
||||
private val dictionary: SqliteDictionary,
|
||||
private val undoManager: UndoManager,
|
||||
) {
|
@ -43,7 +43,7 @@ class WillowApplication : Application() {
|
||||
}
|
||||
val dictionary = SqliteDictionary(connection)
|
||||
val undoManager = UndoManager()
|
||||
val model = Model(
|
||||
val state = State(
|
||||
dictionary,
|
||||
undoManager
|
||||
)
|
||||
@ -56,11 +56,11 @@ class WillowApplication : Application() {
|
||||
fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", config.locale.value)
|
||||
fxmlLoader.controllerFactory = Callback { type ->
|
||||
when (type) {
|
||||
MainController::class.java -> MainController(model)
|
||||
MenuController::class.java -> MenuController(model, config)
|
||||
DetailsController::class.java -> DetailsController(model, config, hostServices)
|
||||
SearchController::class.java -> SearchController(model)
|
||||
SearchResultsController::class.java -> SearchResultsController(model, config, hostServices)
|
||||
MainController::class.java -> MainController(state)
|
||||
MenuController::class.java -> MenuController(state, config)
|
||||
DetailsController::class.java -> DetailsController(state, config, hostServices)
|
||||
SearchController::class.java -> SearchController(state)
|
||||
SearchResultsController::class.java -> SearchResultsController(state, config, hostServices)
|
||||
else -> error("Trying to instantiate unknown controller type $type")
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.marvinelsen.willow.ui.controllers
|
||||
|
||||
import com.marvinelsen.willow.Model
|
||||
import com.marvinelsen.willow.State
|
||||
import com.marvinelsen.willow.config.Config
|
||||
import com.marvinelsen.willow.config.Pronunciation
|
||||
import com.marvinelsen.willow.config.Script
|
||||
@ -33,7 +33,7 @@ import java.util.ResourceBundle
|
||||
|
||||
@Suppress("UnusedPrivateMember", "TooManyFunctions")
|
||||
class DetailsController(
|
||||
private val model: Model,
|
||||
private val state: State,
|
||||
private val config: Config,
|
||||
private val hostServices: HostServices,
|
||||
) {
|
||||
@ -112,14 +112,14 @@ class DetailsController(
|
||||
textProperty().bind(
|
||||
Bindings.createStringBinding(
|
||||
{
|
||||
val selectedEntry = model.selectedEntry.value
|
||||
val selectedEntry = state.selectedEntry.value
|
||||
when (config.script.value!!) {
|
||||
Script.SIMPLIFIED -> selectedEntry?.simplified
|
||||
Script.TRADITIONAL -> selectedEntry?.traditional
|
||||
}
|
||||
},
|
||||
config.script,
|
||||
model.selectedEntry
|
||||
state.selectedEntry
|
||||
)
|
||||
)
|
||||
styleProperty().bind(
|
||||
@ -137,7 +137,7 @@ class DetailsController(
|
||||
textProperty().bind(
|
||||
Bindings.createStringBinding(
|
||||
{
|
||||
val selectedEntry = model.selectedEntry.value
|
||||
val selectedEntry = state.selectedEntry.value
|
||||
when (config.details.pronunciation.value!!) {
|
||||
Pronunciation.PINYIN_WITH_TONE_MARKS -> selectedEntry?.pinyinWithToneMarks
|
||||
Pronunciation.PINYIN_WITH_TONE_NUMBERS -> selectedEntry?.pinyinWithToneNumbers
|
||||
@ -145,7 +145,7 @@ class DetailsController(
|
||||
}
|
||||
},
|
||||
config.details.pronunciation,
|
||||
model.selectedEntry
|
||||
state.selectedEntry
|
||||
)
|
||||
)
|
||||
styleProperty().bind(
|
||||
@ -160,16 +160,16 @@ class DetailsController(
|
||||
|
||||
private fun initializeTabPaneDetails() {
|
||||
tabPaneDetails.apply {
|
||||
disableProperty().bind(Bindings.isNull(model.selectedEntry))
|
||||
disableProperty().bind(Bindings.isNull(state.selectedEntry))
|
||||
|
||||
selectionModel.selectedItemProperty().addListener { _, _, selectedTab ->
|
||||
if (model.selectedEntry.value == null) return@addListener
|
||||
if (state.selectedEntry.value == null) return@addListener
|
||||
|
||||
lazyUpdateTabContent(selectedTab.id)
|
||||
}
|
||||
}
|
||||
|
||||
model.selectedEntry.addListener { _, _, newEntry ->
|
||||
state.selectedEntry.addListener { _, _, newEntry ->
|
||||
if (newEntry == null) return@addListener
|
||||
|
||||
tabPaneDetails.selectionModel.select(0)
|
||||
@ -178,9 +178,9 @@ class DetailsController(
|
||||
tabCharacters.disableProperty().bind(
|
||||
Bindings.createBooleanBinding(
|
||||
{
|
||||
(model.selectedEntry.value?.traditional?.length ?: 0) < 2
|
||||
(state.selectedEntry.value?.traditional?.length ?: 0) < 2
|
||||
},
|
||||
model.selectedEntry
|
||||
state.selectedEntry
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -188,68 +188,68 @@ class DetailsController(
|
||||
private fun initializeListViewSentences() {
|
||||
listViewSentences.apply {
|
||||
cellFactory = SentenceCellFactory(resources, config, hostServices)
|
||||
items = model.sentences
|
||||
items = state.sentences
|
||||
|
||||
disableProperty().bind(Bindings.or(model.isFindingSentences, Bindings.isEmpty(model.sentences)))
|
||||
disableProperty().bind(Bindings.or(state.isFindingSentences, Bindings.isEmpty(state.sentences)))
|
||||
}
|
||||
progressIndicatorSentences.visibleProperty().bind(model.isFindingSentences)
|
||||
progressIndicatorSentences.visibleProperty().bind(state.isFindingSentences)
|
||||
labelNoSentencesFound
|
||||
.visibleProperty()
|
||||
.bind(Bindings.and(Bindings.isEmpty(model.sentences), Bindings.not(model.isFindingSentences)))
|
||||
.bind(Bindings.and(Bindings.isEmpty(state.sentences), Bindings.not(state.isFindingSentences)))
|
||||
}
|
||||
|
||||
private fun initializeListViewWordsContaining() {
|
||||
listViewWordsContaining.apply {
|
||||
cellFactory = DictionaryEntryCellFactory(resources, config, hostServices)
|
||||
items = model.wordsContaining
|
||||
items = state.wordsContaining
|
||||
|
||||
disableProperty().bind(Bindings.or(model.isFindingWordsContaining, Bindings.isEmpty(model.wordsContaining)))
|
||||
disableProperty().bind(Bindings.or(state.isFindingWordsContaining, Bindings.isEmpty(state.wordsContaining)))
|
||||
|
||||
selectionModel.selectedItemProperty().addListener { _, _, newEntry ->
|
||||
if (newEntry == null) return@addListener
|
||||
model.deepDive(newEntry)
|
||||
state.deepDive(newEntry)
|
||||
}
|
||||
}
|
||||
progressIndicatorWordsContaining.visibleProperty().bind(model.isFindingWordsContaining)
|
||||
progressIndicatorWordsContaining.visibleProperty().bind(state.isFindingWordsContaining)
|
||||
labelNoWordsContainingFound
|
||||
.visibleProperty()
|
||||
.bind(Bindings.and(Bindings.isEmpty(model.wordsContaining), Bindings.not(model.isFindingWordsContaining)))
|
||||
.bind(Bindings.and(Bindings.isEmpty(state.wordsContaining), Bindings.not(state.isFindingWordsContaining)))
|
||||
}
|
||||
|
||||
private fun initializeListViewWordsBeginning() {
|
||||
listViewWordsBeginning.apply {
|
||||
cellFactory = DictionaryEntryCellFactory(resources, config, hostServices)
|
||||
items = model.wordsBeginning
|
||||
items = state.wordsBeginning
|
||||
|
||||
disableProperty().bind(Bindings.or(model.isFindingWordsBeginning, Bindings.isEmpty(model.wordsBeginning)))
|
||||
disableProperty().bind(Bindings.or(state.isFindingWordsBeginning, Bindings.isEmpty(state.wordsBeginning)))
|
||||
|
||||
selectionModel.selectedItemProperty().addListener { _, _, newEntry ->
|
||||
if (newEntry == null) return@addListener
|
||||
model.deepDive(newEntry)
|
||||
state.deepDive(newEntry)
|
||||
}
|
||||
}
|
||||
progressIndicatorWordsBeginning.visibleProperty().bind(model.isFindingWordsBeginning)
|
||||
progressIndicatorWordsBeginning.visibleProperty().bind(state.isFindingWordsBeginning)
|
||||
labelNoWordsBeginningFound
|
||||
.visibleProperty()
|
||||
.bind(Bindings.and(Bindings.isEmpty(model.wordsBeginning), Bindings.not(model.isFindingWordsBeginning)))
|
||||
.bind(Bindings.and(Bindings.isEmpty(state.wordsBeginning), Bindings.not(state.isFindingWordsBeginning)))
|
||||
}
|
||||
|
||||
private fun initializeListViewCharacters() {
|
||||
listViewCharacters.apply {
|
||||
cellFactory = DictionaryEntryCellFactory(resources, config, hostServices)
|
||||
items = model.characters
|
||||
items = state.characters
|
||||
|
||||
disableProperty().bind(Bindings.or(model.isFindingCharacters, Bindings.isEmpty(model.characters)))
|
||||
disableProperty().bind(Bindings.or(state.isFindingCharacters, Bindings.isEmpty(state.characters)))
|
||||
|
||||
selectionModel.selectedItemProperty().addListener { _, _, newEntry ->
|
||||
if (newEntry == null) return@addListener
|
||||
model.deepDive(newEntry)
|
||||
state.deepDive(newEntry)
|
||||
}
|
||||
}
|
||||
progressIndicatorCharacters.visibleProperty().bind(model.isFindingCharacters)
|
||||
progressIndicatorCharacters.visibleProperty().bind(state.isFindingCharacters)
|
||||
labelNoCharactersFound
|
||||
.visibleProperty()
|
||||
.bind(Bindings.and(Bindings.isEmpty(model.characters), Bindings.not(model.isFindingCharacters)))
|
||||
.bind(Bindings.and(Bindings.isEmpty(state.characters), Bindings.not(state.isFindingCharacters)))
|
||||
}
|
||||
|
||||
private fun initializeWebViewDefinition() {
|
||||
@ -257,7 +257,7 @@ class DetailsController(
|
||||
engine.userStyleSheetLocation = this::class.java.getResource("/css/definitions.css")!!.toExternalForm()
|
||||
}
|
||||
|
||||
model.selectedEntry.addListener { _, _, newEntry ->
|
||||
state.selectedEntry.addListener { _, _, newEntry ->
|
||||
if (newEntry == null) return@addListener
|
||||
|
||||
webViewDefinition.engine.loadContent(createDefinitionHtml(newEntry))
|
||||
@ -266,9 +266,9 @@ class DetailsController(
|
||||
|
||||
@FXML
|
||||
private fun headerOnContextMenuRequested(contextMenuEvent: ContextMenuEvent) {
|
||||
if (model.selectedEntry.value == null) return
|
||||
if (state.selectedEntry.value == null) return
|
||||
|
||||
createContextMenuForEntry(model.selectedEntry.value, resources, hostServices).show(
|
||||
createContextMenuForEntry(state.selectedEntry.value, resources, hostServices).show(
|
||||
flowPaneHeader.scene.window,
|
||||
contextMenuEvent.screenX,
|
||||
contextMenuEvent.screenY
|
||||
@ -279,24 +279,24 @@ class DetailsController(
|
||||
private fun lazyUpdateTabContent(selectedTabId: String?) {
|
||||
when (selectedTabId) {
|
||||
"tabWords" -> {
|
||||
if (!model.finishedFindingWordsContaining.value) {
|
||||
model.findWordsContaining()
|
||||
if (!state.finishedFindingWordsContaining.value) {
|
||||
state.findWordsContaining()
|
||||
}
|
||||
if (!model.finishedFindingWordsBeginning.value) {
|
||||
model.findWordsBeginning()
|
||||
if (!state.finishedFindingWordsBeginning.value) {
|
||||
state.findWordsBeginning()
|
||||
}
|
||||
}
|
||||
|
||||
"tabCharacters" -> {
|
||||
if (model.finishedFindingCharacters.value) return
|
||||
if (state.finishedFindingCharacters.value) return
|
||||
|
||||
model.findCharacters()
|
||||
state.findCharacters()
|
||||
}
|
||||
|
||||
"tabSentences" -> {
|
||||
if (model.finishedFindingSentences.value) return
|
||||
if (state.finishedFindingSentences.value) return
|
||||
|
||||
model.findSentences()
|
||||
state.findSentences()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.marvinelsen.willow.ui.controllers
|
||||
|
||||
import com.marvinelsen.willow.Model
|
||||
import com.marvinelsen.willow.State
|
||||
import javafx.fxml.FXML
|
||||
|
||||
@Suppress("UnusedPrivateProperty", "UnusedPrivateMember")
|
||||
class MainController(private val model: Model) {
|
||||
class MainController(private val state: State) {
|
||||
@FXML
|
||||
private fun initialize() {
|
||||
// no-op
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.marvinelsen.willow.ui.controllers
|
||||
|
||||
import com.marvinelsen.willow.Model
|
||||
import com.marvinelsen.willow.State
|
||||
import com.marvinelsen.willow.config.Config
|
||||
import com.marvinelsen.willow.ui.dialogs.PreferencesDialog
|
||||
import javafx.application.Platform
|
||||
@ -11,7 +11,7 @@ import javafx.scene.control.MenuItem
|
||||
import java.util.ResourceBundle
|
||||
|
||||
@Suppress("UnusedPrivateMember")
|
||||
class MenuController(private val model: Model, private val config: Config) {
|
||||
class MenuController(private val state: State, private val config: Config) {
|
||||
@FXML
|
||||
private lateinit var resources: ResourceBundle
|
||||
|
||||
@ -26,8 +26,8 @@ class MenuController(private val model: Model, private val config: Config) {
|
||||
|
||||
@FXML
|
||||
private fun initialize() {
|
||||
menuItemCopyPronunciation.disableProperty().bind(Bindings.isNull(model.selectedEntry))
|
||||
menuItemCopyHeadword.disableProperty().bind(Bindings.isNull(model.selectedEntry))
|
||||
menuItemCopyPronunciation.disableProperty().bind(Bindings.isNull(state.selectedEntry))
|
||||
menuItemCopyHeadword.disableProperty().bind(Bindings.isNull(state.selectedEntry))
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -47,11 +47,11 @@ class MenuController(private val model: Model, private val config: Config) {
|
||||
|
||||
@FXML
|
||||
private fun onMenuItemCopyPronunciationAction() {
|
||||
model.copyPronunciationOfSelectedEntry()
|
||||
state.copyPronunciationOfSelectedEntry()
|
||||
}
|
||||
|
||||
@FXML
|
||||
private fun onMenuItemCopyHeadwordAction() {
|
||||
model.copyHeadwordOfSelectedEntry()
|
||||
state.copyHeadwordOfSelectedEntry()
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.marvinelsen.willow.ui.controllers
|
||||
|
||||
import com.marvinelsen.willow.Model
|
||||
import com.marvinelsen.willow.State
|
||||
import com.marvinelsen.willow.domain.SearchMode
|
||||
import javafx.fxml.FXML
|
||||
import javafx.scene.control.Button
|
||||
import javafx.scene.control.TextField
|
||||
import javafx.scene.control.ToggleGroup
|
||||
|
||||
class SearchController(private val model: Model) {
|
||||
class SearchController(private val state: State) {
|
||||
@FXML
|
||||
private lateinit var buttonUndo: Button
|
||||
|
||||
@ -26,8 +26,8 @@ class SearchController(private val model: Model) {
|
||||
textFieldSearch.textProperty().addListener { _, _, _ -> search() }
|
||||
searchModeToggleGroup.selectedToggleProperty().addListener { _, _, _ -> search() }
|
||||
|
||||
buttonUndo.disableProperty().bind(model.canUndo.not())
|
||||
buttonRedo.disableProperty().bind(model.canRedo.not())
|
||||
buttonUndo.disableProperty().bind(state.canUndo.not())
|
||||
buttonRedo.disableProperty().bind(state.canRedo.not())
|
||||
}
|
||||
|
||||
private fun search() {
|
||||
@ -38,14 +38,14 @@ class SearchController(private val model: Model) {
|
||||
return
|
||||
}
|
||||
|
||||
model.search(searchQuery, searchMode)
|
||||
state.search(searchQuery, searchMode)
|
||||
}
|
||||
|
||||
fun onButtonRedoAction() {
|
||||
model.redoSelection()
|
||||
state.redoSelection()
|
||||
}
|
||||
|
||||
fun onButtonUndoAction() {
|
||||
model.undoSelection()
|
||||
state.undoSelection()
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.marvinelsen.willow.ui.controllers
|
||||
|
||||
import com.marvinelsen.willow.Model
|
||||
import com.marvinelsen.willow.State
|
||||
import com.marvinelsen.willow.config.Config
|
||||
import com.marvinelsen.willow.domain.entities.DictionaryEntry
|
||||
import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory
|
||||
@ -13,7 +13,7 @@ import javafx.scene.control.ProgressIndicator
|
||||
import java.util.ResourceBundle
|
||||
|
||||
class SearchResultsController(
|
||||
private val model: Model,
|
||||
private val state: State,
|
||||
private val config: Config,
|
||||
private val hostServices: HostServices,
|
||||
) {
|
||||
@ -35,21 +35,21 @@ class SearchResultsController(
|
||||
@Suppress("UnusedPrivateMember")
|
||||
private fun initialize() {
|
||||
listViewSearchResults.cellFactory = DictionaryEntryCellFactory(resources, config, hostServices)
|
||||
listViewSearchResults.items = model.searchResults
|
||||
listViewSearchResults.items = state.searchResults
|
||||
listViewSearchResults
|
||||
.disableProperty()
|
||||
.bind(Bindings.or(model.isSearching, Bindings.isEmpty(model.searchResults)))
|
||||
.bind(Bindings.or(state.isSearching, Bindings.isEmpty(state.searchResults)))
|
||||
|
||||
progressIndicatorEntries.visibleProperty().bind(model.isSearching)
|
||||
progressIndicatorEntries.visibleProperty().bind(state.isSearching)
|
||||
labelNoEntriesFound
|
||||
.visibleProperty()
|
||||
.bind(Bindings.and(Bindings.isEmpty(model.searchResults), Bindings.not(model.isSearching)))
|
||||
.bind(Bindings.and(Bindings.isEmpty(state.searchResults), Bindings.not(state.isSearching)))
|
||||
|
||||
listViewSearchResults.selectionModel.selectedItemProperty().addListener { _, _, newValue: DictionaryEntry? ->
|
||||
if (newValue == null) {
|
||||
return@addListener
|
||||
}
|
||||
model.normalSelect(newValue)
|
||||
state.normalSelect(newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user