Package: gtk
Class gtk:file-chooser-dialog
Superclassesgtk:dialog, gtk:window, gtk:bin, gtk:container, gtk:widget, gtk:buildable, gtk:file-chooser, gobject:object, common-lisp:standard-object, common-lisp:t Documented Subclasses
None
Direct Slots
None
Details The gtk:file-chooser-dialog widget 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 widget inside a gtk:dialog widget. It exposes the gtk:file-chooser interface, so you can use all of the gtk:file-chooser functions on the file chooser dialog as well as those for the gtk:dialog widget. ![]() Example: Typical usage In the simplest of cases, you can the following code to use the gtk:file-chooser-dialog widget 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 (eq :accept (gtk:dialog-run dialog)) (let ((filename (gtk:file-chooser-filename dialog))) ... )) (gtk:widget-destroy 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))) (setf (gtk:file-chooser-do-overwrite-confirmation dialog) t) (if filename (setf (gtk:file-chooser-filename dialog) filename) (setf (gtk:file-chooser-current-name dialog) "Untitled document")) (if (eq :accept (gtk:dialog-run dialog)) (let ((filename (gtk:file-chooser-filename dialog))) ... )) (gtk:widget-destroy dialog))) Setting up a file chooser dialogThere are various cases in which you may need to use a gtk:file-chooser-dialog widget:
NoteOld versions of the file chooser's documentation suggested using the gtk:file-chooser-current-folder function 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 gtk:file-chooser-filename function, i.e. when you are doing a File/Save As command and you already have a file saved somewhere.Response CodesThe gtk:file-chooser-dialog widget inherits from the gtk:dialog widget, so buttons that go in its action area have response codes such as :accept and :cancel. For example, you could call the gtk:file-chooser-dialog-new function 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 the gtk:response-type enumeration. For most dialog boxes you can use your own custom response codes rather than the ones in the gtk:response-type enumeration, but the gtk:file-chooser-dialog widget 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 the gtk:file-chooser-dialog widget 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 the gtk:file-chooser-dialog widget to ensure proper operation. | Returned byInherited Slot Access FunctionsSee also |
2023-6-11