[gtk/wip/otte/nodeeditor2: 54/55] Some node editor improvements



commit 4ff4fc0fb3afa0a07d5b47818354ec8cf017ffcc
Author: Timm Bäder <mail baedert org>
Date:   Sat May 4 09:22:01 2019 +0200

    Some node editor improvements

 demos/node-editor/node-editor-application.c |  8 +++----
 demos/node-editor/node-editor-window.c      | 35 +++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 8 deletions(-)
---
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] = { "<Ctrl>Q", NULL };
+  const char *quit_accels[2] = { "<Ctrl>Q", NULL };
+  const char *open_accels[2] = { "<Ctrl>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..11c6e9c195 100644
--- a/demos/node-editor/node-editor-window.c
+++ b/demos/node-editor/node-editor-window.c
@@ -234,13 +234,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 +252,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 +509,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 +520,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 +555,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 *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]