[][src]Trait gtk::FileChooserExt

pub trait FileChooserExt: 'static {
    fn add_filter(&self, filter: &FileFilter);
fn add_shortcut_folder<P: AsRef<Path>>(
        &self,
        folder: P
    ) -> Result<(), Error>;
fn add_shortcut_folder_uri(&self, uri: &str) -> Result<(), Error>;
fn get_action(&self) -> FileChooserAction;
fn get_choice(&self, id: &str) -> Option<GString>;
fn get_create_folders(&self) -> bool;
fn get_current_folder(&self) -> Option<PathBuf>;
fn get_current_folder_file(&self) -> Option<File>;
fn get_current_folder_uri(&self) -> Option<GString>;
fn get_current_name(&self) -> Option<GString>;
fn get_do_overwrite_confirmation(&self) -> bool;
fn get_extra_widget(&self) -> Option<Widget>;
fn get_file(&self) -> Option<File>;
fn get_filename(&self) -> Option<PathBuf>;
fn get_filenames(&self) -> Vec<PathBuf>;
fn get_files(&self) -> Vec<File>;
fn get_filter(&self) -> Option<FileFilter>;
fn get_local_only(&self) -> bool;
fn get_preview_file(&self) -> Option<File>;
fn get_preview_filename(&self) -> Option<PathBuf>;
fn get_preview_uri(&self) -> Option<GString>;
fn get_preview_widget(&self) -> Option<Widget>;
fn get_preview_widget_active(&self) -> bool;
fn get_select_multiple(&self) -> bool;
fn get_show_hidden(&self) -> bool;
fn get_uri(&self) -> Option<GString>;
fn get_uris(&self) -> Vec<GString>;
fn get_use_preview_label(&self) -> bool;
fn list_filters(&self) -> Vec<FileFilter>;
fn list_shortcut_folder_uris(&self) -> Vec<GString>;
fn list_shortcut_folders(&self) -> Vec<PathBuf>;
fn remove_choice(&self, id: &str);
fn remove_filter(&self, filter: &FileFilter);
fn remove_shortcut_folder<P: AsRef<Path>>(
        &self,
        folder: P
    ) -> Result<(), Error>;
fn remove_shortcut_folder_uri(&self, uri: &str) -> Result<(), Error>;
fn select_all(&self);
fn select_file<P: IsA<File>>(&self, file: &P) -> Result<(), Error>;
fn select_filename<P: AsRef<Path>>(&self, filename: P) -> bool;
fn select_uri(&self, uri: &str) -> bool;
fn set_action(&self, action: FileChooserAction);
fn set_choice(&self, id: &str, option: &str);
fn set_create_folders(&self, create_folders: bool);
fn set_current_folder<P: AsRef<Path>>(&self, filename: P) -> bool;
fn set_current_folder_file<P: IsA<File>>(
        &self,
        file: &P
    ) -> Result<(), Error>;
fn set_current_folder_uri(&self, uri: &str) -> bool;
fn set_current_name<P: AsRef<Path>>(&self, name: P);
fn set_do_overwrite_confirmation(&self, do_overwrite_confirmation: bool);
fn set_extra_widget<P: IsA<Widget>>(&self, extra_widget: &P);
fn set_file<P: IsA<File>>(&self, file: &P) -> Result<(), Error>;
fn set_filename<P: AsRef<Path>>(&self, filename: P) -> bool;
fn set_filter(&self, filter: &FileFilter);
fn set_local_only(&self, local_only: bool);
fn set_preview_widget<P: IsA<Widget>>(&self, preview_widget: &P);
fn set_preview_widget_active(&self, active: bool);
fn set_select_multiple(&self, select_multiple: bool);
fn set_show_hidden(&self, show_hidden: bool);
fn set_uri(&self, uri: &str) -> bool;
fn set_use_preview_label(&self, use_label: bool);
fn unselect_all(&self);
fn unselect_file<P: IsA<File>>(&self, file: &P);
fn unselect_filename<P: AsRef<Path>>(&self, filename: P);
fn unselect_uri(&self, uri: &str);
fn connect_confirm_overwrite<F: Fn(&Self) -> FileChooserConfirmation + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_current_folder_changed<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_file_activated<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_selection_changed<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_update_preview<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_action_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_create_folders_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_do_overwrite_confirmation_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_extra_widget_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_filter_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_local_only_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_preview_widget_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_preview_widget_active_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_select_multiple_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_show_hidden_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
fn connect_property_use_preview_label_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; }

