gtk-dialog, gtk-window, gtk-bin, gtk-container, gtk-widget, g-initially-unowned, gtk-buildable, gtk-file-chooser, g-object, common-lisp:standard-object, common-lisp:t
gtk-file-chooser-dialog is a dialog box suitable for use with "File/Open" or "File/Save as" commands. This widget works by putting a gtk-file-chooser-widget inside a gtk-dialog. It exposes the GtkFileChooserIface interface, so you can use all of the gtk-file-chooser functions on the file chooser dialog as well as those for gtk-dialog.
Note that gtk-file-chooser-dialog does not have any methods of its own. Instead, you should use the functions that work on a gtk-file-chooser.
Example: Typical usage
In the simplest of cases, you can the following code to use gtk-file-chooser-dialog to select a file for opening:
(defun create-file-chooser-dialog-open (window) (let ((dialog (gtk-file-chooser-dialog-new "Open File" window :open "gtk-cancel" :cancel "gtk-open" :accept))) (if (eql (gtk-dialog-run dialog) (foreign-enum-value 'gtk-response-type :accept)) (let ((filename (gtk-file-chooser-get-filename dialog))) ... ))To use a dialog for saving, you can use this:
(defun create-file-chooser-dialog-save (window filename) (let ((dialog (gtk-file-chooser-dialog-new "Save File" window :save "gtk-cancel" :cancel "gtk-save" :accept))) (gtk-file-chooser-set-do-overwrite-confirmation dialog t) (if filename (gtk-file-chooser-set-filename dialog filename) (gtk-file-chooser-set-current-name dialog "Untitled document")) (if (eql (gtk-dialog-run dialog) (foreign-enum-value 'gtk-response-type :accept)) (let ((filename (gtk-file-chooser-get-filename dialog))) ... ))
Setting up a file chooser dialogThere are various cases in which you may need to use a gtk-file-chooser-dialog:
NoteOld versions of the file chooser's documentation suggested using the function gtk-file-chooser-set-current-folder in various situations, with the intention of letting the application suggest a reasonable default folder. This is no longer considered to be a good policy, as now the file chooser is able to make good suggestions on its own. In general, you should only cause the file chooser to show a specific folder when it is appropriate to use the function gtk-file-chooser-set-filename, i. e. when you are doing a File/Save As command and you already have a file saved somewhere.
Response Codesgtk-file-chooser-dialog inherits from gtk-dialog, so buttons that go in its action area have response codes such as :accept and :cancel. For example, you could call the function gtk-file-chooser-dialog-new as follows:
(let ((dialog (gtk-file-chooser-dialog-new "Open File" parent-window :open "gtk-cancel" :cancel "gtk-open" :accept))) ... )This will create buttons for "Cancel" and "Open" that use stock response identifiers from gtk-response-type. For most dialog boxes you can use your own custom response codes rather than the ones in gtk-response-type, but gtk-file-chooser-dialog assumes that its "accept"-type action, e. g. an "Open" or "Save" button, will have one of the following response codes:
:accept :ok :yes :applyThis is because gtk-file-chooser-dialog must intercept responses and switch to folders if appropriate, rather than letting the dialog terminate - the implementation uses these known response codes to know which responses can be blocked if appropriate.
NoteTo summarize, make sure you use a stock response code when you use gtk-file-chooser-dialog to ensure proper operation.
Inherited Slot Access Functions