comparison src/name/blackcap/clipman/Menus.kt @ 41:33fbe3a78d84

Got the settings stuff compiling (untested).
author David Barts <n5jrn@me.com>
date Sat, 08 Feb 2020 22:10:01 -0700
parents 2a5808156f99
children 19d9da731c43
comparison
equal deleted inserted replaced
40:c803a2c89ea0 41:33fbe3a78d84
16 */ 16 */
17 class MenuItemListener: ActionListener { 17 class MenuItemListener: ActionListener {
18 override fun actionPerformed(e: ActionEvent) { 18 override fun actionPerformed(e: ActionEvent) {
19 when (e.actionCommand) { 19 when (e.actionCommand) {
20 "File.Quit" -> System.exit(0) 20 "File.Quit" -> System.exit(0)
21 "File.Preferences" -> settingsDialog.setVisible(true)
21 "Edit.Clone" -> onlyIfSelected { PasteboardItem.write(it.contents) } 22 "Edit.Clone" -> onlyIfSelected { PasteboardItem.write(it.contents) }
22 "Edit.Coerce" -> onlyIfSelected { coerceDialog.setVisible(true) } 23 "Edit.Coerce" -> onlyIfSelected { coerceDialog.setVisible(true) }
23 "Edit.Find" -> searchDialog.setVisible(true) 24 "Edit.Find" -> searchDialog.setVisible(true)
24 "Edit.FindAgain" -> searchDialog.find() 25 "Edit.FindAgain" -> searchDialog.find()
25 "Help.About" -> JOptionPane.showMessageDialog(frame.v, 26 "Help.About" -> showAboutDialog()
26 "ClipMan, a clipboard manager.\n"
27 + "© MMXX, David W. Barts",
28 "About ClipMan",
29 JOptionPane.PLAIN_MESSAGE)
30 else -> throw RuntimeException("unexpected actionCommand!") 27 else -> throw RuntimeException("unexpected actionCommand!")
31 } 28 }
32 } 29 }
33 30
34 private fun onlyIfSelected(block: (QueueItem) -> Unit) { 31 private fun onlyIfSelected(block: (QueueItem) -> Unit) {
82 add(JMenu("File").apply { 79 add(JMenu("File").apply {
83 add(JMenuItem("Quit").apply { 80 add(JMenuItem("Quit").apply {
84 actionCommand = "File.Quit" 81 actionCommand = "File.Quit"
85 addActionListener(menuItemListener) 82 addActionListener(menuItemListener)
86 makeShortcut(KeyEvent.VK_Q) 83 makeShortcut(KeyEvent.VK_Q)
84 })
85 add(JMenuItem("Preferences…").apply {
86 actionCommand = "File.Preferences"
87 addActionListener(menuItemListener)
88 makeShortcut(KeyEvent.VK_COMMA)
87 }) 89 })
88 }) 90 })
89 } 91 }
90 add(JMenu("Edit").apply { 92 add(JMenu("Edit").apply {
91 add(anyRequired.add(JMenuItem("Clone").apply { 93 add(anyRequired.add(JMenuItem("Clone").apply {
150 })) 152 }))
151 } 153 }
152 } 154 }
153 155
154 val popupMenu = MyPopupMenu() 156 val popupMenu = MyPopupMenu()
157
158 /**
159 * Show an About dialog.
160 */
161 fun showAboutDialog() {
162 JOptionPane.showMessageDialog(frame.v,
163 "ClipMan, a clipboard manager.\n"
164 + "© MMXX, David W. Barts",
165 "About ClipMan",
166 JOptionPane.PLAIN_MESSAGE)
167 }