Trait containing all FileChooser methods.

Implementors

FileChooserButton, FileChooserDialog, FileChooserNative, FileChooserWidget, FileChooser

Required methods

fn add_filter(&self, filter: &FileFilter)

Adds filter to the list of filters that the user can select between. When a filter is selected, only files that are passed by that filter are displayed.

Note that the self takes ownership of the filter, so you have to ref and sink it if you want to keep a reference.

filter

a FileFilter

fn add_shortcut_folder<P: AsRef<Path>>(&self, folder: P) -> Result<(), Error>

Adds a folder to be displayed with the shortcut folders in a file chooser. Note that shortcut folders do not get saved, as they are provided by the application. For example, you can use this to add a “/usr/share/mydrawprogram/Clipart” folder to the volume list.

folder

filename of the folder to add

Returns

true if the folder could be added successfully, false otherwise. In the latter case, the error will be set as appropriate.

fn add_shortcut_folder_uri(&self, uri: &str) -> Result<(), Error>

Adds a folder URI to be displayed with the shortcut folders in a file chooser. Note that shortcut folders do not get saved, as they are provided by the application. For example, you can use this to add a “file:///usr/share/mydrawprogram/Clipart” folder to the volume list.

uri

URI of the folder to add

Returns

true if the folder could be added successfully, false otherwise. In the latter case, the error will be set as appropriate.

fn get_action(&self) -> FileChooserAction

Gets the type of operation that the file chooser is performing; see FileChooser::set_action.

Returns

the action that the file selector is performing

fn get_choice(&self, id: &str) -> Option<GString>

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

Feature: v3_22

id

the ID of the choice to get

Returns

the ID of the currenly selected option

fn get_create_folders(&self) -> bool

Gets whether file choser will offer to create new folders. See FileChooser::set_create_folders.

Returns

true if the Create Folder button should be displayed.

fn get_current_folder(&self) -> Option<PathBuf>

Gets the current folder of self as a local filename. See FileChooser::set_current_folder.

