Package: gtk

Function gtk:file-chooser-file

Lambda List

gtk:file-chooser-file (chooser)

Syntax

(gtk:file-chooser-file chooser) => file
(setf (gtk:file-chooser-file chooser) file)

Arguments

chooser -- a gtk:file-chooser widget
file -- a g:file object for the file

Details

The gtk:file-chooser-file function gets the g:file object for the currently selected file in the file chooser. If multiple files are selected, one of the files will be returned at random. If the file chooser is in folder mode, this function returns the selected folder.

The (setf gtk:file-chooser-file) function sets file as the current filename for the file chooser, by changing to the parent folder of the file and actually selecting the file. If the file chooser is in :save mode, the base name of the file will also appear in the file name entry of the dialog.

If the file name is not in the current folder of the file chooser, then the current folder of the file chooser will be changed to the folder containing file.

Note that the file must exist, or nothing will be done except for the directory change.

Examples

If you are implementing a save dialog, you should use this function if you already have a file name to which the user may save. For example, when the user opens an existing file and then does "File/Save As..." on it. If you do not have a file name already - for example, if the user just created a new file and is saving it for the first time, do not call this function. Instead, use something similar to this:
(if document-is-new
    (progn
      ;; the user just created a new document
      (setf (gtk:file-chooser-current-folder-file chooser)
            default-file-for-saving)
      (setf (gtk:file-chooser-current-name chooser) "Untitled document"))
      (progn
        ;; the user edited an existing document
        (setf (gtk:file-chooser-file chooser) existing-file)))    

Warning

The gtk:file-chooser implementation is deprecated since 4.10. Use the gtk:file-dialog object instead.
 

See also

2024-11-21