changeset 37:9890445e4cc4

Didn't like eating its own dog food. Fixed.
author David Barts <n5jrn@me.com>
date Thu, 30 Jan 2020 21:03:56 -0800
parents fcf82e3b7e31
children 08eaae2aaf76
files src/name/blackcap/clipman/Pasteboard.kt
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/name/blackcap/clipman/Pasteboard.kt	Thu Jan 30 20:24:02 2020 -0800
+++ b/src/name/blackcap/clipman/Pasteboard.kt	Thu Jan 30 21:03:56 2020 -0800
@@ -18,6 +18,10 @@
 import java.util.logging.Logger
 import kotlin.collections.HashMap
 
+/* Kotlin bug: compaion class fails to see these unless they are out here. */
+private val CHARSET = Charset.forName(CHARSET_NAME)
+private val HTML_FLAVOR = DataFlavor("text/html; document=all; class=\"[B\"; charset=" + CHARSET_NAME)
+
 /**
  * Represents an item of data in the clipboard and how to read and
  * write it.
@@ -60,8 +64,6 @@
 
     private class PasteboardData(val item: PasteboardItem):
     Transferable, ClipboardOwner {
-        private val CHARSET = Charset.forName(CHARSET_NAME)
-        private val HTML_FLAVOR = DataFlavor("text/html; document=all; class=\"[B\"; charset=" + CHARSET_NAME)
         private val _data: HashMap<DataFlavor, Any>
         private val flavors: Array<DataFlavor>
 
@@ -117,17 +119,22 @@
          * @return a PasteboardItem? object, null if nothing could be read
          */
         fun read() : PasteboardItem? {
+            /* println("-- BEGIN FLAVORS --")
+            CLIPBOARD.availableDataFlavors.forEach {
+                println(it.mimeType)
+            }
+            println("-- END FLAVORS --") */
             check()
             val plain = getClipboardData(DataFlavor.stringFlavor) as String?
             if (plain == null) {
                 return null
             }
-            val html = getClipboardData(DataFlavor.allHtmlFlavor) as String?
+            val html = getClipboardData(HTML_FLAVOR) as ByteArray?
             if (html == null) {
                 val rtf = getClipboardData(RTF_FLAVOR) as ByteArray?
                 return if (rtf == null) { Plain(plain) } else { RTF(plain, rtf) }
             } else {
-                return HTML(plain, html)
+                return HTML(plain, html.toString(CHARSET))
             }
         }