mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-12 20:00:09 +00:00
filedialog: Add gtk_file_dialog_set_initial_name()
This commit is contained in:
parent
26cec4a021
commit
8a2d35b9fb
@ -342,7 +342,6 @@ save_cb (GtkWidget *button,
|
|||||||
gtk_file_dialog_save (dialog,
|
gtk_file_dialog_save (dialog,
|
||||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
|
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
NULL,
|
|
||||||
save_response_cb, self);
|
save_response_cb, self);
|
||||||
g_object_unref (dialog);
|
g_object_unref (dialog);
|
||||||
}
|
}
|
||||||
|
@ -634,11 +634,11 @@ save_cb (GtkWidget *button,
|
|||||||
gtk_file_dialog_set_title (dialog, "Save node");
|
gtk_file_dialog_set_title (dialog, "Save node");
|
||||||
cwd = g_file_new_for_path (".");
|
cwd = g_file_new_for_path (".");
|
||||||
gtk_file_dialog_set_initial_folder (dialog, cwd);
|
gtk_file_dialog_set_initial_folder (dialog, cwd);
|
||||||
|
gtk_file_dialog_set_initial_name (dialog, "demo.node");
|
||||||
g_object_unref (cwd);
|
g_object_unref (cwd);
|
||||||
gtk_file_dialog_save (dialog,
|
gtk_file_dialog_save (dialog,
|
||||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
|
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
|
||||||
NULL,
|
NULL,
|
||||||
"demo.node",
|
|
||||||
NULL,
|
NULL,
|
||||||
save_response_cb, self);
|
save_response_cb, self);
|
||||||
g_object_unref (dialog);
|
g_object_unref (dialog);
|
||||||
@ -742,10 +742,10 @@ export_image_cb (GtkWidget *button,
|
|||||||
|
|
||||||
dialog = gtk_file_dialog_new ();
|
dialog = gtk_file_dialog_new ();
|
||||||
gtk_file_dialog_set_title (dialog, "");
|
gtk_file_dialog_set_title (dialog, "");
|
||||||
|
gtk_file_dialog_set_initial_name (dialog, "example.png");
|
||||||
gtk_file_dialog_save (dialog,
|
gtk_file_dialog_save (dialog,
|
||||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
|
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
|
||||||
NULL,
|
NULL,
|
||||||
"example.png",
|
|
||||||
NULL,
|
NULL,
|
||||||
export_image_response_cb, texture);
|
export_image_response_cb, texture);
|
||||||
g_object_unref (dialog);
|
g_object_unref (dialog);
|
||||||
|
@ -509,7 +509,6 @@ activate_save_as (GSimpleAction *action,
|
|||||||
GTK_WINDOW (main_window),
|
GTK_WINDOW (main_window),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
|
||||||
on_save_response, NULL);
|
on_save_response, NULL);
|
||||||
g_object_unref (dialog);
|
g_object_unref (dialog);
|
||||||
}
|
}
|
||||||
|
@ -59,17 +59,20 @@ struct _GtkFileDialog
|
|||||||
GListModel *shortcut_folders;
|
GListModel *shortcut_folders;
|
||||||
GtkFileFilter *current_filter;
|
GtkFileFilter *current_filter;
|
||||||
GFile *initial_folder;
|
GFile *initial_folder;
|
||||||
|
char *initial_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_TITLE = 1,
|
PROP_0,
|
||||||
PROP_MODAL,
|
|
||||||
PROP_FILTERS,
|
|
||||||
PROP_SHORTCUT_FOLDERS,
|
|
||||||
PROP_CURRENT_FILTER,
|
|
||||||
PROP_INITIAL_FOLDER,
|
|
||||||
PROP_ACCEPT_LABEL,
|
PROP_ACCEPT_LABEL,
|
||||||
|
PROP_CURRENT_FILTER,
|
||||||
|
PROP_FILTERS,
|
||||||
|
PROP_INITIAL_FOLDER,
|
||||||
|
PROP_INITIAL_NAME,
|
||||||
|
PROP_MODAL,
|
||||||
|
PROP_SHORTCUT_FOLDERS,
|
||||||
|
PROP_TITLE,
|
||||||
|
|
||||||
NUM_PROPERTIES
|
NUM_PROPERTIES
|
||||||
};
|
};
|
||||||
@ -95,6 +98,7 @@ gtk_file_dialog_finalize (GObject *object)
|
|||||||
g_clear_object (&self->shortcut_folders);
|
g_clear_object (&self->shortcut_folders);
|
||||||
g_clear_object (&self->current_filter);
|
g_clear_object (&self->current_filter);
|
||||||
g_clear_object (&self->initial_folder);
|
g_clear_object (&self->initial_folder);
|
||||||
|
g_free (self->initial_name);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_file_dialog_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gtk_file_dialog_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
@ -133,6 +137,10 @@ gtk_file_dialog_get_property (GObject *object,
|
|||||||
g_value_set_object (value, self->initial_folder);
|
g_value_set_object (value, self->initial_folder);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_INITIAL_NAME:
|
||||||
|
g_value_set_string (value, self->initial_name);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_ACCEPT_LABEL:
|
case PROP_ACCEPT_LABEL:
|
||||||
g_value_set_string (value, self->accept_label);
|
g_value_set_string (value, self->accept_label);
|
||||||
break;
|
break;
|
||||||
@ -177,6 +185,10 @@ gtk_file_dialog_set_property (GObject *object,
|
|||||||
gtk_file_dialog_set_initial_folder (self, g_value_get_object (value));
|
gtk_file_dialog_set_initial_folder (self, g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_INITIAL_NAME:
|
||||||
|
gtk_file_dialog_set_initial_name (self, g_value_get_string (value));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_ACCEPT_LABEL:
|
case PROP_ACCEPT_LABEL:
|
||||||
gtk_file_dialog_set_accept_label (self, g_value_get_string (value));
|
gtk_file_dialog_set_accept_label (self, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
@ -271,6 +283,19 @@ gtk_file_dialog_class_init (GtkFileDialogClass *class)
|
|||||||
G_TYPE_FILE,
|
G_TYPE_FILE,
|
||||||
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
|
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkFileDialog:initial-name: (attributes org.gtk.Property.get=gtk_file_dialog_get_initial_name org.gtk.Property.set=gtk_file_dialog_set_initial_name)
|
||||||
|
*
|
||||||
|
* The inital name, that is, the filename that is initially
|
||||||
|
* selected in the file chooser dialog.
|
||||||
|
*
|
||||||
|
* Since: 4.10
|
||||||
|
*/
|
||||||
|
properties[PROP_INITIAL_NAME] =
|
||||||
|
g_param_spec_string ("initial-name", NULL, NULL,
|
||||||
|
NULL,
|
||||||
|
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GtkFileDialog:accept-label: (attributes org.gtk.Property.get=gtk_file_dialog_get_accept_label org.gtk.Property.set=gtk_file_dialog_set_accept_label)
|
* GtkFileDialog:accept-label: (attributes org.gtk.Property.get=gtk_file_dialog_get_accept_label org.gtk.Property.set=gtk_file_dialog_set_accept_label)
|
||||||
*
|
*
|
||||||
@ -616,6 +641,49 @@ gtk_file_dialog_set_initial_folder (GtkFileDialog *self,
|
|||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FOLDER]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_FOLDER]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_file_dialog_get_initial_name:
|
||||||
|
* @self: a `GtkFileDialog`
|
||||||
|
*
|
||||||
|
* Gets the name for the file that should be initially set.
|
||||||
|
*
|
||||||
|
* Returns: (nullable) (transfer none): the name
|
||||||
|
*
|
||||||
|
* Since: 4.10
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
gtk_file_dialog_get_initial_name (GtkFileDialog *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GTK_IS_FILE_DIALOG (self), NULL);
|
||||||
|
|
||||||
|
return self->initial_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_file_dialog_set_initial_name:
|
||||||
|
* @self: a `GtkFileDialog`
|
||||||
|
* @name: (nullable): a UTF8 string
|
||||||
|
*
|
||||||
|
* Sets the name for the file that should be initially set.
|
||||||
|
* For saving dialogs, this will usually be pre-entered into the name field.
|
||||||
|
*
|
||||||
|
* If a file with this name already exists in the directory set via
|
||||||
|
* [property@Gtk.FileDialog:initial-folder], the dialog should preselect it.
|
||||||
|
*
|
||||||
|
* Since: 4.10
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gtk_file_dialog_set_initial_name (GtkFileDialog *self,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
||||||
|
|
||||||
|
if (!g_set_str (&self->initial_name, name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INITIAL_NAME]);
|
||||||
|
}
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
/* {{{ Async implementation */
|
/* {{{ Async implementation */
|
||||||
|
|
||||||
@ -676,7 +744,6 @@ create_file_chooser (GtkFileDialog *self,
|
|||||||
GtkWindow *parent,
|
GtkWindow *parent,
|
||||||
GtkFileChooserAction action,
|
GtkFileChooserAction action,
|
||||||
GFile *current_file,
|
GFile *current_file,
|
||||||
const char *current_name,
|
|
||||||
gboolean select_multiple)
|
gboolean select_multiple)
|
||||||
{
|
{
|
||||||
GtkFileChooserNative *chooser;
|
GtkFileChooserNative *chooser;
|
||||||
@ -738,8 +805,8 @@ create_file_chooser (GtkFileDialog *self,
|
|||||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser), self->initial_folder, NULL);
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser), self->initial_folder, NULL);
|
||||||
if (current_file)
|
if (current_file)
|
||||||
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (chooser), current_file, NULL);
|
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (chooser), current_file, NULL);
|
||||||
else if (current_name)
|
else if (self->initial_name)
|
||||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser), current_name);
|
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser), self->initial_name);
|
||||||
|
|
||||||
return chooser;
|
return chooser;
|
||||||
}
|
}
|
||||||
@ -815,7 +882,7 @@ gtk_file_dialog_open (GtkFileDialog *self,
|
|||||||
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
||||||
|
|
||||||
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_OPEN,
|
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
current_file, NULL, FALSE);
|
current_file, FALSE);
|
||||||
|
|
||||||
task = g_task_new (self, cancellable, callback, user_data);
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
g_task_set_check_cancellable (task, FALSE);
|
g_task_set_check_cancellable (task, FALSE);
|
||||||
@ -892,7 +959,7 @@ gtk_file_dialog_select_folder (GtkFileDialog *self,
|
|||||||
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
||||||
|
|
||||||
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||||
initial_folder, NULL, FALSE);
|
initial_folder, FALSE);
|
||||||
|
|
||||||
task = g_task_new (self, cancellable, callback, user_data);
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
g_task_set_check_cancellable (task, FALSE);
|
g_task_set_check_cancellable (task, FALSE);
|
||||||
@ -938,7 +1005,6 @@ gtk_file_dialog_select_folder_finish (GtkFileDialog *self,
|
|||||||
* @self: a `GtkFileDialog`
|
* @self: a `GtkFileDialog`
|
||||||
* @parent: (nullable): the parent `GtkWindow`
|
* @parent: (nullable): the parent `GtkWindow`
|
||||||
* @current_file: (nullable): the initial file
|
* @current_file: (nullable): the initial file
|
||||||
* @current_name: (nullable): the initial filename to offer
|
|
||||||
* @cancellable: (nullable): a `GCancellable` to cancel the operation
|
* @cancellable: (nullable): a `GCancellable` to cancel the operation
|
||||||
* @callback: (scope async): a callback to call when the operation is complete
|
* @callback: (scope async): a callback to call when the operation is complete
|
||||||
* @user_data: (closure callback): data to pass to @callback
|
* @user_data: (closure callback): data to pass to @callback
|
||||||
@ -963,7 +1029,6 @@ void
|
|||||||
gtk_file_dialog_save (GtkFileDialog *self,
|
gtk_file_dialog_save (GtkFileDialog *self,
|
||||||
GtkWindow *parent,
|
GtkWindow *parent,
|
||||||
GFile *current_file,
|
GFile *current_file,
|
||||||
const char *current_name,
|
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
@ -974,7 +1039,7 @@ gtk_file_dialog_save (GtkFileDialog *self,
|
|||||||
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
||||||
|
|
||||||
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SAVE,
|
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||||
current_file, current_name, FALSE);
|
current_file, FALSE);
|
||||||
|
|
||||||
task = g_task_new (self, cancellable, callback, user_data);
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
g_task_set_check_cancellable (task, FALSE);
|
g_task_set_check_cancellable (task, FALSE);
|
||||||
@ -1048,7 +1113,7 @@ gtk_file_dialog_open_multiple (GtkFileDialog *self,
|
|||||||
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
||||||
|
|
||||||
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_OPEN,
|
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
NULL, NULL, TRUE);
|
NULL, TRUE);
|
||||||
|
|
||||||
task = g_task_new (self, cancellable, callback, user_data);
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
g_task_set_check_cancellable (task, FALSE);
|
g_task_set_check_cancellable (task, FALSE);
|
||||||
@ -1123,7 +1188,7 @@ gtk_file_dialog_select_multiple_folders (GtkFileDialog *self,
|
|||||||
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
g_return_if_fail (GTK_IS_FILE_DIALOG (self));
|
||||||
|
|
||||||
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
chooser = create_file_chooser (self, parent, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||||
NULL, NULL, TRUE);
|
NULL, TRUE);
|
||||||
|
|
||||||
task = g_task_new (self, cancellable, callback, user_data);
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
g_task_set_check_cancellable (task, FALSE);
|
g_task_set_check_cancellable (task, FALSE);
|
||||||
|
@ -80,6 +80,13 @@ GDK_AVAILABLE_IN_4_10
|
|||||||
void gtk_file_dialog_set_initial_folder (GtkFileDialog *self,
|
void gtk_file_dialog_set_initial_folder (GtkFileDialog *self,
|
||||||
GFile *folder);
|
GFile *folder);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
const char * gtk_file_dialog_get_initial_name (GtkFileDialog *self);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
void gtk_file_dialog_set_initial_name (GtkFileDialog *self,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_4_10
|
GDK_AVAILABLE_IN_4_10
|
||||||
void gtk_file_dialog_open (GtkFileDialog *self,
|
void gtk_file_dialog_open (GtkFileDialog *self,
|
||||||
GtkWindow *parent,
|
GtkWindow *parent,
|
||||||
@ -111,7 +118,6 @@ GDK_AVAILABLE_IN_4_10
|
|||||||
void gtk_file_dialog_save (GtkFileDialog *self,
|
void gtk_file_dialog_save (GtkFileDialog *self,
|
||||||
GtkWindow *parent,
|
GtkWindow *parent,
|
||||||
GFile *current_file,
|
GFile *current_file,
|
||||||
const char *current_name,
|
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
@ -737,10 +737,10 @@ filesave_choose_cb (GtkWidget *button,
|
|||||||
|
|
||||||
dialog = gtk_file_dialog_new ();
|
dialog = gtk_file_dialog_new ();
|
||||||
gtk_file_dialog_set_title (dialog, _("Select a filename"));
|
gtk_file_dialog_set_title (dialog, _("Select a filename"));
|
||||||
|
gtk_file_dialog_set_initial_name (dialog, current_name);
|
||||||
gtk_file_dialog_save (dialog,
|
gtk_file_dialog_save (dialog,
|
||||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (widget))),
|
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (widget))),
|
||||||
current_folder,
|
current_folder,
|
||||||
current_name,
|
|
||||||
NULL,
|
NULL,
|
||||||
dialog_response_callback, widget);
|
dialog_response_callback, widget);
|
||||||
|
|
||||||
|
@ -243,10 +243,10 @@ save_clicked (GtkButton *button,
|
|||||||
GtkFileDialog *dialog;
|
GtkFileDialog *dialog;
|
||||||
|
|
||||||
dialog = gtk_file_dialog_new ();
|
dialog = gtk_file_dialog_new ();
|
||||||
|
gtk_file_dialog_set_initial_name (dialog, "custom.css");
|
||||||
gtk_file_dialog_save (dialog,
|
gtk_file_dialog_save (dialog,
|
||||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))),
|
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))),
|
||||||
NULL, "custom.css",
|
NULL, NULL,
|
||||||
NULL,
|
|
||||||
save_response, ce);
|
save_response, ce);
|
||||||
g_object_unref (dialog);
|
g_object_unref (dialog);
|
||||||
}
|
}
|
||||||
|
@ -1859,12 +1859,14 @@ render_node_save (GtkButton *button,
|
|||||||
filename = g_strdup_printf ("%s.node", nodename);
|
filename = g_strdup_printf ("%s.node", nodename);
|
||||||
|
|
||||||
dialog = gtk_file_dialog_new ();
|
dialog = gtk_file_dialog_new ();
|
||||||
|
gtk_file_dialog_set_initial_name (dialog, filename);
|
||||||
gtk_file_dialog_save (dialog,
|
gtk_file_dialog_save (dialog,
|
||||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (recorder))),
|
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (recorder))),
|
||||||
NULL, filename,
|
NULL, NULL,
|
||||||
NULL,
|
|
||||||
render_node_save_response, node);
|
render_node_save_response, node);
|
||||||
g_object_unref (dialog);
|
g_object_unref (dialog);
|
||||||
|
g_free (filename);
|
||||||
|
g_free (nodename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user