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() {
|
fun copyHeadwordOfSelectedEntry() {
|
||||||
ClipboardHelper.copyHeadword(internalSelectedEntry.get())
|
ClipboardHelper.copyString(internalSelectedEntry.value.traditionalProperty.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun copyPronunciationOfSelectedEntry() {
|
fun copyPronunciationOfSelectedEntry() {
|
||||||
ClipboardHelper.copyPronunciation(internalSelectedEntry.get())
|
ClipboardHelper.copyString(internalSelectedEntry.value.pinyinWithToneMarksProperty.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,14 @@
|
|||||||
package com.marvinelsen.willow.ui.util
|
package com.marvinelsen.willow.ui.util
|
||||||
|
|
||||||
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
|
||||||
import javafx.scene.input.Clipboard
|
import javafx.scene.input.Clipboard
|
||||||
import javafx.scene.input.ClipboardContent
|
import javafx.scene.input.ClipboardContent
|
||||||
|
|
||||||
object ClipboardHelper {
|
object ClipboardHelper {
|
||||||
private val systemClipboard = Clipboard.getSystemClipboard()
|
private val systemClipboard = Clipboard.getSystemClipboard()
|
||||||
|
|
||||||
fun copyHeadword(entry: DictionaryEntryFx) {
|
fun copyString(string: String) {
|
||||||
val clipboardContent = ClipboardContent()
|
val clipboardContent = ClipboardContent()
|
||||||
clipboardContent.putString(entry.traditionalProperty.value)
|
clipboardContent.putString(string)
|
||||||
systemClipboard.setContent(clipboardContent)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun copyPronunciation(entry: DictionaryEntryFx) {
|
|
||||||
val clipboardContent = ClipboardContent()
|
|
||||||
clipboardContent.putString(entry.pinyinWithToneMarksProperty.value)
|
|
||||||
systemClipboard.setContent(clipboardContent)
|
systemClipboard.setContent(clipboardContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ import javafx.scene.control.MenuItem
|
|||||||
fun createContextMenuForEntry(entry: DictionaryEntryFx) = ContextMenu().apply {
|
fun createContextMenuForEntry(entry: DictionaryEntryFx) = ContextMenu().apply {
|
||||||
val menuItemCopyHeadword =
|
val menuItemCopyHeadword =
|
||||||
MenuItem(WillowApplication.resourceBundle.getString("menubar.edit.copy.headword")).apply {
|
MenuItem(WillowApplication.resourceBundle.getString("menubar.edit.copy.headword")).apply {
|
||||||
onAction = EventHandler { ClipboardHelper.copyHeadword(entry) }
|
onAction = EventHandler { ClipboardHelper.copyString(entry.traditionalProperty.value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val menuItemCopyPronunciation =
|
val menuItemCopyPronunciation =
|
||||||
MenuItem(WillowApplication.resourceBundle.getString("menubar.edit.copy.pronunciation")).apply {
|
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)
|
items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation)
|
||||||
|
Loading…
Reference in New Issue
Block a user