diff options
author | Benjamin Otte <otte@redhat.com> | 2022-12-23 05:54:32 +0100 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-12-24 07:56:57 -0500 |
commit | e2f730c0bfa6dbcf0e57369e957e6d1dfb9865e6 (patch) | |
tree | f9a495c48dda6214d306506476e9ac371f109221 | |
parent | 8a2d35b9fbe5f6c63c1f26aeee612b5632db4208 (diff) | |
download | gtk+-e2f730c0bfa6dbcf0e57369e957e6d1dfb9865e6.tar.gz |
filedialog: Add gtk_file_dialog_set_initial_file()
A shortcut for setting initial-folder and initial-name at the same time.
We can remove all arguments from the actual async calls this way.
-rw-r--r-- | demos/constraint-editor/constraint-editor-window.c | 4 | ||||
-rw-r--r-- | demos/gtk-demo/application.c | 2 | ||||
-rw-r--r-- | demos/gtk-demo/clipboard.c | 7 | ||||
-rw-r--r-- | demos/gtk-demo/listview_words.c | 1 | ||||
-rw-r--r-- | demos/gtk-demo/paintable_svg.c | 1 | ||||
-rw-r--r-- | demos/gtk-demo/pickers.c | 2 | ||||
-rw-r--r-- | demos/gtk-demo/video_player.c | 1 | ||||
-rw-r--r-- | demos/node-editor/node-editor-window.c | 4 | ||||
-rw-r--r-- | demos/print-editor/print-editor.c | 2 | ||||
-rw-r--r-- | demos/widget-factory/widget-factory.c | 2 | ||||
-rw-r--r-- | gtk/gtkfiledialog.c | 181 | ||||
-rw-r--r-- | gtk/gtkfiledialog.h | 11 | ||||
-rw-r--r-- | gtk/gtkprinteroptionwidget.c | 25 | ||||
-rw-r--r-- | gtk/inspector/css-editor.c | 2 | ||||
-rw-r--r-- | gtk/inspector/recorder.c | 2 |
15 files changed, 172 insertions, 75 deletions
diff --git a/demos/constraint-editor/constraint-editor-window.c b/demos/constraint-editor/constraint-editor-window.c index 1f81ac4a42..ab084ef62b 100644 --- a/demos/constraint-editor/constraint-editor-window.c +++ b/demos/constraint-editor/constraint-editor-window.c @@ -230,7 +230,7 @@ open_cb (GtkWidget *button, cwd = g_file_new_for_path ("."); gtk_file_dialog_set_initial_folder (dialog, cwd); g_object_unref (cwd); - gtk_file_dialog_open (dialog, GTK_WINDOW (self), NULL, NULL, open_response_cb, self); + gtk_file_dialog_open (dialog, GTK_WINDOW (self), NULL, open_response_cb, self); g_object_unref (dialog); } @@ -341,7 +341,7 @@ save_cb (GtkWidget *button, g_object_unref (cwd); gtk_file_dialog_save (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))), - NULL, NULL, + NULL, save_response_cb, self); g_object_unref (dialog); } diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c index 4570d06452..56567b197b 100644 --- a/demos/gtk-demo/application.c +++ b/demos/gtk-demo/application.c @@ -124,7 +124,7 @@ activate_open (GSimpleAction *action, GtkFileDialog *dialog; dialog = gtk_file_dialog_new (); - gtk_file_dialog_open (dialog, NULL, NULL, NULL, open_response_cb, g_object_ref (app)); + gtk_file_dialog_open (dialog, NULL, NULL, open_response_cb, g_object_ref (app)); g_object_unref (dialog); } diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c index 753ecb32d9..672a51ac44 100644 --- a/demos/gtk-demo/clipboard.c +++ b/demos/gtk-demo/clipboard.c @@ -244,8 +244,9 @@ open_file_cb (GtkWidget *button) gtk_file_dialog_open (dialog, GTK_WINDOW (gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW)), NULL, - NULL, file_chooser_response, button); + + g_object_unref (dialog); } static void @@ -277,9 +278,11 @@ open_folder_cb (GtkWidget *button) gtk_file_dialog_select_folder (dialog, GTK_WINDOW (gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW)), NULL, - NULL, folder_chooser_response, button); + + g_object_unref (dialog); } + static void update_paste_button_sensitivity (GdkClipboard *clipboard, GtkWidget *paste_button) diff --git a/demos/gtk-demo/listview_words.c b/demos/gtk-demo/listview_words.c index 235af6a31e..1004aebbec 100644 --- a/demos/gtk-demo/listview_words.c +++ b/demos/gtk-demo/listview_words.c @@ -167,7 +167,6 @@ file_open_cb (GtkWidget *button, gtk_file_dialog_open (dialog, GTK_WINDOW (gtk_widget_get_root (button)), NULL, - NULL, open_response_cb, stringlist); g_object_unref (dialog); } diff --git a/demos/gtk-demo/paintable_svg.c b/demos/gtk-demo/paintable_svg.c index 5d73fd91bb..ecbe6a8d80 100644 --- a/demos/gtk-demo/paintable_svg.c +++ b/demos/gtk-demo/paintable_svg.c @@ -55,7 +55,6 @@ show_file_open (GtkWidget *button, gtk_file_dialog_open (dialog, GTK_WINDOW (gtk_widget_get_root (button)), NULL, - NULL, open_response_cb, picture); } diff --git a/demos/gtk-demo/pickers.c b/demos/gtk-demo/pickers.c index bed57cecc5..6f48a28a9a 100644 --- a/demos/gtk-demo/pickers.c +++ b/demos/gtk-demo/pickers.c @@ -66,7 +66,7 @@ open_file (GtkButton *picker, 20, abort_mission, g_object_ref (cancellable), g_object_unref); - gtk_file_dialog_open (dialog, parent, NULL, cancellable, file_opened, label); + gtk_file_dialog_open (dialog, parent, cancellable, file_opened, label); g_object_unref (cancellable); g_object_unref (dialog); diff --git a/demos/gtk-demo/video_player.c b/demos/gtk-demo/video_player.c index b6909472a5..78e7c69102 100644 --- a/demos/gtk-demo/video_player.c +++ b/demos/gtk-demo/video_player.c @@ -65,7 +65,6 @@ open_clicked_cb (GtkWidget *button, gtk_file_dialog_open (dialog, GTK_WINDOW (gtk_widget_get_root (button)), NULL, - NULL, open_dialog_response_cb, video); } diff --git a/demos/node-editor/node-editor-window.c b/demos/node-editor/node-editor-window.c index b790eda124..c3b876ac5e 100644 --- a/demos/node-editor/node-editor-window.c +++ b/demos/node-editor/node-editor-window.c @@ -572,7 +572,7 @@ show_open_filechooser (NodeEditorWindow *self) gtk_file_dialog_set_initial_folder (dialog, cwd); g_object_unref (cwd); gtk_file_dialog_open (dialog, GTK_WINDOW (self), - NULL, NULL, open_response_cb, self); + NULL, open_response_cb, self); g_object_unref (dialog); } @@ -639,7 +639,6 @@ save_cb (GtkWidget *button, gtk_file_dialog_save (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))), NULL, - NULL, save_response_cb, self); g_object_unref (dialog); } @@ -746,7 +745,6 @@ export_image_cb (GtkWidget *button, gtk_file_dialog_save (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))), NULL, - NULL, export_image_response_cb, texture); g_object_unref (dialog); } diff --git a/demos/print-editor/print-editor.c b/demos/print-editor/print-editor.c index daa95c0610..bf45b6945d 100644 --- a/demos/print-editor/print-editor.c +++ b/demos/print-editor/print-editor.c @@ -508,7 +508,6 @@ activate_save_as (GSimpleAction *action, gtk_file_dialog_save (dialog, GTK_WINDOW (main_window), NULL, - NULL, on_save_response, NULL); g_object_unref (dialog); } @@ -552,7 +551,6 @@ activate_open (GSimpleAction *action, gtk_file_dialog_open (dialog, GTK_WINDOW (main_window), NULL, - NULL, on_open_response, NULL); g_object_unref (dialog); } diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index 16b041933f..99fd76c258 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -237,7 +237,7 @@ activate_open_file (GSimpleAction *action, GtkFileDialog *dialog; dialog = gtk_file_dialog_new (); - gtk_file_dialog_open (dialog, NULL, NULL, NULL, file_chooser_response, NULL); + gtk_file_dialog_open (dialog, NULL, NULL, file_chooser_response, NULL); g_object_unref (dialog); } diff --git a/gtk/gtkfiledialog.c b/gtk/gtkfiledialog.c index c8242a1bc8..9e4d8723f0 100644 --- a/gtk/gtkfiledialog.c +++ b/gtk/gtkfiledialog.c @@ -60,6 +60,7 @@ struct _GtkFileDialog GtkFileFilter *current_filter; GFile *initial_folder; char *initial_name; + GFile *initial_file; }; enum @@ -68,6 +69,7 @@ enum PROP_ACCEPT_LABEL, PROP_CURRENT_FILTER, PROP_FILTERS, + PROP_INITIAL_FILE, PROP_INITIAL_FOLDER, PROP_INITIAL_NAME, PROP_MODAL, @@ -133,6 +135,10 @@ gtk_file_dialog_get_property (GObject *object, g_value_set_object (value, self->current_filter); break; + case PROP_INITIAL_FILE: + g_value_set_object (value, self->initial_file); + break; + case PROP_INITIAL_FOLDER: g_value_set_object (value, self->initial_folder); break; @@ -181,6 +187,10 @@ gtk_file_dialog_set_property (GObject *object, gtk_file_dialog_set_current_filter (self, g_value_get_object (value)); break; + case PROP_INITIAL_FILE: + gtk_file_dialog_set_initial_file (self, g_value_get_object (value)); + break; + case PROP_INITIAL_FOLDER: gtk_file_dialog_set_initial_folder (self, g_value_get_object (value)); break; @@ -270,11 +280,26 @@ gtk_file_dialog_class_init (GtkFileDialogClass *class) G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY); /** + * GtkFileDialog:initial-file: (attributes org.gtk.Property.get=gtk_file_dialog_get_initial_file org.gtk.Property.set=gtk_file_dialog_set_initial_file) + * + * The inital file, that is, the file that is initially selected + * in the file chooser dialog + * + * This is a utility property that sets both [property@Gtk.FileDialog:initial-folder] and + * [property@Gtk.FileDialog:initial-name]. + * + * Since: 4.10 + */ + properties[PROP_INITIAL_FILE] = + g_param_spec_object ("initial-file", NULL, NULL, + G_TYPE_FILE, + G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY); + + /** * GtkFileDialog:initial-folder: (attributes org.gtk.Property.get=gtk_file_dialog_get_initial_folder org.gtk.Property.set=gtk_file_dialog_set_initial_folder) * * The inital folder, that is, the directory that is initially - * opened in the file chooser dialog, unless overridden by parameters - * of the async call. + * opened in the file chooser dialog * * Since: 4.10 */ @@ -622,9 +647,7 @@ gtk_file_dialog_get_initial_folder (GtkFileDialog *self) * @folder: (nullable): a `GFile` * * Sets the folder that will be set as the - * initial folder in the file chooser dialog, - * unless overridden by parameters of the async - * call. + * initial folder in the file chooser dialog. * * Since: 4.10 */ @@ -638,6 +661,14 @@ gtk_file_dialog_set_initial_folder (GtkFileDialog *self, if (!g_set_object (&self->initial_folder, folder)) return; + if (self->initial_name) + { + g_clear_object (&self->initial_file); + self->initial_file = g_file_get_child_for_display_name (self->initial_folder, + self->initial_name, + NULL); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FILE]); + } g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FOLDER]); } @@ -681,9 +712,112 @@ gtk_file_dialog_set_initial_name (GtkFileDialog *self, if (!g_set_str (&self->initial_name, name)) return; + if (self->initial_name) + { + g_clear_object (&self->initial_file); + self->initial_file = g_file_get_child_for_display_name (self->initial_folder, + self->initial_name, + NULL); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FILE]); + } g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_NAME]); } +/** + * gtk_file_dialog_get_initial_file: + * @self: a `GtkFileDialog` + * + * Gets the file that will be initially selected in + * the file chooser dialog. + * + * Returns: (nullable) (transfer none): the file + * + * Since: 4.10 + */ +GFile * +gtk_file_dialog_get_initial_file (GtkFileDialog *self) +{ + g_return_val_if_fail (GTK_IS_FILE_DIALOG (self), NULL); + + return self->initial_file; +} + +/** + * gtk_file_dialog_set_initial_file: + * @self: a `GtkFileDialog` + * @file: (nullable): a `GFile` + * + * Sets the file that will be initially selected in + * the file chooser dialog. + * + * This function is a shortcut for calling both + * gtk_file_dialog_set_initial_folder() and + * gtk_file_dialog_set_initial_name() with the directory and + * name of @file respectively. + * + * Since: 4.10 + */ +void +gtk_file_dialog_set_initial_file (GtkFileDialog *self, + GFile *file) +{ + g_return_if_fail (GTK_IS_FILE_DIALOG (self)); + g_return_if_fail (file == NULL || G_IS_FILE (file)); + + g_object_freeze_notify (G_OBJECT (self)); + + if (file != NULL) + { + GFile *folder; + GFileInfo *info; + + if (g_file_equal (self->initial_file, file)) + return; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FILE]); + + folder = g_file_get_parent (file); + if (folder == NULL) + goto invalid_file; + + if (g_set_object (&self->initial_folder, NULL)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FOLDER]); + + info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME, 0, NULL, NULL); + if (g_file_info_get_edit_name (info) != NULL) + { + if (g_set_str (&self->initial_name, g_file_info_get_edit_name (info))) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_NAME]); + } + else + { + char *relative, *name; + + relative = g_file_get_relative_path (folder, file); + name = g_filename_display_name (relative); + if (g_set_str (&self->initial_name, name)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_NAME]); + + g_free (name); + g_free (relative); + } + g_object_unref (info); + g_object_unref (folder); + } + else + { +invalid_file: + if (g_set_object (&self->initial_file, NULL)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FILE]); + if (g_set_object (&self->initial_folder, NULL)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FOLDER]); + if (g_set_str (&self->initial_name, NULL)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_NAME]); + } + + g_object_thaw_notify (G_OBJECT (self)); +} + /* }}} */ /* {{{ Async implementation */ @@ -743,7 +877,6 @@ static GtkFileChooserNative * create_file_chooser (GtkFileDialog *self, GtkWindow *parent, GtkFileChooserAction action, - GFile *current_file, gboolean select_multiple) { GtkFileChooserNative *chooser; @@ -803,8 +936,8 @@ create_file_chooser (GtkFileDialog *self, file_chooser_set_shortcut_folders (GTK_FILE_CHOOSER (chooser), self->shortcut_folders); if (self->initial_folder) gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser), self->initial_folder, NULL); - if (current_file) - gtk_file_chooser_set_file (GTK_FILE_CHOOSER (chooser), current_file, NULL); + if (self->initial_file) + gtk_file_chooser_set_file (GTK_FILE_CHOOSER (chooser), self->initial_file, NULL); else if (self->initial_name) gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser), self->initial_name); @@ -850,7 +983,6 @@ finish_multiple_files_op (GtkFileDialog *self, * gtk_file_dialog_open: * @self: a `GtkFileDialog` * @parent: (nullable): the parent `GtkWindow` - * @current_file: (nullable): the file to select initially * @cancellable: (nullable): a `GCancellable` to cancel the operation * @callback: (scope async): a callback to call when the operation is complete * @user_data: (closure callback): data to pass to @callback @@ -858,10 +990,6 @@ finish_multiple_files_op (GtkFileDialog *self, * This function initiates a file selection operation by * presenting a file chooser dialog to the user. * - * If you pass @current_file, the file chooser will initially be - * opened in the parent directory of that file, otherwise, it - * will be in the directory [property@Gtk.FileDialog:initial-folder]. - * * The @callback will be called when the dialog is dismissed. * It should call [method@Gtk.FileDialog.open_finish] * to obtain the result. @@ -871,7 +999,6 @@ finish_multiple_files_op (GtkFileDialog *self, void gtk_file_dialog_open (GtkFileDialog *self, GtkWindow *parent, - GFile *current_file, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -881,8 +1008,7 @@ gtk_file_dialog_open (GtkFileDialog *self, g_return_if_fail (GTK_IS_FILE_DIALOG (self)); - chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_OPEN, - current_file, FALSE); + chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_OPEN, FALSE); task = g_task_new (self, cancellable, callback, user_data); g_task_set_check_cancellable (task, FALSE); @@ -927,7 +1053,6 @@ gtk_file_dialog_open_finish (GtkFileDialog *self, * gtk_file_dialog_select_folder: * @self: a `GtkFileDialog` * @parent: (nullable): the parent `GtkWindow` - * @initial_folder: (nullable): the folder to select initially * @cancellable: (nullable): a `GCancellable` to cancel the operation * @callback: (scope async): a callback to call when the operation is complete * @user_data: (closure callback): data to pass to @callback @@ -948,7 +1073,6 @@ gtk_file_dialog_open_finish (GtkFileDialog *self, void gtk_file_dialog_select_folder (GtkFileDialog *self, GtkWindow *parent, - GFile *initial_folder, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -958,8 +1082,7 @@ gtk_file_dialog_select_folder (GtkFileDialog *self, g_return_if_fail (GTK_IS_FILE_DIALOG (self)); - chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - initial_folder, FALSE); + chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, FALSE); task = g_task_new (self, cancellable, callback, user_data); g_task_set_check_cancellable (task, FALSE); @@ -1004,7 +1127,6 @@ gtk_file_dialog_select_folder_finish (GtkFileDialog *self, * gtk_file_dialog_save: * @self: a `GtkFileDialog` * @parent: (nullable): the parent `GtkWindow` - * @current_file: (nullable): the initial file * @cancellable: (nullable): a `GCancellable` to cancel the operation * @callback: (scope async): a callback to call when the operation is complete * @user_data: (closure callback): data to pass to @callback @@ -1012,13 +1134,6 @@ gtk_file_dialog_select_folder_finish (GtkFileDialog *self, * This function initiates a file save operation by * presenting a file chooser dialog to the user. * - * You should pass either @current_file if you have a file to - * save to, or @current_name, if you are creating a new file. - * - * If you pass @current_file, the file chooser will initially be - * opened in the parent directory of that file, otherwise, it - * will be in the directory [property@Gtk.FileDialog:initial-folder]. - * * The @callback will be called when the dialog is dismissed. * It should call [method@Gtk.FileDialog.save_finish] * to obtain the result. @@ -1028,7 +1143,6 @@ gtk_file_dialog_select_folder_finish (GtkFileDialog *self, void gtk_file_dialog_save (GtkFileDialog *self, GtkWindow *parent, - GFile *current_file, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -1038,8 +1152,7 @@ gtk_file_dialog_save (GtkFileDialog *self, g_return_if_fail (GTK_IS_FILE_DIALOG (self)); - chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SAVE, - current_file, FALSE); + chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SAVE, FALSE); task = g_task_new (self, cancellable, callback, user_data); g_task_set_check_cancellable (task, FALSE); @@ -1112,8 +1225,7 @@ gtk_file_dialog_open_multiple (GtkFileDialog *self, g_return_if_fail (GTK_IS_FILE_DIALOG (self)); - chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_OPEN, - NULL, TRUE); + chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_OPEN, TRUE); task = g_task_new (self, cancellable, callback, user_data); g_task_set_check_cancellable (task, FALSE); @@ -1187,8 +1299,7 @@ gtk_file_dialog_select_multiple_folders (GtkFileDialog *self, g_return_if_fail (GTK_IS_FILE_DIALOG (self)); - chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - NULL, TRUE); + chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, TRUE); task = g_task_new (self, cancellable, callback, user_data); g_task_set_check_cancellable (task, FALSE); diff --git a/gtk/gtkfiledialog.h b/gtk/gtkfiledialog.h index de5574972a..27c0f50aba 100644 --- a/gtk/gtkfiledialog.h +++ b/gtk/gtkfiledialog.h @@ -88,9 +88,16 @@ void gtk_file_dialog_set_initial_name (GtkFileDialog *self const char *name); GDK_AVAILABLE_IN_4_10 +GFile * gtk_file_dialog_get_initial_file (GtkFileDialog *self); + +GDK_AVAILABLE_IN_4_10 +void gtk_file_dialog_set_initial_file (GtkFileDialog *self, + GFile *file); + + +GDK_AVAILABLE_IN_4_10 void gtk_file_dialog_open (GtkFileDialog *self, GtkWindow *parent, - GFile *current_file, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -103,7 +110,6 @@ GFile * gtk_file_dialog_open_finish (GtkFileDialog *self GDK_AVAILABLE_IN_4_10 void gtk_file_dialog_select_folder (GtkFileDialog *self, GtkWindow *parent, - GFile *initial_folder, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -117,7 +123,6 @@ GFile * gtk_file_dialog_select_folder_finish GDK_AVAILABLE_IN_4_10 void gtk_file_dialog_save (GtkFileDialog *self, GtkWindow *parent, - GFile *current_file, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); diff --git a/gtk/gtkprinteroptionwidget.c b/gtk/gtkprinteroptionwidget.c index c84532b14d..0d378fe8ee 100644 --- a/gtk/gtkprinteroptionwidget.c +++ b/gtk/gtkprinteroptionwidget.c @@ -707,12 +707,13 @@ filesave_choose_cb (GtkWidget *button, { GtkPrinterOptionWidgetPrivate *priv = widget->priv; GtkFileDialog *dialog; - GFile *current_folder = NULL; - char *current_name = NULL; /* this will be unblocked in the dialog_response_callback function */ g_signal_handler_block (priv->source, priv->source_changed_handler); + dialog = gtk_file_dialog_new (); + gtk_file_dialog_set_title (dialog, _("Select a filename")); + /* select the current filename in the dialog */ if (priv->source != NULL && priv->source->value != NULL) { @@ -720,32 +721,16 @@ filesave_choose_cb (GtkWidget *button, if (priv->last_location) { if (g_file_query_file_type (priv->last_location, 0, NULL) == G_FILE_TYPE_DIRECTORY) - { - current_folder = g_object_ref (priv->last_location); - current_name = NULL; - } + gtk_file_dialog_set_initial_folder (dialog, priv->last_location); else - { - current_folder = g_file_get_parent (priv->last_location); - current_name = g_file_get_basename (priv->last_location); - if (strcmp (current_name, "/") == 0 || - !g_utf8_validate (current_name, -1, NULL)) - g_clear_pointer (¤t_name, g_free); - } + gtk_file_dialog_set_initial_file (dialog, priv->last_location); } } - dialog = gtk_file_dialog_new (); - gtk_file_dialog_set_title (dialog, _("Select a filename")); - gtk_file_dialog_set_initial_name (dialog, current_name); gtk_file_dialog_save (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (widget))), - current_folder, NULL, dialog_response_callback, widget); - - g_object_unref (current_folder); - g_free (current_name); } static char * diff --git a/gtk/inspector/css-editor.c b/gtk/inspector/css-editor.c index 0f177add9d..d0e71c8d37 100644 --- a/gtk/inspector/css-editor.c +++ b/gtk/inspector/css-editor.c @@ -246,7 +246,7 @@ save_clicked (GtkButton *button, gtk_file_dialog_set_initial_name (dialog, "custom.css"); gtk_file_dialog_save (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))), - NULL, NULL, + NULL, save_response, ce); g_object_unref (dialog); } diff --git a/gtk/inspector/recorder.c b/gtk/inspector/recorder.c index f827e30108..e33d058b05 100644 --- a/gtk/inspector/recorder.c +++ b/gtk/inspector/recorder.c @@ -1862,7 +1862,7 @@ render_node_save (GtkButton *button, gtk_file_dialog_set_initial_name (dialog, filename); gtk_file_dialog_save (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (recorder))), - NULL, NULL, + NULL, render_node_save_response, node); g_object_unref (dialog); g_free (filename); |