Note that this is the folder that the file chooser is currently displaying (e.g. "/home/username/Documents"), which is not the same as the currently-selected folder if the chooser is in FileChooserAction::SelectFolder mode (e.g. "/home/username/Documents/selected-folder/". To get the currently-selected folder in that mode, use FileChooser::get_uri as the usual way to get the selection.

Returns

the full path of the current folder, or None if the current path cannot be represented as a local filename. Free with g_free. This function will also return None if the file chooser was unable to load the last folder that was requested from it; for example, as would be for calling FileChooser::set_current_folder on a nonexistent folder.

fn get_current_folder_file(&self) -> Option<File>

Gets the current folder of self as gio::File. See FileChooser::get_current_folder_uri.

Returns

the gio::File for the current folder.

fn get_current_folder_uri(&self) -> Option<GString>

Gets the current folder of self as an URI. See FileChooser::set_current_folder_uri.

Note that this is the folder that the file chooser is currently displaying (e.g. "file:///home/username/Documents"), which is not the same as the currently-selected folder if the chooser is in FileChooserAction::SelectFolder mode (e.g. "file:///home/username/Documents/selected-folder/". To get the currently-selected folder in that mode, use FileChooser::get_uri as the usual way to get the selection.

Returns

the URI for the current folder. Free with g_free. This function will also return None if the file chooser was unable to load the last folder that was requested from it; for example, as would be for calling FileChooser::set_current_folder_uri on a nonexistent folder.

fn get_current_name(&self) -> Option<GString>

Gets the current name in the file selector, as entered by the user in the text entry for “Name”.

This is meant to be used in save dialogs, to get the currently typed filename when the file itself does not exist yet. For example, an application that adds a custom extra widget to the file chooser for “file format” may want to change the extension of the typed filename based on the chosen format, say, from “.jpg” to “.png”.

Returns

The raw text from the file chooser’s “Name” entry. Free this with g_free. Note that this string is not a full pathname or URI; it is whatever the contents of the entry are. Note also that this string is in UTF-8 encoding, which is not necessarily the system’s encoding for filenames.

fn get_do_overwrite_confirmation(&self) -> bool

Queries whether a file chooser is set to confirm for overwriting when the user types a file name that already exists.

Returns

true if the file chooser will present a confirmation dialog; false otherwise.

fn get_extra_widget(&self) -> Option<Widget>

Gets the current extra widget; see FileChooser::set_extra_widget.

Returns

the current extra widget, or None

fn get_file(&self) -> Option<File>

Gets the gio::File for the currently selected file in the file selector. 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.

Returns

a selected gio::File. You own the returned file; use gobject::ObjectExt::unref to release it.

fn get_filename(&self) -> Option<PathBuf>

Gets the filename for the currently selected file in the file selector. The filename is returned as an absolute path. If multiple files are selected, one of the filenames will be returned at random.

If the file chooser is in folder mode, this function returns the selected folder.

Returns

The currently selected filename, or None if no file is selected, or the selected file can't be represented with a local filename. Free with g_free.

fn get_filenames(&self) -> Vec<PathBuf>

Lists all the selected files and subfolders in the current folder of self. The returned names are full absolute paths. If files in the current folder cannot be represented as local filenames they will be ignored. (See FileChooser::get_uris)

Returns

a glib::SList containing the filenames of all selected files and subfolders in the current folder. Free the returned list with glib::SList::free, and the filenames with g_free.

fn get_files(&self) -> Vec<File>

Lists all the selected files and subfolders in the current folder of self as gio::File. An internal function, see FileChooser::get_uris.

Returns

a glib::SList containing a gio::File for each selected file and subfolder in the current folder. Free the returned list with glib::SList::free, and the files with gobject::ObjectExt::unref.

fn get_filter(&self) -> Option<FileFilter>

Gets the current filter; see FileChooser::set_filter.

Returns

the current filter, or None

fn get_local_only(&self) -> bool

Gets whether only local files can be selected in the file selector. See FileChooser::set_local_only

Returns

true if only local files can be selected.

fn get_preview_file(&self) -> Option<File>

Gets the gio::File that should be previewed in a custom preview Internal function, see FileChooser::get_preview_uri.

Returns

the gio::File for the file to preview, or None if no file is selected. Free with gobject::ObjectExt::unref.

fn get_preview_filename(&self) -> Option<PathBuf>

Gets the filename that should be previewed in a custom preview widget. See FileChooser::set_preview_widget.

Returns

the filename to preview, or None if no file is selected, or if the selected file cannot be represented as a local filename. Free with g_free

fn get_preview_uri(&self) -> Option<GString>

Gets the URI that should be previewed in a custom preview widget. See FileChooser::set_preview_widget.

Returns

the URI for the file to preview, or None if no file is selected. Free with g_free.

fn get_preview_widget(&self) -> Option<Widget>

Gets the current preview widget; see FileChooser::set_preview_widget.

Returns

the current preview widget, or None

fn get_preview_widget_active(&self) -> bool

Gets whether the preview widget set by FileChooser::set_preview_widget should be shown for the current filename. See FileChooser::set_preview_widget_active.

Returns

true if the preview widget is active for the current filename.

fn get_select_multiple(&self) -> bool

Gets whether multiple files can be selected in the file selector. See FileChooser::set_select_multiple.

Returns

true if multiple files can be selected.

fn get_show_hidden(&self) -> bool

Gets whether hidden files and folders are displayed in the file selector. See FileChooser::set_show_hidden.

Returns

true if hidden files and folders are displayed.

fn get_uri(&self) -> Option<GString>

Gets the URI for the currently selected file in the file selector. If multiple files are selected, one of the filenames will be returned at random.

If the file chooser is in folder mode, this function returns the selected folder.

Returns

The currently selected URI, or None if no file is selected. If FileChooser::set_local_only is set to true (the default) a local URI will be returned for any FUSE locations. Free with g_free

fn get_uris(&self) -> Vec<GString>

Lists all the selected files and subfolders in the current folder of self. The returned names are full absolute URIs.

Returns

a glib::SList containing the URIs of all selected files and subfolders in the current folder. Free the returned list with glib::SList::free, and the filenames with g_free.

fn get_use_preview_label(&self) -> bool

Gets whether a stock label should be drawn with the name of the previewed file. See FileChooser::set_use_preview_label.

Returns

true if the file chooser is set to display a label with the name of the previewed file, false otherwise.

fn list_filters(&self) -> Vec<FileFilter>

Lists the current set of user-selectable filters; see FileChooser::add_filter, FileChooser::remove_filter.

Returns

a glib::SList containing the current set of user selectable filters. The contents of the list are owned by GTK+, but you must free the list itself with glib::SList::free when you are done with it.

fn list_shortcut_folder_uris(&self) -> Vec<GString>

Queries the list of shortcut folders in the file chooser, as set by FileChooser::add_shortcut_folder_uri.

Returns

A list of folder URIs, or None if there are no shortcut folders. Free the returned list with glib::SList::free, and the URIs with g_free.

fn list_shortcut_folders(&self) -> Vec<PathBuf>

Queries the list of shortcut folders in the file chooser, as set by FileChooser::add_shortcut_folder.

Returns

A list of folder filenames, or None if there are no shortcut folders. Free the returned list with glib::SList::free, and the filenames with g_free.

fn remove_choice(&self, id: &str)

Removes a 'choice' that has been added with FileChooser::add_choice.

Feature: v3_22

id

the ID of the choice to remove

fn remove_filter(&self, filter: &FileFilter)

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

filter

a FileFilter

fn remove_shortcut_folder<P: AsRef<Path>>(&self, folder: P) -> Result<(), Error>

Removes a folder from a file chooser’s list of shortcut folders.

folder

filename of the folder to remove

Returns

true if the operation succeeds, false otherwise. In the latter case, the error will be set as appropriate.

See also: FileChooser::add_shortcut_folder

fn remove_shortcut_folder_uri(&self, uri: &str) -> Result<(), Error>

Removes a folder URI from a file chooser’s list of shortcut folders.

uri

URI of the folder to remove

Returns

true if the operation succeeds, false otherwise. In the latter case, the error will be set as appropriate.

See also: FileChooser::add_shortcut_folder_uri

fn select_all(&self)

Selects all the files in the current folder of a file chooser.

fn select_file<P: IsA<File>>(&self, file: &P) -> Result<(), Error>

Selects the file referred to by file. An internal function. See _gtk_file_chooser_select_uri.

file

the file to select

Returns

Not useful.

fn select_filename<P: AsRef<Path>>(&self, filename: P) -> bool

Selects a filename. If the file name isn’t in the current folder of self, then the current folder of self will be changed to the folder containing filename.

filename

the filename to select

Returns

Not useful.

See also: FileChooser::set_filename

fn select_uri(&self, uri: &str) -> bool

Selects the file to by uri. If the URI doesn’t refer to a file in the current folder of self, then the current folder of self will be changed to the folder containing filename.

uri

the URI to select

Returns

Not useful.

fn set_action(&self, action: FileChooserAction)

Sets the type of operation that the chooser is performing; the user interface is adapted to suit the selected action. For example, an option to create a new folder might be shown if the action is FileChooserAction::Save but not if the action is FileChooserAction::Open.

action

the action that the file selector is performing

fn set_choice(&self, id: &str, option: &str)

Selects an option in a 'choice' that has been added with FileChooser::add_choice. For a boolean choice, the possible options are "true" and "false".

Feature: v3_22

id

the ID of the choice to set

option

the ID of the option to select

fn set_create_folders(&self, create_folders: bool)

Sets whether file choser will offer to create new folders. This is only relevant if the action is not set to be FileChooserAction::Open.

create_folders

true if the Create Folder button should be displayed

fn set_current_folder<P: AsRef<Path>>(&self, filename: P) -> bool

Sets the current folder for self from a local filename. The user will be shown the full contents of the current folder, plus user interface elements for navigating to other folders.

In general, you should not use this function. See the [section on setting up a file chooser dialog][gtkfilechooserdialog-setting-up] for the rationale behind this.

filename

the full path of the new current folder

Returns

Not useful.

fn set_current_folder_file<P: IsA<File>>(&self, file: &P) -> Result<(), Error>

Sets the current folder for self from a gio::File. Internal function, see FileChooser::set_current_folder_uri.

file

the gio::File for the new folder

Returns

true if the folder could be changed successfully, false otherwise.

fn set_current_folder_uri(&self, uri: &str) -> bool

Sets the current folder for self from an URI. The user will be shown the full contents of the current folder, plus user interface elements for navigating to other folders.

In general, you should not use this function. See the [section on setting up a file chooser dialog][gtkfilechooserdialog-setting-up] for the rationale behind this.

uri

the URI for the new current folder

Returns

true if the folder could be changed successfully, false otherwise.

fn set_current_name<P: AsRef<Path>>(&self, name: P)

Sets the current name in the file selector, as if entered by the user. Note that the name passed in here is a UTF-8 string rather than a filename. This function is meant for such uses as a suggested name in a “Save As...” dialog. You can pass “Untitled.doc” or a similarly suitable suggestion for the name.

If you want to preselect a particular existing file, you should use FileChooser::set_filename or FileChooser::set_uri instead. Please see the documentation for those functions for an example of using FileChooser::set_current_name as well.

name

the filename to use, as a UTF-8 string

fn set_do_overwrite_confirmation(&self, do_overwrite_confirmation: bool)

Sets whether a file chooser in FileChooserAction::Save mode will present a confirmation dialog if the user types a file name that already exists. This is false by default.

If set to true, the self will emit the FileChooser::confirm-overwrite signal when appropriate.

If all you need is the stock confirmation dialog, set this property to true. You can override the way confirmation is done by actually handling the FileChooser::confirm-overwrite signal; please refer to its documentation for the details.

do_overwrite_confirmation

whether to confirm overwriting in save mode

fn set_extra_widget<P: IsA<Widget>>(&self, extra_widget: &P)

Sets an application-supplied widget to provide extra options to the user.

extra_widget

widget for extra options

fn set_file<P: IsA<File>>(&self, file: &P) -> Result<(), Error>

Sets file as the current filename for the file chooser, by changing to the file’s parent folder and actually selecting the file in list. If the self is in FileChooserAction::Save mode, the file’s base name will also appear in the dialog’s file name entry.

If the file name isn’t in the current folder of self, then the current folder of self will be changed to the folder containing filename. This is equivalent to a sequence of FileChooser::unselect_all followed by FileChooser::select_filename.

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

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 Save As... If you don’t 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)
  {
    // the user just created a new document
    gtk_file_chooser_set_current_folder_file (chooser, default_file_for_saving);
    gtk_file_chooser_set_current_name (chooser, "Untitled document");
  }
else
  {
    // the user edited an existing document
    gtk_file_chooser_set_file (chooser, existing_file);
  }

file

the gio::File to set as current

Returns

Not useful.

fn set_filename<P: AsRef<Path>>(&self, filename: P) -> bool

Sets filename as the current filename for the file chooser, by changing to the file’s parent folder and actually selecting the file in list; all other files will be unselected. If the self is in FileChooserAction::Save mode, the file’s base name will also appear in the dialog’s file name entry.

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

You should use this function only when implementing a save dialog for which you already have a file name to which the user may save. For example, when the user opens an existing file and then does Save As... to save a copy or a modified version. If you don’t 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)
  {
    // the user just created a new document
    gtk_file_chooser_set_current_name (chooser, "Untitled document");
  }
