set_file


Description:

public bool set_file (File file) throws Error

Sets file as the current filename for the file chooser.

This includes changing to the file’s parent folder and actually selecting the file in list. If the this is in gtk_file_chooser_action_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 this, then the current folder of this will be changed to the folder containing file.

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:

```c static void prepare_file_chooser (GtkFileChooser *chooser, GFile *existing_file) { gboolean document_is_new = (existing_file == NULL);

if (document_is_new) { GFile *default_file_for_saving = g_file_new_for_path ("./out.txt"); // the user just created a new document gtk_file_chooser_set_current_folder (chooser, default_file_for_saving, NULL); gtk_file_chooser_set_current_name (chooser, "Untitled document"); g_object_unref (default_file_for_saving); } else { // the user edited an existing document gtk_file_chooser_set_file ( chooser, existing_file, NULL); } } ```

Parameters:

this

a `GtkFileChooser`

file

the `GFile` to set as current

Returns:

Not useful




2022 vala-language.org