[gtk/wip/otte/nodeeditor2: 1/3] Some node editor improvements
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/nodeeditor2: 1/3] Some node editor improvements
- Date: Sat, 4 May 2019 09:15:40 +0000 (UTC)
commit 79b6500392e61ab9f2e3bf5ce0d4d11195bbca85
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 | 37 +++++++++++++++++++++++++----
2 files changed, 37 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..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 *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]