Fix detekt issues
All checks were successful
Pull Request / build (pull_request) Successful in 3m37s

This commit is contained in:
Marvin Elsen 2024-09-28 20:08:18 +02:00
parent 62c57d1e85
commit 7add73fe28
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2
4 changed files with 69 additions and 65 deletions

View File

@ -3,10 +3,10 @@ package com.marvinelsen.willow
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.domain.SqliteDictionary
import com.marvinelsen.willow.ui.controllers.DetailsController
import com.marvinelsen.willow.ui.controllers.SearchResultsController
import com.marvinelsen.willow.ui.controllers.MainController
import com.marvinelsen.willow.ui.controllers.MenuController
import com.marvinelsen.willow.ui.controllers.SearchController
import com.marvinelsen.willow.ui.controllers.SearchResultsController
import com.marvinelsen.willow.ui.util.FindWordsService
import com.marvinelsen.willow.ui.util.SearchService
import javafx.application.Application

View File

@ -6,7 +6,6 @@ import javafx.beans.property.StringProperty
import javafx.collections.FXCollections
import javafx.collections.ObservableList
// TODO: Consider removing this class completely if no property is ever used directly
data class DictionaryEntryFx(
val traditionalProperty: StringProperty,
val simplifiedProperty: StringProperty,

View File

@ -46,7 +46,59 @@ class DetailsController(private val model: Model, private val config: Config) {
@FXML
@Suppress("UnusedPrivateMember")
private fun initialize() {
labelHeadword.textProperty().bind(
initializeLabelHeadword()
initializeTabPaneDetails()
initializeListViewWords()
initializeWebViewDefinition()
model.selectedEntry.addListener { _, _, newEntry ->
if (newEntry == null) return@addListener
when (tabPaneDetails.selectionModel.selectedItem.id) {
"tabWords" -> {
model.findWords()
}
else -> {}
}
webViewDefinition.engine.loadContent(newEntry.createCedictDefinitionHtml())
}
}
private fun initializeWebViewDefinition() {
webViewDefinition.apply {
engine.userStyleSheetLocation = this::class.java.getResource("/css/definitions.css")!!.toExternalForm()
}
}
private fun initializeListViewWords() {
listViewWords.apply {
cellFactory = DictionaryEntryCellFactory(resources, config)
items = model.wordsContaining
}
}
private fun initializeTabPaneDetails() {
tabPaneDetails.apply {
disableProperty().bind(Bindings.isNull(model.selectedEntry))
selectionModel.selectedItemProperty().addListener { _, _, selectedTab ->
if (model.selectedEntry.value == null) return@addListener
when (selectedTab.id) {
"tabWords" -> {
model.findWords()
}
else -> {}
}
}
}
}
private fun initializeLabelHeadword() {
labelHeadword.apply {
textProperty().bind(
Bindings.createStringBinding(
{
when (config.script.value!!) {
@ -58,57 +110,17 @@ class DetailsController(private val model: Model, private val config: Config) {
model.selectedEntry
)
)
labelHeadword
.styleProperty()
.bind(
Bindings.concat(
"-fx-font-size: ",
config.detailHeadwordFontSize.asString(),
"px;"
)
)
tabPaneDetails.disableProperty().bind(Bindings.isNull(model.selectedEntry))
listViewWords.cellFactory = DictionaryEntryCellFactory(resources, config)
listViewWords.items = model.wordsContaining
tabPaneDetails.selectionModel.selectedItemProperty().addListener { _, _, selectedTab ->
if (model.selectedEntry.value == null) return@addListener
when (selectedTab.id) {
"tabWords" -> {
model.findWords()
}
else -> {}
styleProperty().bind(Bindings.concat("-fx-font-size: ", config.detailHeadwordFontSize.asString(), "px;"))
}
}
webViewDefinition.apply {
isContextMenuEnabled = false
engine.userStyleSheetLocation =
this::class.java.getResource("/css/definitions.css")!!.toExternalForm()
}
model.selectedEntry.addListener { _, _, newValue ->
if (newValue == null) {
return@addListener
}
when (tabPaneDetails.selectionModel.selectedItem.id) {
"tabWords" -> {
model.findWords()
}
else -> {}
}
webViewDefinition.engine.loadContent(
createHTML().html {
private fun DictionaryEntryFx.createCedictDefinitionHtml() = createHTML().html {
body {
h1 {
+"CC-CEDICT"
}
ol {
for (definition in newValue.definitions) {
for (definition in this@createCedictDefinitionHtml.definitions) {
li {
+definition.joinToString(separator = "; ")
}
@ -116,7 +128,4 @@ class DetailsController(private val model: Model, private val config: Config) {
}
}
}
)
}
}
}

View File

@ -30,9 +30,6 @@ class PreferencesDialog(owner: Window?, config: Config) : Dialog<PreferencesDial
CHANGES, NO_CHANGES
}
@FXML
private lateinit var comboBoxPronunciationDetails: ComboBox<Pronunciation>
@FXML
private lateinit var comboBoxLocale: ComboBox<Locale>
@ -79,7 +76,6 @@ class PreferencesDialog(owner: Window?, config: Config) : Dialog<PreferencesDial
val root: DialogPane = loader.load()
dialogPane = root
// TODO: Use resource bundle string
title = "Settings"
isResizable = true