FileChooserT

GtkFileChooser is an interface that can be implemented by file selection widgets.

In GTK, the main objects that implement this interface are [class@Gtk.FileChooserWidget] and [class@Gtk.FileChooserDialog].

You do not need to write an object that implements the GtkFileChooser interface unless you are trying to adapt an existing file selector to expose a standard programming interface.

GtkFileChooser allows for shortcuts to various places in the filesystem. In the default implementation these are displayed in the left pane. It may be a bit confusing at first that these shortcuts come from various sources and in various flavours, so lets explain the terminology here:

- Bookmarks: are created by the user, by dragging folders from the right pane to the left pane, or by using the “Add”. Bookmarks can be renamed and deleted by the user.

- Shortcuts: can be provided by the application. For example, a Paint program may want to add a shortcut for a Clipart folder. Shortcuts cannot be modified by the user.

- Volumes: are provided by the underlying filesystem abstraction. They are the “roots” of the filesystem.

File Names and Encodings

When the user is finished selecting files in a GtkFileChooser, your program can get the selected filenames as GFiles.

Adding options

You can add extra widgets to a file chooser to provide options that are not present in the default design, by using [method@Gtk.FileChooser.add_choice]. Each choice has an identifier and a user visible label; additionally, each choice can have multiple options. If a choice has no option, it will be rendered as a check button with the given label; if a choice has options, it will be rendered as a combo box.

Members

Functions

addChoice
void addChoice(string id, string label, string[] options, string[] optionLabels)

Adds a 'choice' to the file chooser.

addFilter
void addFilter(FileFilter filter)

Adds @filter to the list of filters that the user can select between.

addShortcutFolder
bool addShortcutFolder(FileIF folder)

Adds a folder to be displayed with the shortcut folders in a file chooser.

getAction
GtkFileChooserAction getAction()

Gets the type of operation that the file chooser is performing.

getChoice
string getChoice(string id)

Gets the currently selected option in the 'choice' with the given ID.

getCreateFolders
bool getCreateFolders()

Gets whether file chooser will offer to create new folders.

getCurrentFolder
FileIF getCurrentFolder()

Gets the current folder of @chooser as #GFile.

getCurrentName
string getCurrentName()

Gets the current name in the file selector, as entered by the user.

getFile
FileIF getFile()

Gets the GFile for the currently selected file in the file selector.

getFileChooserStruct
GtkFileChooser* getFileChooserStruct(bool transferOwnership)

Get the main Gtk struct

getFiles
ListModelIF getFiles()

Lists all the selected files and subfolders in the current folder of @chooser as #GFile.

getFilter
FileFilter getFilter()

Gets the current filter.

getFilters
ListModelIF getFilters()

Gets the current set of user-selectable filters, as a list model.

getSelectMultiple
bool getSelectMultiple()

Gets whether multiple files can be selected in the file chooser.

getShortcutFolders
ListModelIF getShortcutFolders()

Queries the list of shortcut folders in the file chooser.

removeChoice
void removeChoice(string id)

Removes a 'choice' that has been added with gtk_file_chooser_add_choice().

removeFilter
void removeFilter(FileFilter filter)

Removes @filter from the list of filters that the user can select between.

removeShortcutFolder
bool removeShortcutFolder(FileIF folder)

Removes a folder from the shortcut folders in a file chooser.

setAction
void setAction(GtkFileChooserAction action)

Sets the type of operation that the chooser is performing.

setChoice
void setChoice(string id, string option)

Selects an option in a 'choice' that has been added with gtk_file_chooser_add_choice().

setCreateFolders
void setCreateFolders(bool createFolders)

Sets whether file chooser will offer to create new folders.

setCurrentFolder
bool setCurrentFolder(FileIF file)

Sets the current folder for @chooser from a #GFile.

setCurrentName
void setCurrentName(string name)

Sets the current name in the file selector, as if entered by the user.

setFile
bool setFile(FileIF file)

Sets @file as the current filename for the file chooser.

setFilter
void setFilter(FileFilter filter)

Sets the current filter.

setSelectMultiple
void setSelectMultiple(bool selectMultiple)

Sets whether multiple files can be selected in the file chooser.

Meta