else
  {
    // the user edited an existing document
    gtk_file_chooser_set_filename (chooser, existing_filename);
  }

In the first case, the file chooser will present the user with useful suggestions as to where to save his new file. In the second case, the file’s existing location is already known, so the file chooser will use it.

filename

the filename to set as current

Returns

Not useful.

fn set_filter(&self, filter: &FileFilter)

Sets the current filter; only the files that pass the filter will be displayed. If the user-selectable list of filters is non-empty, then the filter should be one of the filters in that list. Setting the current filter when the list of filters is empty is useful if you want to restrict the displayed set of files without letting the user change it.

filter

a FileFilter

fn set_local_only(&self, local_only: bool)

Sets whether only local files can be selected in the file selector. If local_only is true (the default), then the selected file or files are guaranteed to be accessible through the operating systems native file system and therefore the application only needs to worry about the filename functions in FileChooser, like FileChooser::get_filename, rather than the URI functions like FileChooser::get_uri,

On some systems non-native files may still be available using the native filesystem via a userspace filesystem (FUSE).

local_only

true if only local files can be selected

fn set_preview_widget<P: IsA<Widget>>(&self, preview_widget: &P)

Sets an application-supplied widget to use to display a custom preview of the currently selected file. To implement a preview, after setting the preview widget, you connect to the FileChooser::update-preview signal, and call FileChooser::get_preview_filename or FileChooser::get_preview_uri on each change. If you can display a preview of the new file, update your widget and set the preview active using FileChooser::set_preview_widget_active. Otherwise, set the preview inactive.

