Compare commits
No commits in common. "baa4b9bd1a80247c119793b49e5875d78f5da450" and "cfff342a3afa429b1dd6194f4a5dd864df58474d" have entirely different histories.
baa4b9bd1a
...
cfff342a3a
@ -34,11 +34,6 @@ class Model(
|
|||||||
private val internalIsFindingCharacters: BooleanProperty = SimpleBooleanProperty(false)
|
private val internalIsFindingCharacters: BooleanProperty = SimpleBooleanProperty(false)
|
||||||
private val internalIsFindingSentences: BooleanProperty = SimpleBooleanProperty(false)
|
private val internalIsFindingSentences: BooleanProperty = SimpleBooleanProperty(false)
|
||||||
|
|
||||||
private val internalFinishedFindingWordsBeginning: BooleanProperty = SimpleBooleanProperty(false)
|
|
||||||
private val internalFinishedFindingWordsContaining: BooleanProperty = SimpleBooleanProperty(false)
|
|
||||||
private val internalFinishedFindingCharacters: BooleanProperty = SimpleBooleanProperty(false)
|
|
||||||
private val internalFinishedFindingSentences: BooleanProperty = SimpleBooleanProperty(false)
|
|
||||||
|
|
||||||
val selectedEntry: ReadOnlyObjectProperty<DictionaryEntryFx> = internalSelectedEntry
|
val selectedEntry: ReadOnlyObjectProperty<DictionaryEntryFx> = internalSelectedEntry
|
||||||
|
|
||||||
val searchResults: ObservableList<DictionaryEntryFx> =
|
val searchResults: ObservableList<DictionaryEntryFx> =
|
||||||
@ -58,11 +53,6 @@ class Model(
|
|||||||
val isFindingCharacters: ReadOnlyBooleanProperty = internalIsFindingCharacters
|
val isFindingCharacters: ReadOnlyBooleanProperty = internalIsFindingCharacters
|
||||||
val isFindingSentences: ReadOnlyBooleanProperty = internalIsFindingSentences
|
val isFindingSentences: ReadOnlyBooleanProperty = internalIsFindingSentences
|
||||||
|
|
||||||
val finishedFindingWordsBeginning: ReadOnlyBooleanProperty = internalFinishedFindingWordsBeginning
|
|
||||||
val finishedFindingWordsContaining: ReadOnlyBooleanProperty = internalFinishedFindingWordsContaining
|
|
||||||
val finishedFindingCharacters: ReadOnlyBooleanProperty = internalFinishedFindingCharacters
|
|
||||||
val finishedFindingSentences: ReadOnlyBooleanProperty = internalFinishedFindingSentences
|
|
||||||
|
|
||||||
private val coroutineScope = MainScope()
|
private val coroutineScope = MainScope()
|
||||||
|
|
||||||
fun search(query: String, searchMode: SearchMode) {
|
fun search(query: String, searchMode: SearchMode) {
|
||||||
@ -82,7 +72,6 @@ class Model(
|
|||||||
.map { it.toFx() }
|
.map { it.toFx() }
|
||||||
)
|
)
|
||||||
internalIsFindingWordsBeginning.value = false
|
internalIsFindingWordsBeginning.value = false
|
||||||
internalFinishedFindingWordsBeginning.value = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +84,6 @@ class Model(
|
|||||||
.map { it.toFx() }
|
.map { it.toFx() }
|
||||||
)
|
)
|
||||||
internalIsFindingWordsContaining.value = false
|
internalIsFindingWordsContaining.value = false
|
||||||
internalFinishedFindingWordsContaining.value = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +96,6 @@ class Model(
|
|||||||
.map { it.toFx() }
|
.map { it.toFx() }
|
||||||
)
|
)
|
||||||
internalIsFindingCharacters.value = false
|
internalIsFindingCharacters.value = false
|
||||||
internalFinishedFindingCharacters.value = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +108,6 @@ class Model(
|
|||||||
.map { it.toFx() }
|
.map { it.toFx() }
|
||||||
)
|
)
|
||||||
internalIsFindingSentences.value = false
|
internalIsFindingSentences.value = false
|
||||||
internalFinishedFindingSentences.value = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,12 +116,6 @@ class Model(
|
|||||||
internalWordsContaining.setAll(emptyList())
|
internalWordsContaining.setAll(emptyList())
|
||||||
internalCharacters.setAll(emptyList())
|
internalCharacters.setAll(emptyList())
|
||||||
internalSentences.setAll(emptyList())
|
internalSentences.setAll(emptyList())
|
||||||
|
|
||||||
internalFinishedFindingCharacters.value = false
|
|
||||||
internalFinishedFindingWordsBeginning.value = false
|
|
||||||
internalFinishedFindingWordsContaining.value = false
|
|
||||||
internalFinishedFindingSentences.value = false
|
|
||||||
|
|
||||||
internalSelectedEntry.value = entry
|
internalSelectedEntry.value = entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import com.marvinelsen.willow.ui.controllers.MenuController
|
|||||||
import com.marvinelsen.willow.ui.controllers.SearchController
|
import com.marvinelsen.willow.ui.controllers.SearchController
|
||||||
import com.marvinelsen.willow.ui.controllers.SearchResultsController
|
import com.marvinelsen.willow.ui.controllers.SearchResultsController
|
||||||
import javafx.application.Application
|
import javafx.application.Application
|
||||||
import javafx.application.HostServices
|
|
||||||
import javafx.fxml.FXMLLoader
|
import javafx.fxml.FXMLLoader
|
||||||
import javafx.scene.Scene
|
import javafx.scene.Scene
|
||||||
import javafx.scene.image.Image
|
import javafx.scene.image.Image
|
||||||
@ -47,17 +46,15 @@ class WillowApplication : Application() {
|
|||||||
val config = Config()
|
val config = Config()
|
||||||
config.load()
|
config.load()
|
||||||
|
|
||||||
val hostServices: HostServices = hostServices
|
|
||||||
|
|
||||||
val fxmlLoader = FXMLLoader()
|
val fxmlLoader = FXMLLoader()
|
||||||
fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", config.locale.value)
|
fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", config.locale.value)
|
||||||
fxmlLoader.controllerFactory = Callback { type ->
|
fxmlLoader.controllerFactory = Callback { type ->
|
||||||
when (type) {
|
when (type) {
|
||||||
MainController::class.java -> MainController(model)
|
MainController::class.java -> MainController(model)
|
||||||
MenuController::class.java -> MenuController(model, config)
|
MenuController::class.java -> MenuController(model, config)
|
||||||
DetailsController::class.java -> DetailsController(model, config, hostServices)
|
DetailsController::class.java -> DetailsController(model, config)
|
||||||
SearchController::class.java -> SearchController(model)
|
SearchController::class.java -> SearchController(model)
|
||||||
SearchResultsController::class.java -> SearchResultsController(model, config, hostServices)
|
SearchResultsController::class.java -> SearchResultsController(model, config)
|
||||||
else -> error("Trying to instantiate unknown controller type $type")
|
else -> error("Trying to instantiate unknown controller type $type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import com.marvinelsen.willow.config.Pronunciation
|
|||||||
import com.marvinelsen.willow.config.Script
|
import com.marvinelsen.willow.config.Script
|
||||||
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
||||||
import com.marvinelsen.willow.ui.util.createContextMenuForEntry
|
import com.marvinelsen.willow.ui.util.createContextMenuForEntry
|
||||||
import javafx.application.HostServices
|
|
||||||
import javafx.beans.binding.Bindings
|
import javafx.beans.binding.Bindings
|
||||||
import javafx.geometry.VPos
|
import javafx.geometry.VPos
|
||||||
import javafx.scene.control.Label
|
import javafx.scene.control.Label
|
||||||
@ -16,14 +15,10 @@ import javafx.scene.layout.VBox
|
|||||||
import javafx.util.Callback
|
import javafx.util.Callback
|
||||||
import java.util.ResourceBundle
|
import java.util.ResourceBundle
|
||||||
|
|
||||||
class DictionaryEntryCellFactory(
|
class DictionaryEntryCellFactory(private val resources: ResourceBundle, private val config: Config) :
|
||||||
private val resources: ResourceBundle,
|
Callback<ListView<DictionaryEntryFx?>, ListCell<DictionaryEntryFx?>> {
|
||||||
private val config: Config,
|
|
||||||
private val hostServices: HostServices,
|
|
||||||
) : Callback<ListView<DictionaryEntryFx?>, ListCell<DictionaryEntryFx?>> {
|
|
||||||
|
|
||||||
override fun call(listView: ListView<DictionaryEntryFx?>): ListCell<DictionaryEntryFx?> {
|
override fun call(listView: ListView<DictionaryEntryFx?>): ListCell<DictionaryEntryFx?> {
|
||||||
val entryCell = EntryCell(resources, config, hostServices)
|
val entryCell = EntryCell(resources, config)
|
||||||
entryCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
|
entryCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
|
||||||
return entryCell
|
return entryCell
|
||||||
}
|
}
|
||||||
@ -33,12 +28,8 @@ class DictionaryEntryCellFactory(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EntryCell(
|
private class EntryCell(private val resources: ResourceBundle, private val config: Config) :
|
||||||
private val resources: ResourceBundle,
|
ListCell<DictionaryEntryFx?>() {
|
||||||
private val config: Config,
|
|
||||||
private val hostServices: HostServices,
|
|
||||||
) : ListCell<DictionaryEntryFx?>() {
|
|
||||||
|
|
||||||
private val labelHeadword = Label().apply {
|
private val labelHeadword = Label().apply {
|
||||||
styleClass.add("headword")
|
styleClass.add("headword")
|
||||||
styleProperty().bind(
|
styleProperty().bind(
|
||||||
@ -127,16 +118,14 @@ private class EntryCell(
|
|||||||
entry.crossStraitsDefinitions.isNotEmpty() -> entry.crossStraitsDefinitions.joinToString(
|
entry.crossStraitsDefinitions.isNotEmpty() -> entry.crossStraitsDefinitions.joinToString(
|
||||||
separator = " / "
|
separator = " / "
|
||||||
) { it.definition }
|
) { it.definition }
|
||||||
|
|
||||||
entry.moedictDefinitions.isNotEmpty() -> entry.moedictDefinitions.joinToString(
|
entry.moedictDefinitions.isNotEmpty() -> entry.moedictDefinitions.joinToString(
|
||||||
separator = " / "
|
separator = " / "
|
||||||
) { it.definition }
|
) { it.definition }
|
||||||
|
|
||||||
else -> error("No definition for entry")
|
else -> error("No definition for entry")
|
||||||
}
|
}
|
||||||
labelDefinition.text = definition
|
labelDefinition.text = definition
|
||||||
|
|
||||||
contextMenu = createContextMenuForEntry(entry, resources, hostServices)
|
contextMenu = createContextMenuForEntry(entry, resources)
|
||||||
graphic = root
|
graphic = root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,24 +3,17 @@ package com.marvinelsen.willow.ui.cells
|
|||||||
import com.marvinelsen.willow.config.Config
|
import com.marvinelsen.willow.config.Config
|
||||||
import com.marvinelsen.willow.config.Script
|
import com.marvinelsen.willow.config.Script
|
||||||
import com.marvinelsen.willow.ui.SentenceFx
|
import com.marvinelsen.willow.ui.SentenceFx
|
||||||
import com.marvinelsen.willow.ui.util.createContextMenuForSentence
|
|
||||||
import javafx.application.HostServices
|
|
||||||
import javafx.beans.binding.Bindings
|
import javafx.beans.binding.Bindings
|
||||||
import javafx.scene.control.Label
|
import javafx.scene.control.Label
|
||||||
import javafx.scene.control.ListCell
|
import javafx.scene.control.ListCell
|
||||||
import javafx.scene.control.ListView
|
import javafx.scene.control.ListView
|
||||||
import javafx.scene.layout.VBox
|
import javafx.scene.layout.VBox
|
||||||
import javafx.util.Callback
|
import javafx.util.Callback
|
||||||
import java.util.ResourceBundle
|
|
||||||
|
|
||||||
class SentenceCellFactory(
|
class SentenceCellFactory(private val config: Config) : Callback<ListView<SentenceFx?>, ListCell<SentenceFx?>> {
|
||||||
private val resources: ResourceBundle,
|
|
||||||
private val config: Config,
|
|
||||||
private val hostServices: HostServices,
|
|
||||||
) : Callback<ListView<SentenceFx?>, ListCell<SentenceFx?>> {
|
|
||||||
|
|
||||||
override fun call(listView: ListView<SentenceFx?>): ListCell<SentenceFx?> {
|
override fun call(listView: ListView<SentenceFx?>): ListCell<SentenceFx?> {
|
||||||
val sentenceCell = SentenceCell(resources, config, hostServices)
|
val sentenceCell = SentenceCell(config)
|
||||||
sentenceCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
|
sentenceCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
|
||||||
return sentenceCell
|
return sentenceCell
|
||||||
}
|
}
|
||||||
@ -30,12 +23,7 @@ class SentenceCellFactory(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SentenceCell(
|
private class SentenceCell(private val config: Config) : ListCell<SentenceFx?>() {
|
||||||
private val resources: ResourceBundle,
|
|
||||||
private val config: Config,
|
|
||||||
private val hostServices: HostServices,
|
|
||||||
) : ListCell<SentenceFx?>() {
|
|
||||||
|
|
||||||
private val labelSentence = Label().apply {
|
private val labelSentence = Label().apply {
|
||||||
styleClass.add("sentence")
|
styleClass.add("sentence")
|
||||||
isWrapText = true
|
isWrapText = true
|
||||||
@ -63,7 +51,6 @@ private class SentenceCell(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
contextMenu = createContextMenuForSentence(sentence, resources, hostServices)
|
|
||||||
graphic = root
|
graphic = root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import com.marvinelsen.willow.ui.SentenceFx
|
|||||||
import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory
|
import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory
|
||||||
import com.marvinelsen.willow.ui.cells.SentenceCellFactory
|
import com.marvinelsen.willow.ui.cells.SentenceCellFactory
|
||||||
import com.marvinelsen.willow.ui.util.createContextMenuForEntry
|
import com.marvinelsen.willow.ui.util.createContextMenuForEntry
|
||||||
import javafx.application.HostServices
|
|
||||||
import javafx.beans.binding.Bindings
|
import javafx.beans.binding.Bindings
|
||||||
import javafx.fxml.FXML
|
import javafx.fxml.FXML
|
||||||
import javafx.scene.control.Label
|
import javafx.scene.control.Label
|
||||||
@ -32,12 +31,7 @@ import kotlinx.html.stream.createHTML
|
|||||||
import java.util.ResourceBundle
|
import java.util.ResourceBundle
|
||||||
|
|
||||||
@Suppress("UnusedPrivateMember", "TooManyFunctions")
|
@Suppress("UnusedPrivateMember", "TooManyFunctions")
|
||||||
class DetailsController(
|
class DetailsController(private val model: Model, private val config: Config) {
|
||||||
private val model: Model,
|
|
||||||
private val config: Config,
|
|
||||||
private val hostServices: HostServices,
|
|
||||||
) {
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private lateinit var resources: ResourceBundle
|
private lateinit var resources: ResourceBundle
|
||||||
|
|
||||||
@ -198,7 +192,7 @@ class DetailsController(
|
|||||||
|
|
||||||
private fun initializeListViewSentences() {
|
private fun initializeListViewSentences() {
|
||||||
listViewSentences.apply {
|
listViewSentences.apply {
|
||||||
cellFactory = SentenceCellFactory(resources, config, hostServices)
|
cellFactory = SentenceCellFactory(config)
|
||||||
items = model.sentences
|
items = model.sentences
|
||||||
|
|
||||||
disableProperty().bind(Bindings.or(model.isFindingSentences, Bindings.isEmpty(model.sentences)))
|
disableProperty().bind(Bindings.or(model.isFindingSentences, Bindings.isEmpty(model.sentences)))
|
||||||
@ -211,7 +205,7 @@ class DetailsController(
|
|||||||
|
|
||||||
private fun initializeListViewWordsContaining() {
|
private fun initializeListViewWordsContaining() {
|
||||||
listViewWordsContaining.apply {
|
listViewWordsContaining.apply {
|
||||||
cellFactory = DictionaryEntryCellFactory(resources, config, hostServices)
|
cellFactory = DictionaryEntryCellFactory(resources, config)
|
||||||
items = model.wordsContaining
|
items = model.wordsContaining
|
||||||
|
|
||||||
disableProperty().bind(Bindings.or(model.isFindingWordsContaining, Bindings.isEmpty(model.wordsContaining)))
|
disableProperty().bind(Bindings.or(model.isFindingWordsContaining, Bindings.isEmpty(model.wordsContaining)))
|
||||||
@ -224,7 +218,7 @@ class DetailsController(
|
|||||||
|
|
||||||
private fun initializeListViewWordsBeginning() {
|
private fun initializeListViewWordsBeginning() {
|
||||||
listViewWordsBeginning.apply {
|
listViewWordsBeginning.apply {
|
||||||
cellFactory = DictionaryEntryCellFactory(resources, config, hostServices)
|
cellFactory = DictionaryEntryCellFactory(resources, config)
|
||||||
items = model.wordsBeginning
|
items = model.wordsBeginning
|
||||||
|
|
||||||
disableProperty().bind(Bindings.or(model.isFindingWordsBeginning, Bindings.isEmpty(model.wordsBeginning)))
|
disableProperty().bind(Bindings.or(model.isFindingWordsBeginning, Bindings.isEmpty(model.wordsBeginning)))
|
||||||
@ -237,7 +231,7 @@ class DetailsController(
|
|||||||
|
|
||||||
private fun initializeListViewCharacters() {
|
private fun initializeListViewCharacters() {
|
||||||
listViewCharacters.apply {
|
listViewCharacters.apply {
|
||||||
cellFactory = DictionaryEntryCellFactory(resources, config, hostServices)
|
cellFactory = DictionaryEntryCellFactory(resources, config)
|
||||||
items = model.characters
|
items = model.characters
|
||||||
|
|
||||||
disableProperty().bind(Bindings.or(model.isFindingCharacters, Bindings.isEmpty(model.characters)))
|
disableProperty().bind(Bindings.or(model.isFindingCharacters, Bindings.isEmpty(model.characters)))
|
||||||
@ -264,7 +258,7 @@ class DetailsController(
|
|||||||
private fun headerOnContextMenuRequested(contextMenuEvent: ContextMenuEvent) {
|
private fun headerOnContextMenuRequested(contextMenuEvent: ContextMenuEvent) {
|
||||||
if (model.selectedEntry.value == null) return
|
if (model.selectedEntry.value == null) return
|
||||||
|
|
||||||
createContextMenuForEntry(model.selectedEntry.value, resources, hostServices).show(
|
createContextMenuForEntry(model.selectedEntry.value, resources).show(
|
||||||
flowPaneHeader.scene.window,
|
flowPaneHeader.scene.window,
|
||||||
contextMenuEvent.screenX,
|
contextMenuEvent.screenX,
|
||||||
contextMenuEvent.screenY
|
contextMenuEvent.screenY
|
||||||
@ -275,22 +269,22 @@ class DetailsController(
|
|||||||
private fun lazyUpdateTabContent(selectedTabId: String?) {
|
private fun lazyUpdateTabContent(selectedTabId: String?) {
|
||||||
when (selectedTabId) {
|
when (selectedTabId) {
|
||||||
"tabWords" -> {
|
"tabWords" -> {
|
||||||
if (!model.finishedFindingWordsContaining.value) {
|
if (model.wordsContaining.isEmpty()) {
|
||||||
model.findWordsContaining()
|
model.findWordsContaining()
|
||||||
}
|
}
|
||||||
if (!model.finishedFindingWordsBeginning.value) {
|
if (model.wordsBeginning.isEmpty()) {
|
||||||
model.findWordsBeginning()
|
model.findWordsBeginning()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"tabCharacters" -> {
|
"tabCharacters" -> {
|
||||||
if (model.finishedFindingCharacters.value) return
|
if (model.characters.isNotEmpty()) return
|
||||||
|
|
||||||
model.findCharacters()
|
model.findCharacters()
|
||||||
}
|
}
|
||||||
|
|
||||||
"tabSentences" -> {
|
"tabSentences" -> {
|
||||||
if (model.finishedFindingSentences.value) return
|
if (model.sentences.isNotEmpty()) return
|
||||||
|
|
||||||
model.findSentences()
|
model.findSentences()
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import com.marvinelsen.willow.Model
|
|||||||
import com.marvinelsen.willow.config.Config
|
import com.marvinelsen.willow.config.Config
|
||||||
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
||||||
import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory
|
import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory
|
||||||
import javafx.application.HostServices
|
|
||||||
import javafx.beans.binding.Bindings
|
import javafx.beans.binding.Bindings
|
||||||
import javafx.fxml.FXML
|
import javafx.fxml.FXML
|
||||||
import javafx.scene.control.Label
|
import javafx.scene.control.Label
|
||||||
@ -12,12 +11,7 @@ import javafx.scene.control.ListView
|
|||||||
import javafx.scene.control.ProgressIndicator
|
import javafx.scene.control.ProgressIndicator
|
||||||
import java.util.ResourceBundle
|
import java.util.ResourceBundle
|
||||||
|
|
||||||
class SearchResultsController(
|
class SearchResultsController(private val model: Model, private val config: Config) {
|
||||||
private val model: Model,
|
|
||||||
private val config: Config,
|
|
||||||
private val hostServices: HostServices,
|
|
||||||
) {
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private lateinit var resources: ResourceBundle
|
private lateinit var resources: ResourceBundle
|
||||||
|
|
||||||
@ -34,7 +28,7 @@ class SearchResultsController(
|
|||||||
@FXML
|
@FXML
|
||||||
@Suppress("UnusedPrivateMember")
|
@Suppress("UnusedPrivateMember")
|
||||||
private fun initialize() {
|
private fun initialize() {
|
||||||
listViewSearchResults.cellFactory = DictionaryEntryCellFactory(resources, config, hostServices)
|
listViewSearchResults.cellFactory = DictionaryEntryCellFactory(resources, config)
|
||||||
listViewSearchResults.items = model.searchResults
|
listViewSearchResults.items = model.searchResults
|
||||||
listViewSearchResults
|
listViewSearchResults
|
||||||
.disableProperty()
|
.disableProperty()
|
||||||
|
@ -1,20 +1,12 @@
|
|||||||
package com.marvinelsen.willow.ui.util
|
package com.marvinelsen.willow.ui.util
|
||||||
|
|
||||||
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
||||||
import com.marvinelsen.willow.ui.SentenceFx
|
|
||||||
import javafx.application.HostServices
|
|
||||||
import javafx.event.EventHandler
|
import javafx.event.EventHandler
|
||||||
import javafx.scene.control.ContextMenu
|
import javafx.scene.control.ContextMenu
|
||||||
import javafx.scene.control.MenuItem
|
import javafx.scene.control.MenuItem
|
||||||
import java.net.URLEncoder
|
|
||||||
import java.nio.charset.StandardCharsets
|
|
||||||
import java.util.ResourceBundle
|
import java.util.ResourceBundle
|
||||||
|
|
||||||
fun createContextMenuForEntry(
|
fun createContextMenuForEntry(entry: DictionaryEntryFx, resourceBundle: ResourceBundle) = ContextMenu().apply {
|
||||||
entry: DictionaryEntryFx,
|
|
||||||
resourceBundle: ResourceBundle,
|
|
||||||
hostServices: HostServices,
|
|
||||||
) = ContextMenu().apply {
|
|
||||||
val menuItemCopyHeadword =
|
val menuItemCopyHeadword =
|
||||||
MenuItem(resourceBundle.getString("menubar.edit.copy.headword")).apply {
|
MenuItem(resourceBundle.getString("menubar.edit.copy.headword")).apply {
|
||||||
onAction = EventHandler { ClipboardHelper.copyString(entry.traditionalProperty.value) }
|
onAction = EventHandler { ClipboardHelper.copyString(entry.traditionalProperty.value) }
|
||||||
@ -25,34 +17,5 @@ fun createContextMenuForEntry(
|
|||||||
onAction = EventHandler { ClipboardHelper.copyString(entry.pinyinWithToneMarksProperty.value) }
|
onAction = EventHandler { ClipboardHelper.copyString(entry.pinyinWithToneMarksProperty.value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val menuItemSearchOnWeb =
|
items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation)
|
||||||
MenuItem(resourceBundle.getString("menubar.edit.search-web")).apply {
|
|
||||||
onAction = EventHandler {
|
|
||||||
val query = URLEncoder.encode(entry.traditionalProperty.value, StandardCharsets.UTF_8)
|
|
||||||
hostServices.showDocument("https://duckduckgo.com/?q=$query")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation, menuItemSearchOnWeb)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createContextMenuForSentence(
|
|
||||||
sentence: SentenceFx,
|
|
||||||
resourceBundle: ResourceBundle,
|
|
||||||
hostServices: HostServices,
|
|
||||||
) = ContextMenu().apply {
|
|
||||||
val menuItemCopySentence =
|
|
||||||
MenuItem(resourceBundle.getString("menubar.edit.copy.sentence")).apply {
|
|
||||||
onAction = EventHandler { ClipboardHelper.copyString(sentence.traditionalProperty.value) }
|
|
||||||
}
|
|
||||||
|
|
||||||
val menuItemSearchOnWeb =
|
|
||||||
MenuItem(resourceBundle.getString("menubar.edit.search-web")).apply {
|
|
||||||
onAction = EventHandler {
|
|
||||||
val query = URLEncoder.encode(sentence.traditionalProperty.value, StandardCharsets.UTF_8)
|
|
||||||
hostServices.showDocument("https://duckduckgo.com/?q=$query")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
items.addAll(menuItemCopySentence, menuItemSearchOnWeb)
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@ menubar.file.preferences=_Preferences…
|
|||||||
menubar.edit=_Edit
|
menubar.edit=_Edit
|
||||||
menubar.edit.copy.headword=Copy Headword
|
menubar.edit.copy.headword=Copy Headword
|
||||||
menubar.edit.copy.pronunciation=Copy Pronunciation
|
menubar.edit.copy.pronunciation=Copy Pronunciation
|
||||||
menubar.edit.copy.sentence=Copy Sentence
|
|
||||||
menubar.edit.search-web=Search on Web...
|
|
||||||
menubar.help=_Help
|
menubar.help=_Help
|
||||||
menubar.help.about=_About…
|
menubar.help.about=_About…
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ menubar.file.preferences=_Einstellungen…
|
|||||||
menubar.edit=_Bearbeiten
|
menubar.edit=_Bearbeiten
|
||||||
menubar.edit.copy.headword=Kopiere Wort
|
menubar.edit.copy.headword=Kopiere Wort
|
||||||
menubar.edit.copy.pronunciation=Kopiere Aussprache
|
menubar.edit.copy.pronunciation=Kopiere Aussprache
|
||||||
menubar.edit.copy.sentence=Copy Sentence
|
|
||||||
menubar.edit.search-web=Search on Web...
|
|
||||||
menubar.help=_Hilfe
|
menubar.help=_Hilfe
|
||||||
menubar.help.about=_Über…
|
menubar.help.about=_Über…
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ menubar.file.preferences=_Preferences…
|
|||||||
menubar.edit=_Edit
|
menubar.edit=_Edit
|
||||||
menubar.edit.copy.headword=Copy Headword
|
menubar.edit.copy.headword=Copy Headword
|
||||||
menubar.edit.copy.pronunciation=Copy Pronunciation
|
menubar.edit.copy.pronunciation=Copy Pronunciation
|
||||||
menubar.edit.copy.sentence=Copy Sentence
|
|
||||||
menubar.edit.search-web=Search on Web...
|
|
||||||
menubar.help=_Help
|
menubar.help=_Help
|
||||||
menubar.help.about=_About…
|
menubar.help.about=_About…
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ menubar.file.preferences=_設定…
|
|||||||
menubar.edit=_編輯
|
menubar.edit=_編輯
|
||||||
menubar.edit.copy.headword=複製 Wort
|
menubar.edit.copy.headword=複製 Wort
|
||||||
menubar.edit.copy.pronunciation=複製 Aussprache
|
menubar.edit.copy.pronunciation=複製 Aussprache
|
||||||
menubar.edit.copy.sentence=Copy Sentence
|
|
||||||
menubar.edit.search-web=Search on Web...
|
|
||||||
menubar.help=_說明
|
menubar.help=_說明
|
||||||
menubar.help.about=_關於 Willow…
|
menubar.help.about=_關於 Willow…
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ menubar.file.preferences=_設定…
|
|||||||
menubar.edit=_編輯
|
menubar.edit=_編輯
|
||||||
menubar.edit.copy.headword=複製 Wort
|
menubar.edit.copy.headword=複製 Wort
|
||||||
menubar.edit.copy.pronunciation=複製 Aussprache
|
menubar.edit.copy.pronunciation=複製 Aussprache
|
||||||
menubar.edit.copy.sentence=Copy Sentence
|
|
||||||
menubar.edit.search-web=Search on Web...
|
|
||||||
menubar.help=_說明
|
menubar.help=_說明
|
||||||
menubar.help.about=_關於 Willow…
|
menubar.help.about=_關於 Willow…
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user