mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-24 20:51:10 +00:00
node-editor: Be a bit better about saving
When we have a file, suggest it for saving. This has the side benefit of giving us a test case for gtk_file_dialog_set_initial_file.
This commit is contained in:
parent
68a2ca7e85
commit
1fba59f1d1
@ -64,6 +64,7 @@ struct _NodeEditorWindow
|
||||
GListStore *renderers;
|
||||
GskRenderNode *node;
|
||||
|
||||
GFile *file;
|
||||
GFileMonitor *file_monitor;
|
||||
|
||||
GArray *errors;
|
||||
@ -544,12 +545,14 @@ node_editor_window_load (NodeEditorWindow *self,
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_clear_object (&self->file);
|
||||
g_clear_object (&self->file_monitor);
|
||||
|
||||
if (!load_file_contents (self, file))
|
||||
return FALSE;
|
||||
|
||||
self->file_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
|
||||
self->file = g_object_ref (file);
|
||||
self->file_monitor = g_file_monitor_file (self->file, G_FILE_MONITOR_NONE, NULL, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
@ -586,13 +589,21 @@ static void
|
||||
show_open_filechooser (NodeEditorWindow *self)
|
||||
{
|
||||
GtkFileDialog *dialog;
|
||||
GFile *cwd;
|
||||
|
||||
dialog = gtk_file_dialog_new ();
|
||||
gtk_file_dialog_set_title (dialog, "Open node file");
|
||||
cwd = g_file_new_for_path (".");
|
||||
gtk_file_dialog_set_initial_folder (dialog, cwd);
|
||||
g_object_unref (cwd);
|
||||
if (self->file)
|
||||
{
|
||||
gtk_file_dialog_set_initial_file (dialog, self->file);
|
||||
}
|
||||
else
|
||||
{
|
||||
GFile *cwd;
|
||||
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, open_response_cb, self);
|
||||
g_object_unref (dialog);
|
||||
@ -650,14 +661,21 @@ save_cb (GtkWidget *button,
|
||||
NodeEditorWindow *self)
|
||||
{
|
||||
GtkFileDialog *dialog;
|
||||
GFile *cwd;
|
||||
|
||||
dialog = gtk_file_dialog_new ();
|
||||
gtk_file_dialog_set_title (dialog, "Save node");
|
||||
cwd = g_file_new_for_path (".");
|
||||
gtk_file_dialog_set_initial_folder (dialog, cwd);
|
||||
gtk_file_dialog_set_initial_name (dialog, "demo.node");
|
||||
g_object_unref (cwd);
|
||||
if (self->file)
|
||||
{
|
||||
gtk_file_dialog_set_initial_file (dialog, self->file);
|
||||
}
|
||||
else
|
||||
{
|
||||
GFile *cwd = g_file_new_for_path (".");
|
||||
gtk_file_dialog_set_initial_folder (dialog, cwd);
|
||||
gtk_file_dialog_set_initial_name (dialog, "demo.node");
|
||||
g_object_unref (cwd);
|
||||
}
|
||||
|
||||
gtk_file_dialog_save (dialog,
|
||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
|
||||
NULL,
|
||||
@ -1091,6 +1109,8 @@ node_editor_window_finalize (GObject *object)
|
||||
|
||||
g_clear_pointer (&self->node, gsk_render_node_unref);
|
||||
g_clear_object (&self->renderers);
|
||||
g_clear_object (&self->file_monitor);
|
||||
g_clear_object (&self->file);
|
||||
|
||||
G_OBJECT_CLASS (node_editor_window_parent_class)->finalize (object);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user