Refactor ClipboardHelper
This commit is contained in:
parent
efde0dcdb4
commit
8350cb3b3d
@ -53,10 +53,10 @@ class Model(private val searchService: SearchService, private val findWordsServi
|
||||
}
|
||||
|
||||
fun copyHeadwordOfSelectedEntry() {
|
||||
ClipboardHelper.copyHeadword(internalSelectedEntry.get())
|
||||
ClipboardHelper.copyString(internalSelectedEntry.value.traditionalProperty.value)
|
||||
}
|
||||
|
||||
fun copyPronunciationOfSelectedEntry() {
|
||||
ClipboardHelper.copyPronunciation(internalSelectedEntry.get())
|
||||
ClipboardHelper.copyString(internalSelectedEntry.value.pinyinWithToneMarksProperty.value)
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,14 @@
|
||||
package com.marvinelsen.willow.ui.util
|
||||
|
||||
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
||||
import javafx.scene.input.Clipboard
|
||||
import javafx.scene.input.ClipboardContent
|
||||
|
||||
object ClipboardHelper {
|
||||
private val systemClipboard = Clipboard.getSystemClipboard()
|
||||
|
||||
fun copyHeadword(entry: DictionaryEntryFx) {
|
||||
fun copyString(string: String) {
|
||||
val clipboardContent = ClipboardContent()
|
||||
clipboardContent.putString(entry.traditionalProperty.value)
|
||||
systemClipboard.setContent(clipboardContent)
|
||||
}
|
||||
|
||||
fun copyPronunciation(entry: DictionaryEntryFx) {
|
||||
val clipboardContent = ClipboardContent()
|
||||
clipboardContent.putString(entry.pinyinWithToneMarksProperty.value)
|
||||
clipboardContent.putString(string)
|
||||
systemClipboard.setContent(clipboardContent)
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,12 @@ import javafx.scene.control.MenuItem
|
||||
fun createContextMenuForEntry(entry: DictionaryEntryFx) = ContextMenu().apply {
|
||||
val menuItemCopyHeadword =
|
||||
MenuItem(WillowApplication.resourceBundle.getString("menubar.edit.copy.headword")).apply {
|
||||
onAction = EventHandler { ClipboardHelper.copyHeadword(entry) }
|
||||
onAction = EventHandler { ClipboardHelper.copyString(entry.traditionalProperty.value) }
|
||||
}
|
||||
|
||||
val menuItemCopyPronunciation =
|
||||
MenuItem(WillowApplication.resourceBundle.getString("menubar.edit.copy.pronunciation")).apply {
|
||||
onAction = EventHandler { ClipboardHelper.copyPronunciation(entry) }
|
||||
onAction = EventHandler { ClipboardHelper.copyString(entry.pinyinWithToneMarksProperty.value) }
|
||||
}
|
||||
|
||||
items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation)
|
||||
|
Loading…
Reference in New Issue
Block a user