Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/seesaw/chooser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@
(default-option :dir
(fn [^JFileChooser chooser dir]
(.setCurrentDirectory chooser (if (instance? java.io.File dir) dir
(java.io.File. (str dir))))))
(java.io.File. (str dir))))))
(bean-option [:multi? :multi-selection-enabled] JFileChooser boolean)
(bean-option [:selection-mode :file-selection-mode] JFileChooser file-selection-modes)
(default-option :filters set-file-filters)
(bean-option [:all-files? :accept-all-file-filter-used] JFileChooser boolean)))
(bean-option [:all-files? :accept-all-file-filter-used] JFileChooser boolean)
(default-option :suggest-name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would :selected-file be a better name since this can also be used to set the initial selection to an existing file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Especially if it should also accept java.io.File.

(fn [^JFileChooser chooser suggest-name]
(.setSelectedFile chooser (java.io.File. (str suggest-name)))))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd allow the name to be either a java.io.File or convert it to a string. See :dir above.



(option-provider JFileChooser file-chooser-options)

Expand Down Expand Up @@ -147,6 +151,8 @@
:cancel-fn Function which will be called with the JFileChooser on user abort of the dialog.
Its result will be returned. Default: returns nil.

:suggest-name The default name of file.

Examples:

; ask & return single file
Expand All @@ -168,11 +174,12 @@
See http://download.oracle.com/javase/6/docs/api/javax/swing/JFileChooser.html
"
[& args]
(let [[parent & {:keys [type remember-directory? success-fn cancel-fn]
:or {type :open
(let [[parent & {:keys [type remember-directory? success-fn cancel-fn suggest-name]
:or {type :open
remember-directory? true
success-fn (fn [fc files] files)
cancel-fn (fn [fc])}
cancel-fn (fn [fc])
suggest-name ""}
:as opts}] (if (keyword? (first args)) (cons nil args) args)
parent (if (keyword? parent) nil parent)
^JFileChooser chooser (configure-file-chooser
Expand Down