# HG changeset patch # User David Barts # Date 1586642483 25200 # Node ID 841f711c40bd84dc8a564503fb1a12d99b9fd9fb # Parent 0528030187e9ddd491ccf4152dc3b5050401ca79 Add new dialogs, and make NO the default for dangerous YES answers. diff -r 0528030187e9 -r 841f711c40bd src/name/blackcap/exifwasher/WashDialog.kt --- a/src/name/blackcap/exifwasher/WashDialog.kt Sat Apr 11 13:38:26 2020 -0700 +++ b/src/name/blackcap/exifwasher/WashDialog.kt Sat Apr 11 15:01:23 2020 -0700 @@ -4,6 +4,7 @@ package name.blackcap.exifwasher import java.awt.Color +import java.awt.Component import java.awt.Dimension import java.awt.event.ActionEvent import java.awt.event.ActionListener @@ -72,9 +73,32 @@ private lateinit var washing: File + /* a yes/no dialog in which NO is the default */ + private fun noYesDialog(parent: Component, message: String, title: String): Int { + val options = arrayOf("No", "Yes") + val status = JOptionPane.showOptionDialog(parent, message, title, + JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, + null, options, options[0]) + return if (status == 1) JOptionPane.YES_OPTION else JOptionPane.NO_OPTION + } + /* initiates the washing of the Exif data */ fun wash(dirty: File) { title = "Washing: ${dirty.name}" + + /* warn (and allow user to back out) if not a JPEG */ + val lcext = splitext(dirty.name).second.toLowerCase() + if (lcext != ".jpg" && lcext != ".jpeg") { + val answer = noYesDialog(Application.mainFrame, + "File ${dirty.name} does not appear to be a JPEG image.\n"+ + "Washing non-JPEG images may damage them. Proceed anyway?", + "Non-JPEG file detected") + if (answer != JOptionPane.YES_OPTION) { + close() + return + } + } + selectAll.setSelected(false) washing = dirty useWaitCursor() @@ -155,11 +179,9 @@ /* warn (and allow user to back out) if overwriting */ if (newFile.exists()) { - val answer = JOptionPane.showConfirmDialog(Application.mainFrame, + val answer = noYesDialog(Application.mainFrame, "File ${newFile.name} already exists. Overwrite?", - "Confirm overwriting file", - JOptionPane.YES_NO_OPTION, - JOptionPane.WARNING_MESSAGE) + "Confirm overwriting file") if (answer != JOptionPane.YES_OPTION) { close() return