When there is no application-supplied preview widget, or the application-supplied preview widget is not active, the file chooser will display no preview at all.

preview_widget

widget for displaying preview.

fn set_preview_widget_active(&self, active: bool)

Sets whether the preview widget set by FileChooser::set_preview_widget should be shown for the current filename. When active is set to false, the file chooser may display an internally generated preview of the current file or it may display no preview at all. See FileChooser::set_preview_widget for more details.

active

whether to display the user-specified preview widget

fn set_select_multiple(&self, select_multiple: bool)

Sets whether multiple files can be selected in the file selector. This is only relevant if the action is set to be FileChooserAction::Open or FileChooserAction::SelectFolder.

select_multiple

true if multiple files can be selected.

fn set_show_hidden(&self, show_hidden: bool)

Sets whether hidden files and folders are displayed in the file selector.

show_hidden

true if hidden files and folders should be displayed.

fn set_uri(&self, uri: &str) -> bool

Sets the file referred to by uri as the current file for the file chooser, by changing to the URI’s parent folder and actually selecting the URI in the list. If the self is FileChooserAction::Save mode, the URI’s base name will also appear in the dialog’s file name entry.

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

You should use this function only when implementing a save dialog for which you already have a file name to which the user may save. For example, when the user opens an existing file and then does Save As... to save a copy or a modified version. If you don’t 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)
  {
    // the user just created a new document
    gtk_file_chooser_set_current_name (chooser, "Untitled document");
  }
