filedialog: Add gtk_file_dialog_set_initial_file()
authorBenjamin Otte <otte@redhat.com>
Fri, 23 Dec 2022 04:54:32 +0000 (05:54 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 24 Dec 2022 12:56:57 +0000 (07:56 -0500)
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.

15 files changed:
demos/constraint-editor/constraint-editor-window.c
demos/gtk-demo/application.c
demos/gtk-demo/clipboard.c
demos/gtk-demo/listview_words.c
demos/gtk-demo/paintable_svg.c
demos/gtk-demo/pickers.c
demos/gtk-demo/video_player.c
demos/node-editor/node-editor-window.c
demos/print-editor/print-editor.c
demos/widget-factory/widget-factory.c
gtk/gtkfiledialog.c
gtk/gtkfiledialog.h
gtk/gtkprinteroptionwidget.c
gtk/inspector/css-editor.c
gtk/inspector/recorder.c

index 1f81ac4a427616414b6641bec0afe720a3fe6d71..ab084ef62b4831f19b56d52c79b49d956e2e6733 100644 (file)
@@ -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);
 }
index 4570d06452edf38696f43aa73c9ae96e82410dad..56567b197b073782b2e0091f7dd25eed2afd047a 100644 (file)
@@ -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);
 }
 
index 753ecb32d988475f66b597d3751a95eff7ba4abf..672a51ac442929658dbfcf9ea479cf234ad2661c 100644 (file)
@@ -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)
index 235af6a31effea5891f931b10a6dd22aa8e85ebf..1004aebbec7bc9710d9bb7c1811c06b956ededfd 100644 (file)
@@ -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);
 }
index 5d73fd91bb892181892f226a825b05b16043de42..ecbe6a8d80fd3c90e2c7f856be2bb391d3f41fca 100644 (file)
@@ -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);
 }
 
index bed57cecc53cd7927ead236ac27db75556e8dbec..6f48a28a9ab394e157d6031c19cf9ec0d66f93e9 100644 (file)
@@ -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);
index b6909472a578100b8e8bf84acef663b7209d666f..78e7c69102be4c2540e4e9d52d7bbf98ca4acf41 100644 (file)
@@ -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);
 }
 
index b790eda124281b6e70780816f858ac0ea927b7dd..c3b876ac5ebd78910a792d98233e6167e1a0a32f 100644 (file)
@@ -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);
 }
index daa95c0610974babf25d2dc4cd8c6e5eb1e055db..bf45b6945df508c403ea76cefa22d7e2f0cd31fe 100644 (file)
@@ -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);
 }
index 16b041933f3c01789292e467e21531debd11098e..99fd76c2582d2929af16fcecabcba5aef9f83bfd 100644 (file)
@@ -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);
 }
 
index c8242a1bc805d4d2736ee4c7ad30301528cabed5..9e4d8723f0733c0438e28f3c8bba9c2218e2a7f1 100644 (file)
@@ -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;
@@ -269,12 +279,27 @@ gtk_file_dialog_class_init (GtkFileDialogClass *class)
                            GTK_TYPE_FILE_FILTER,
                            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);
index de5574972a29e52ae4da8ac55d27a5612f2b1dfc..27c0f50abaff2da19b072347207074db852a8f0c 100644 (file)
@@ -87,10 +87,17 @@ GDK_AVAILABLE_IN_4_10
 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);
index c84532b14d671b9e37c2569d623413eb45c85f83..0d378fe8ee046b4cab9ff1379a2ed1eedca9f6af 100644 (file)
@@ -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 (&current_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 *
index 0f177add9dd21f5b00034280c1badca36bc64208..d0e71c8d37305d8042848418c95bbbee71e59d88 100644 (file)
@@ -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);
 }
index f827e30108906d972a0c33cc5b9e03ae7e2db21d..e33d058b05db407f0d7238ad793155a969357674 100644 (file)
@@ -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);