Created
June 24, 2014 18:04
-
-
Save mtcomb/93b45873336369d08fba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; http://stackoverflow.com/questions/3651494/jfilechooser-with-confirmation-dialog | |
; in Clojure | |
(defn chooser [] | |
(proxy [javax.swing.JFileChooser] [] | |
(approveSelection [] | |
(let [f (proxy-super getSelectedFile)] | |
(if (and (.exists f) | |
(= (.getDialogType this) | |
javax.swing.JFileChooser/SAVE_DIALOG)) | |
(do | |
(let [result (javax.swing.JOptionPane/showConfirmDialog | |
this "The file exists, overwrite?" "Existing file" | |
javax.swing.JOptionPane/YES_NO_CANCEL_OPTION)] | |
(condp = result | |
javax.swing.JOptionPane/YES_OPTION (proxy-super approveSelection) | |
javax.swing.JOptionPane/NO_OPTION nil | |
javax.swing.JOptionPane/CLOSED_OPTION nil | |
javax.swing.JOptionPane/CANCEL_OPTION (.cancelSelection this) | |
nil))) | |
(proxy-super approveSelection)) | |
)))) | |
(.showOpenDialog (chooser) nil) | |
(.showSaveDialog (chooser) nil) | |
(let [c (chooser)] | |
(if (== (.showSaveDialog c nil) 0) | |
(.getSelectedFile c)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment