Add context menu for details view

This commit is contained in:
Marvin Elsen 2024-10-03 12:50:30 +02:00
parent 12eb98d5b1
commit 8ada0a5510
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2

View File

@ -6,12 +6,14 @@ 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.cells.DictionaryEntryCellFactory import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory
import com.marvinelsen.willow.ui.util.createContextMenuForEntry
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
import javafx.scene.control.ListView import javafx.scene.control.ListView
import javafx.scene.control.TabPane import javafx.scene.control.TabPane
import javafx.scene.input.ContextMenuEvent import javafx.scene.input.ContextMenuEvent
import javafx.scene.layout.FlowPane
import javafx.scene.web.WebView import javafx.scene.web.WebView
import kotlinx.html.body import kotlinx.html.body
import kotlinx.html.h1 import kotlinx.html.h1
@ -22,6 +24,9 @@ import kotlinx.html.stream.createHTML
import java.util.ResourceBundle import java.util.ResourceBundle
class DetailsController(private val model: Model, private val config: Config) { class DetailsController(private val model: Model, private val config: Config) {
@FXML
private lateinit var flowPaneSelectedEntry: FlowPane
@FXML @FXML
private lateinit var labelPronunciation: Label private lateinit var labelPronunciation: Label
@ -177,5 +182,12 @@ class DetailsController(private val model: Model, private val config: Config) {
} }
fun showSelectedEntryContextMenu(contextMenuEvent: ContextMenuEvent) { fun showSelectedEntryContextMenu(contextMenuEvent: ContextMenuEvent) {
if (model.selectedEntry.value == null) return
createContextMenuForEntry(model.selectedEntry.value, resources).show(
flowPaneSelectedEntry.scene.window,
contextMenuEvent.screenX,
contextMenuEvent.screenY
)
} }
} }