else
  {
    // the user edited an existing document
    gtk_file_chooser_set_uri (chooser, existing_uri);
  }

In the first case, the file chooser will present the user with useful suggestions as to where to save his new file. In the second case, the file’s existing location is already known, so the file chooser will use it.

uri

the URI to set as current

Returns

Not useful.

fn set_use_preview_label(&self, use_label: bool)

Sets whether the file chooser should display a stock label with the name of the file that is being previewed; the default is true. Applications that want to draw the whole preview area themselves should set this to false and display the name themselves in their preview widget.

See also: FileChooser::set_preview_widget

use_label

whether to display a stock label with the name of the previewed file

fn unselect_all(&self)

Unselects all the files in the current folder of a file chooser.

fn unselect_file<P: IsA<File>>(&self, file: &P)

Unselects the file referred to by file. If the file is not in the current directory, does not exist, or is otherwise not currently selected, does nothing.

file

a gio::File

fn unselect_filename<P: AsRef<Path>>(&self, filename: P)

Unselects a currently selected filename. If the filename is not in the current directory, does not exist, or is otherwise not currently selected, does nothing.

filename

the filename to unselect

fn unselect_uri(&self, uri: &str)

Unselects the file referred to by uri. If the file is not in the current directory, does not exist, or is otherwise not currently selected, does nothing.

uri

the URI to unselect

fn connect_confirm_overwrite<F: Fn(&Self) -> FileChooserConfirmation + 'static>(
    &self,
    f: F
) -> SignalHandlerId

This signal gets emitted whenever it is appropriate to present a confirmation dialog when the user has selected a file name that already exists. The signal only gets emitted when the file chooser is in FileChooserAction::Save mode.

