# HG changeset patch # User David Barts # Date 1580444502 28800 # Node ID 5f8475b37e23d7555a0f845464875237586b90c8 # Parent 376643a09b5267684a06bdc24d0758347f6f20fd Got it correctly enabling and disabling menu items. diff -r 376643a09b52 -r 5f8475b37e23 src/name/blackcap/clipman/Main.kt --- 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() } } } diff -r 376643a09b52 -r 5f8475b37e23 src/name/blackcap/clipman/Menus.kt --- 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() + private val controls = HashSet() + /* private val parents = HashSet() */ 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()