diff src/name/blackcap/clipman/Menus.kt @ 62:c56a0747c256 default tip

Add make plain feature.
author David Barts <n5jrn@me.com>
date Thu, 28 Apr 2022 20:53:39 -0700
parents c6cccbe2f393
children
line wrap: on
line diff
--- a/src/name/blackcap/clipman/Menus.kt	Sun Apr 03 16:58:01 2022 -0700
+++ b/src/name/blackcap/clipman/Menus.kt	Thu Apr 28 20:53:39 2022 -0700
@@ -28,6 +28,7 @@
             "Edit.Coerce" -> onlyIfSelected { Application.coerceDialog.setVisible(true) }
             "Edit.Find" -> Application.searchDialog.setVisible(true)
             "Edit.FindAgain" -> Application.searchDialog.find()
+            "Edit.Plain" -> onlyIfSelected { if (suitedForCoercing(it)) { makePlain(it.contents) } }
             "Edit.Troff" -> onlyIfSelected { if (suitedForCoercing(it)) { troffize(it.contents) } }
             "Help.About" -> showAboutDialog()
             else -> throw RuntimeException("unexpected actionCommand!")
@@ -109,6 +110,12 @@
                 addActionListener(Application.menuItemListener)
                 makeShortcut(KeyEvent.VK_T)
             }))
+            add(Application.styledRequired.add(JMenuItem("Make Plain").apply {
+                setEnabled(false)
+                actionCommand = "Edit.Plain"
+                addActionListener(Application.menuItemListener)
+                makeShortcut(KeyEvent.VK_P)
+            }))
             add(JMenuItem("Find…").apply {
                 actionCommand = "Edit.Find"
                 addActionListener(Application.menuItemListener)
@@ -155,6 +162,10 @@
             actionCommand = "Edit.Troff"
             addActionListener(Application.menuItemListener)
         }))
+        add(Application.styledRequired.add(JMenuItem("Make Plain").apply {
+            actionCommand = "Edit.Plain"
+            addActionListener(Application.menuItemListener)
+        }))
         add(Application.styledRequired.add(JMenuItem("Coerce…").apply {
             actionCommand = "Edit.Coerce"
             addActionListener(Application.menuItemListener)
@@ -162,6 +173,18 @@
     }
 }
 
+fun makePlain(item: PasteboardItem): Unit {
+    val plain = when (item) {
+        is PasteboardItem.Plain ->
+            item.plain
+        is PasteboardItem.HTML ->
+            item.plain
+        is PasteboardItem.RTF ->
+            item.plain
+    }
+    PasteboardItem.write(PasteboardItem.Plain(plain))
+}
+
 /**
  * Show an About dialog.
  */