Add "Copy sentence" context menu for example sentences
This commit is contained in:
parent
cfff342a3a
commit
b8194f3ca6
@ -15,8 +15,11 @@ import javafx.scene.layout.VBox
|
||||
import javafx.util.Callback
|
||||
import java.util.ResourceBundle
|
||||
|
||||
class DictionaryEntryCellFactory(private val resources: ResourceBundle, private val config: Config) :
|
||||
Callback<ListView<DictionaryEntryFx?>, ListCell<DictionaryEntryFx?>> {
|
||||
class DictionaryEntryCellFactory(
|
||||
private val resources: ResourceBundle,
|
||||
private val config: Config,
|
||||
) : Callback<ListView<DictionaryEntryFx?>, ListCell<DictionaryEntryFx?>> {
|
||||
|
||||
override fun call(listView: ListView<DictionaryEntryFx?>): ListCell<DictionaryEntryFx?> {
|
||||
val entryCell = EntryCell(resources, config)
|
||||
entryCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
|
||||
@ -28,8 +31,11 @@ class DictionaryEntryCellFactory(private val resources: ResourceBundle, private
|
||||
}
|
||||
}
|
||||
|
||||
private class EntryCell(private val resources: ResourceBundle, private val config: Config) :
|
||||
ListCell<DictionaryEntryFx?>() {
|
||||
private class EntryCell(
|
||||
private val resources: ResourceBundle,
|
||||
private val config: Config,
|
||||
) : ListCell<DictionaryEntryFx?>() {
|
||||
|
||||
private val labelHeadword = Label().apply {
|
||||
styleClass.add("headword")
|
||||
styleProperty().bind(
|
||||
@ -118,9 +124,11 @@ private class EntryCell(private val resources: ResourceBundle, private val confi
|
||||
entry.crossStraitsDefinitions.isNotEmpty() -> entry.crossStraitsDefinitions.joinToString(
|
||||
separator = " / "
|
||||
) { it.definition }
|
||||
|
||||
entry.moedictDefinitions.isNotEmpty() -> entry.moedictDefinitions.joinToString(
|
||||
separator = " / "
|
||||
) { it.definition }
|
||||
|
||||
else -> error("No definition for entry")
|
||||
}
|
||||
labelDefinition.text = definition
|
||||
|
@ -3,17 +3,22 @@ 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.ui.util.createContextMenuForSentence
|
||||
import javafx.beans.binding.Bindings
|
||||
import javafx.scene.control.Label
|
||||
import javafx.scene.control.ListCell
|
||||
import javafx.scene.control.ListView
|
||||
import javafx.scene.layout.VBox
|
||||
import javafx.util.Callback
|
||||
import java.util.ResourceBundle
|
||||
|
||||
class SentenceCellFactory(private val config: Config) : Callback<ListView<SentenceFx?>, ListCell<SentenceFx?>> {
|
||||
class SentenceCellFactory(
|
||||
private val resources: ResourceBundle,
|
||||
private val config: Config,
|
||||
) : Callback<ListView<SentenceFx?>, ListCell<SentenceFx?>> {
|
||||
|
||||
override fun call(listView: ListView<SentenceFx?>): ListCell<SentenceFx?> {
|
||||
val sentenceCell = SentenceCell(config)
|
||||
val sentenceCell = SentenceCell(resources, config)
|
||||
sentenceCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
|
||||
return sentenceCell
|
||||
}
|
||||
@ -23,7 +28,11 @@ class SentenceCellFactory(private val config: Config) : Callback<ListView<Senten
|
||||
}
|
||||
}
|
||||
|
||||
private class SentenceCell(private val config: Config) : ListCell<SentenceFx?>() {
|
||||
private class SentenceCell(
|
||||
private val resources: ResourceBundle,
|
||||
private val config: Config,
|
||||
) : ListCell<SentenceFx?>() {
|
||||
|
||||
private val labelSentence = Label().apply {
|
||||
styleClass.add("sentence")
|
||||
isWrapText = true
|
||||
@ -51,6 +60,7 @@ private class SentenceCell(private val config: Config) : ListCell<SentenceFx?>()
|
||||
)
|
||||
)
|
||||
|
||||
contextMenu = createContextMenuForSentence(sentence, resources)
|
||||
graphic = root
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ class DetailsController(private val model: Model, private val config: Config) {
|
||||
|
||||
private fun initializeListViewSentences() {
|
||||
listViewSentences.apply {
|
||||
cellFactory = SentenceCellFactory(config)
|
||||
cellFactory = SentenceCellFactory(resources, config)
|
||||
items = model.sentences
|
||||
|
||||
disableProperty().bind(Bindings.or(model.isFindingSentences, Bindings.isEmpty(model.sentences)))
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.marvinelsen.willow.ui.util
|
||||
|
||||
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
||||
import com.marvinelsen.willow.ui.SentenceFx
|
||||
import javafx.event.EventHandler
|
||||
import javafx.scene.control.ContextMenu
|
||||
import javafx.scene.control.MenuItem
|
||||
@ -19,3 +20,12 @@ fun createContextMenuForEntry(entry: DictionaryEntryFx, resourceBundle: Resource
|
||||
|
||||
items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation)
|
||||
}
|
||||
|
||||
fun createContextMenuForSentence(sentence: SentenceFx, resourceBundle: ResourceBundle) = ContextMenu().apply {
|
||||
val menuItemCopySentence =
|
||||
MenuItem(resourceBundle.getString("menubar.edit.copy.sentence")).apply {
|
||||
onAction = EventHandler { ClipboardHelper.copyString(sentence.traditionalProperty.value) }
|
||||
}
|
||||
|
||||
items.addAll(menuItemCopySentence)
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ menubar.file.preferences=_Preferences…
|
||||
menubar.edit=_Edit
|
||||
menubar.edit.copy.headword=Copy Headword
|
||||
menubar.edit.copy.pronunciation=Copy Pronunciation
|
||||
menubar.edit.copy.sentence=Copy Sentence
|
||||
menubar.help=_Help
|
||||
menubar.help.about=_About…
|
||||
|
||||
|
@ -25,6 +25,7 @@ menubar.file.preferences=_Einstellungen…
|
||||
menubar.edit=_Bearbeiten
|
||||
menubar.edit.copy.headword=Kopiere Wort
|
||||
menubar.edit.copy.pronunciation=Kopiere Aussprache
|
||||
menubar.edit.copy.sentence=Copy Sentence
|
||||
menubar.help=_Hilfe
|
||||
menubar.help.about=_Über…
|
||||
|
||||
|
@ -25,6 +25,7 @@ menubar.file.preferences=_Preferences…
|
||||
menubar.edit=_Edit
|
||||
menubar.edit.copy.headword=Copy Headword
|
||||
menubar.edit.copy.pronunciation=Copy Pronunciation
|
||||
menubar.edit.copy.sentence=Copy Sentence
|
||||
menubar.help=_Help
|
||||
menubar.help.about=_About…
|
||||
|
||||
|
@ -25,6 +25,7 @@ menubar.file.preferences=_設定…
|
||||
menubar.edit=_編輯
|
||||
menubar.edit.copy.headword=複製 Wort
|
||||
menubar.edit.copy.pronunciation=複製 Aussprache
|
||||
menubar.edit.copy.sentence=Copy Sentence
|
||||
menubar.help=_說明
|
||||
menubar.help.about=_關於 Willow…
|
||||
|
||||
|
@ -25,6 +25,7 @@ menubar.file.preferences=_設定…
|
||||
menubar.edit=_編輯
|
||||
menubar.edit.copy.headword=複製 Wort
|
||||
menubar.edit.copy.pronunciation=複製 Aussprache
|
||||
menubar.edit.copy.sentence=Copy Sentence
|
||||
menubar.help=_說明
|
||||
menubar.help.about=_關於 Willow…
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user