Package: gtk

Class gtk:file-chooser-dialog

Superclasses

Documented Subclasses

None

Direct Slots

None

Details

The gtk:file-chooser-dialog widget is a dialog 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.

Figure: GtkFileChooserDialog

Note that the gtk:file-chooser-dialog widget does not have any methods of its own. Instead, you should use the functions that work on a gtk:file-chooser interface.

If you want to integrate well with the platform you should use the gtk:file-chooser-native API, which will use a platform-specific dialog if available and fall back to the gtk:file-chooser-dialog widget otherwise.

Setting up a file chooser dialog

There are various cases in which you may need to use a gtk:file-chooser-dialog widget:
  • To select a file for opening, as for a File/Open command. Use :open.
  • To save a file for the first time, as for a File/Save command. Use :save, and suggest a name such as "Untitled" with the gtk:file-chooser-current-name function.
  • To save a file under a different name, as for a File/Save As command. Use :save, and set the existing filename with the gtk:file-chooser-file function.
  • To choose a folder instead of a file. Use :select-folder.
In general, you should only cause the file chooser to show a specific folder when it is appropriate to use the gtk:file-chooser-file function, that is, when you are doing a "Save As" command and you already have a file saved somewhere.

Response Codes

The 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
                                           "Cancel" :cancel
                                           "Open" :accept)))
  ... )    
This will create buttons for "Cancel" and "Open" that identifiers from the gtk:response-type enumeration. For most dialogs 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, for example, an "Open" or "Save" button, will have one of the following response codes:
  :accept  :ok  :yes  :apply    
This 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.

To summarize, make sure you use a predefined response code when you use the gtk:file-chooser-dialog widget to ensure proper operation.

Examples

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
                                             "Cancel" :cancel
                                             "Open" :accept)))
    (if (eq :accept (gtk:dialog-run dialog))
      (let ((filename (gtk:file-chooser-filename dialog)))
        ...
      ))
    (gtk:window-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
                                             "Cancel" :cancel
                                             "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:window-destroy dialog)))    

CSS nodes

The gtk:file-chooser-dialog implementation has a single CSS node with the name window and .filechooser style class.

Warning

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

Returned by

Inherited Slot Access Functions

gtk:file-chooser-action
gtk:file-chooser-create-folders
gtk:file-chooser-filter
gtk:file-chooser-filters
gtk:file-chooser-select-multiple
gtk:file-chooser-shortcut-folders
gtk:accessible-accessible-role
gtk:widget-can-focus
gtk:widget-can-target
gtk:widget-css-classes
gtk:widget-css-name
gtk:widget-cursor
gtk:widget-focus-on-click
gtk:widget-focusable
gtk:widget-halign
gtk:widget-has-default
gtk:widget-has-focus
gtk:widget-has-tooltip
gtk:widget-height-request
gtk:widget-hexpand
gtk:widget-hexpand-set
gtk:widget-layout-manager
gtk:widget-margin-bottom
gtk:widget-margin-end
gtk:widget-margin-start
gtk:widget-margin-top
gtk:widget-name
gtk:widget-opacity
gtk:widget-overflow
gtk:widget-parent
gtk:widget-receives-default
gtk:widget-root
gtk:widget-scale-factor
gtk:widget-sensitive
gtk:widget-tooltip-markup
gtk:widget-tooltip-text
gtk:widget-valign
gtk:widget-vexpand
gtk:widget-vexpand-set
gtk:widget-visible
gtk:widget-width-request
gtk:window-application
gtk:window-child
gtk:window-decorated
gtk:window-default-height
gtk:window-default-widget
gtk:window-default-width
gtk:window-deletable
gtk:window-destroy-with-parent
gtk:window-display
gtk:window-focus-visible
gtk:window-focus-widget
gtk:window-fullscreened
gtk:window-handle-menubar-accel
gtk:window-hide-on-close
gtk:window-icon-name
gtk:window-is-active
gtk:window-maximized
gtk:window-mnemonics-visible
gtk:window-modal
gtk:window-resizable
gtk:window-startup-id
gtk:window-suspended
gtk:window-title
gtk:window-titlebar
gtk:window-transient-for
gtk:dialog-use-header-bar
g:object-has-reference
g:object-pointer

See also

2024-7-30