Mercurial > cgi-bin > hgweb.cgi > ClipMan
changeset 35:5f8475b37e23
Got it correctly enabling and disabling menu items.
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 30 Jan 2020 20:21:42 -0800 |
parents | 376643a09b52 |
children | fcf82e3b7e31 |
files | src/name/blackcap/clipman/Main.kt src/name/blackcap/clipman/Menus.kt |
diffstat | 2 files changed, 20 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/name/blackcap/clipman/Main.kt Thu Jan 30 19:38:59 2020 -0800 +++ b/src/name/blackcap/clipman/Main.kt Thu Jan 30 20:21:42 2020 -0800 @@ -138,6 +138,8 @@ source.basedOn.let { if (it is PasteboardItem.HTML || it is PasteboardItem.RTF) { styledRequired.enable() + } else { + styledRequired.disable() } } }
--- a/src/name/blackcap/clipman/Menus.kt Thu Jan 30 19:38:59 2020 -0800 +++ b/src/name/blackcap/clipman/Menus.kt Thu Jan 30 20:21:42 2020 -0800 @@ -3,12 +3,13 @@ */ package name.blackcap.clipman +import java.awt.Container import java.awt.Toolkit import java.awt.event.ActionEvent import java.awt.event.ActionListener import java.awt.event.KeyEvent -import java.util.LinkedList import javax.swing.* +import kotlin.collections.HashSet /** * Listen to actionEvents from both menu bar and popup menu selections. @@ -58,24 +59,30 @@ * to work, and allow them to be enabled and disabled en masse. */ class SelectionRequired { - private val cache = LinkedList<JMenuItem>() + private val controls = HashSet<JMenuItem>() + /* private val parents = HashSet<Container>() */ fun add(item: JMenuItem): JMenuItem { - cache.add(item) + controls.add(item) + /* var p = item.parent + if (p != null) { + parents.add(p) + } */ return item } - fun enable() { - cache.forEach { - it.setEnabled(true) + private fun setEnabled(state: Boolean) { + controls.forEach { + it.setEnabled(state) } + /* parents.forEach { + it.validate() + } */ } - fun disable() { - cache.forEach { - it.setEnabled(false) - } - } + fun enable() = setEnabled(true) + + fun disable() = setEnabled(false) } val anyRequired = SelectionRequired()