From: Timm Bäder Date: Sat, 4 May 2019 07:22:01 +0000 (+0200) Subject: Some node editor improvements X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~21^2~11 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=759a97403c33e35b9c6a7802178f167508181fd8;p=gtk4.git Some node editor improvements --- diff --git a/demos/node-editor/node-editor-application.c b/demos/node-editor/node-editor-application.c index 9455cf3bc3..a2c9dcfb19 100644 --- a/demos/node-editor/node-editor-application.c +++ b/demos/node-editor/node-editor-application.c @@ -56,16 +56,16 @@ static GActionEntry app_entries[] = static void node_editor_application_startup (GApplication *app) { - const gchar *quit_accels[2] = { "Q", NULL }; + const char *quit_accels[2] = { "Q", NULL }; + const char *open_accels[2] = { "O", NULL }; G_APPLICATION_CLASS (node_editor_application_parent_class)->startup (app); g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app); - gtk_application_set_accels_for_action (GTK_APPLICATION (app), - "app.quit", - quit_accels); + gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels); + gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.open", open_accels); } static void diff --git a/demos/node-editor/node-editor-window.c b/demos/node-editor/node-editor-window.c index dc07f0a102..ef61e9f20d 100644 --- a/demos/node-editor/node-editor-window.c +++ b/demos/node-editor/node-editor-window.c @@ -211,6 +211,8 @@ node_editor_window_load (NodeEditorWindow *self, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes)); + g_bytes_unref (bytes); + return TRUE; } @@ -234,13 +236,12 @@ open_response_cb (GtkWidget *dialog, } static void -open_cb (GtkWidget *button, - NodeEditorWindow *self) +show_open_filechooser (NodeEditorWindow *self) { GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new ("Open node file", - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (button))), + GTK_WINDOW (self), GTK_FILE_CHOOSER_ACTION_OPEN, "_Cancel", GTK_RESPONSE_CANCEL, "_Load", GTK_RESPONSE_ACCEPT, @@ -253,6 +254,13 @@ open_cb (GtkWidget *button, gtk_widget_show (dialog); } +static void +open_cb (GtkWidget *button, + NodeEditorWindow *self) +{ + show_open_filechooser (self); +} + static void save_response_cb (GtkWidget *dialog, gint response, @@ -503,6 +511,7 @@ node_editor_window_create_renderer_widget (gpointer item, { GdkPaintable *paintable = item; GtkWidget *box, *label, *picture; + GtkWidget *row; box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_size_request (box, 120, 90); @@ -513,9 +522,27 @@ node_editor_window_create_renderer_widget (gpointer item, picture = gtk_picture_new_for_paintable (paintable); gtk_container_add (GTK_CONTAINER (box), picture); - return box; + row = gtk_list_box_row_new (); + gtk_container_add (GTK_CONTAINER (row), box); + gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE); + + return row; +} + +static void +window_open (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + NodeEditorWindow *self = user_data; + + show_open_filechooser (self); } +static GActionEntry win_entries[] = { + { "open", window_open, NULL, NULL, NULL }, +}; + static void node_editor_window_init (NodeEditorWindow *self) { @@ -530,6 +557,8 @@ node_editor_window_init (NodeEditorWindow *self) self->errors = g_array_new (FALSE, TRUE, sizeof (TextViewError)); g_array_set_clear_func (self->errors, (GDestroyNotify)text_view_error_free); + + g_action_map_add_action_entries (G_ACTION_MAP (self), win_entries, G_N_ELEMENTS (win_entries), self); } NodeEditorWindow *