Mercurial > cgi-bin > hgweb.cgi > JpegWasher
diff src/name/blackcap/exifwasher/Menus.kt @ 3:19c381c536ec
Code to make it a proper Mac GUI app. Untested!
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 08 Apr 2020 20:29:12 -0700 |
parents | |
children | dc1f4359659d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/name/blackcap/exifwasher/Menus.kt Wed Apr 08 20:29:12 2020 -0700 @@ -0,0 +1,76 @@ +/* + * Menus. + */ +package name.blackcap.exifwasher + +import java.awt.event.ActionEvent +import java.awt.event.ActionListener +import java.awt.event.KeyEvent +import javax.swing.* + +/** + * 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. + */ +class MyMenuBar: JMenuBar() { + init { + add(JMenu("File").apply { + add(JMenuItem("Wash…").apply { + addActionListener(ActionListener { doWash() }) + makeShortcut(KeyEvent.VK_W) + }) + if (OS.type != OS.MAC) { + add(JMenuItem("Preferences…").apply { + addActionListener(ActionListener { + Application.settingsDialog.setVisible(true) + }) + makeShortcut(KeyEvent.VK_COMMA) + }) + add(JMenuItem("Quit").apply { + addActionListener(ActionListener { System.exit(0) }) + makeShortcut(KeyEvent.VK_Q) + }) + } + }) + if (OS.type != OS.MAC) { + add(JMenu("Help").apply { + add(JMenuItem("About ClipMan…").apply { + addActionListener(ActionListener { showAboutDialog() }) + }) + }) + } + } + + fun getMenu(name: String): JMenu? { + subElements.forEach { + val jmenu = it.component as? JMenu + if (jmenu?.text == name) { + return jmenu + } + } + return null + } + + fun doWash() { + val fc = JFileChooser().apply { + setMultiSelectionEnabled(true) + } + val status = fc.showOpenDialog(Application.mainFrame) + if (status == JFileChooser.APPROVE_OPTION) { + for (file in fc.getSelectedFiles()) { + WashDialog().wash(file) + } + } + } +} + +/** + * Show an About dialog. + */ +fun showAboutDialog() { + JOptionPane.showMessageDialog(frame.v, + "ExifWasher—Privacy for your photos.\n" + + "© MMXX, David W. Barts", + "About ExifWasher", + JOptionPane.PLAIN_MESSAGE) +}