Mercurial > cgi-bin > hgweb.cgi > ClipMan
diff src/name/blackcap/clipman/Menus.kt @ 31:0c6c18a733b7
Compiles, new menu still a mess.
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 30 Jan 2020 16:01:51 -0800 |
parents | 0e88c6bed11e |
children | 5f8475b37e23 |
line wrap: on
line diff
--- a/src/name/blackcap/clipman/Menus.kt Wed Jan 29 21:56:12 2020 -0800 +++ b/src/name/blackcap/clipman/Menus.kt Thu Jan 30 16:01:51 2020 -0800 @@ -18,7 +18,7 @@ when (e.actionCommand) { "File.Quit" -> System.exit(0) "Edit.Clone" -> onlyIfSelected { PasteboardItem.write(it.contents) } - "Edit.Coerce" -> onlyIfSelected { doCoerceFonts(it) } + "Edit.Coerce" -> onlyIfSelected { coerceDialog.setVisible(true) } "Edit.Find" -> searchDialog.setVisible(true) "Edit.FindAgain" -> searchDialog.find() else -> throw RuntimeException("unexpected actionCommand!") @@ -31,20 +31,57 @@ JOptionPane.showMessageDialog(frame.v, "No item selected.", "Error", - JOptionPane.ERROR_MESSAGE); - } else { + JOptionPane.ERROR_MESSAGE) + } else { block(selected) } } - private fun doCoerceFonts(item: QueueItem) { - /* not finished */ + private fun clone(contents: PasteboardItem) { + val (plain, html) = when(contents) { + is PasteboardItem.Plain -> Pair(contents.plain, null) + is PasteboardItem.HTML -> Pair(contents.plain, contents.html) + is PasteboardItem.RTF -> Pair(contents.plain, contents.html) + } + if (html == null) { + PasteboardItem.write(PasteboardItem.Plain(plain)) + } else { + PasteboardItem.write(PasteboardItem.HTML(plain, scrub(html))) + } } } val menuItemListener = MenuItemListener() /** + * Track menu items that require something to be selected in order + * to work, and allow them to be enabled and disabled en masse. + */ +class SelectionRequired { + private val cache = LinkedList<JMenuItem>() + + fun add(item: JMenuItem): JMenuItem { + cache.add(item) + return item + } + + fun enable() { + cache.forEach { + it.setEnabled(true) + } + } + + fun disable() { + cache.forEach { + it.setEnabled(false) + } + } +} + +val anyRequired = SelectionRequired() +val styledRequired = SelectionRequired() + +/** * Our menu bar. What we display depends somewhat on the system type, as * the Mac gives us a gratuitous menu bar entry for handling some stuff. */ @@ -60,13 +97,13 @@ }) } add(JMenu("Edit").apply { - add(SelectionRequired.add(JMenuItem("Clone").apply { + add(anyRequired.add(JMenuItem("Clone").apply { setEnabled(false) actionCommand = "Edit.Clone" addActionListener(menuItemListener) makeShortcut(KeyEvent.VK_C) })) - add(SelectionRequired.add(JMenuItem("Coerce…").apply { + add(styledRequired.add(JMenuItem("Coerce…").apply { setEnabled(false) actionCommand = "Edit.Coerce" addActionListener(menuItemListener) @@ -112,11 +149,11 @@ */ class MyPopupMenu: JPopupMenu() { init { - add(SelectionRequired.add(JMenuItem("Clone").apply { + add(anyRequired.add(JMenuItem("Clone").apply { actionCommand = "Edit.Clone" addActionListener(menuItemListener) })) - add(SelectionRequired.add(JMenuItem("Coerce…").apply { + add(styledRequired.add(JMenuItem("Coerce…").apply { actionCommand = "Edit.Coerce" addActionListener(menuItemListener) })) @@ -124,28 +161,3 @@ } val popupMenu = MyPopupMenu() - -/** - * Track menu items that require something to be selected in order - * to work, and allow them to be enabled and disabled en masse. - */ -object SelectionRequired { - private val cache = LinkedList<JMenuItem>() - - fun add(item: JMenuItem): JMenuItem { - cache.add(item) - return item - } - - fun enable() { - cache.forEach { - it.setEnabled(true) - } - } - - fun disable() { - cache.forEach { - it.setEnabled(false) - } - } -} \ No newline at end of file