Most applications just need to turn on the FileChooser:do-overwrite-confirmation property (or call the FileChooser::set_do_overwrite_confirmation function), and they will automatically get a stock confirmation dialog. Applications which need to customize this behavior should do that, and also connect to the FileChooser::confirm-overwrite signal.

A signal handler for this signal must return a FileChooserConfirmation value, which indicates the action to take. If the handler determines that the user wants to select a different filename, it should return FileChooserConfirmation::SelectAgain. If it determines that the user is satisfied with his choice of file name, it should return FileChooserConfirmation::AcceptFilename. On the other hand, if it determines that the stock confirmation dialog should be used, it should return FileChooserConfirmation::Confirm. The following example illustrates this.

Custom confirmation ## {gtkfilechooser-confirmation}

static GtkFileChooserConfirmation
confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
{
  char *uri;

  uri = gtk_file_chooser_get_uri (chooser);

  if (is_uri_read_only (uri))
    {
      if (user_wants_to_replace_read_only_file (uri))
        return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
      else
        return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
    } else
      return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog
}

...

chooser = gtk_file_chooser_dialog_new (...);

gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
g_signal_connect (chooser, "confirm-overwrite",
                  G_CALLBACK (confirm_overwrite_callback), NULL);

if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
        save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));

gtk_widget_destroy (chooser);

Returns

a FileChooserConfirmation value that indicates which action to take after emitting the signal.

fn connect_current_folder_changed<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

This signal is emitted when the current folder in a FileChooser changes. This can happen due to the user performing some action that changes folders, such as selecting a bookmark or visiting a folder on the file list. It can also happen as a result of calling a function to explicitly change the current folder in a file chooser.

Normally you do not need to connect to this signal, unless you need to keep track of which folder a file chooser is showing.

See also: FileChooser::set_current_folder, FileChooser::get_current_folder, FileChooser::set_current_folder_uri, FileChooser::get_current_folder_uri.

fn connect_file_activated<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

This signal is emitted when the user "activates" a file in the file chooser. This can happen by double-clicking on a file in the file list, or by pressing Enter.

Normally you do not need to connect to this signal. It is used internally by FileChooserDialog to know when to activate the default button in the dialog.

See also: FileChooser::get_filename, FileChooser::get_filenames, FileChooser::get_uri, FileChooser::get_uris.

fn connect_selection_changed<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

This signal is emitted when there is a change in the set of selected files in a FileChooser. This can happen when the user modifies the selection with the mouse or the keyboard, or when explicitly calling functions to change the selection.

Normally you do not need to connect to this signal, as it is easier to wait for the file chooser to finish running, and then to get the list of selected files using the functions mentioned below.

See also: FileChooser::select_filename, FileChooser::unselect_filename, FileChooser::get_filename, FileChooser::get_filenames, FileChooser::select_uri, FileChooser::unselect_uri, FileChooser::get_uri, FileChooser::get_uris.

fn connect_update_preview<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

This signal is emitted when the preview in a file chooser should be regenerated. For example, this can happen when the currently selected file changes. You should use this signal if you want your file chooser to have a preview widget.

Once you have installed a preview widget with FileChooser::set_preview_widget, you should update it when this signal is emitted. You can use the functions FileChooser::get_preview_filename or FileChooser::get_preview_uri to get the name of the file to preview. Your widget may not be able to preview all kinds of files; your callback must call FileChooser::set_preview_widget_active to inform the file chooser about whether the preview was generated successfully or not.

Please see the example code in [Using a Preview Widget][gtkfilechooser-preview].

See also: FileChooser::set_preview_widget, FileChooser::set_preview_widget_active, FileChooser::set_use_preview_label, FileChooser::get_preview_filename, FileChooser::get_preview_uri.

fn connect_property_action_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_create_folders_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_do_overwrite_confirmation_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_extra_widget_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_filter_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_local_only_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_preview_widget_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_preview_widget_active_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_select_multiple_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_show_hidden_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

fn connect_property_use_preview_label_notify<F: Fn(&Self) + 'static>(
    &self,
    f: F
) -> SignalHandlerId

Loading content...

Implementors

impl<O: IsA<FileChooser>> FileChooserExt for O[src]

Loading content...