[gtk/matthiasc/for-master] node-editor: Add a gear menu
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master] node-editor: Add a gear menu
- Date: Mon, 29 Jun 2020 03:54:16 +0000 (UTC)
commit fd5945cdfe243446ae91ad3708f817abb22d8fea
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jun 28 23:43:13 2020 -0400
node-editor: Add a gear menu
Add a gear menu with Inspector and About menu items.
demos/node-editor/node-editor-application.c | 76 +++++++++++++++++++++++++++--
demos/node-editor/node-editor-window.ui | 20 ++++++++
2 files changed, 93 insertions(+), 3 deletions(-)
---
diff --git a/demos/node-editor/node-editor-application.c b/demos/node-editor/node-editor-application.c
index fd80787ce2..dd55284ca3 100644
--- a/demos/node-editor/node-editor-application.c
+++ b/demos/node-editor/node-editor-application.c
@@ -51,16 +51,86 @@ node_editor_application_init (NodeEditorApplication *app)
}
static void
-quit_activated (GSimpleAction *action,
+activate_about (GSimpleAction *action,
GVariant *parameter,
- gpointer data)
+ gpointer user_data)
+{
+ GtkApplication *app = user_data;
+ char *version;
+ GString *s;
+ GskRenderer *gsk_renderer;
+ const char *renderer;
+
+ s = g_string_new ("");
+
+ g_string_append (s, "System libraries\n");
+ g_string_append_printf (s, "\tGLib\t%d.%d.%d\n",
+ glib_major_version,
+ glib_minor_version,
+ glib_micro_version);
+ g_string_append_printf (s, "\tPango\t%s\n",
+ pango_version_string ());
+ g_string_append_printf (s, "\tGTK\t%d.%d.%d\n",
+ gtk_get_major_version (),
+ gtk_get_minor_version (),
+ gtk_get_micro_version ());
+
+ gsk_renderer = gtk_native_get_renderer (GTK_NATIVE (gtk_application_get_active_window (app)));
+ if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskVulkanRenderer") == 0)
+ renderer = "Vulkan";
+ else if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskGLRenderer") == 0)
+ renderer = "OpenGL";
+ else if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskCairoRenderer") == 0)
+ renderer = "Cairo";
+ else
+ renderer = "Unknown";
+
+ g_string_append_printf (s, "\nRenderer\n\t%s", renderer);
+
+ version = g_strdup_printf ("%s\nRunning against GTK %d.%d.%d",
+ PACKAGE_VERSION,
+ gtk_get_major_version (),
+ gtk_get_minor_version (),
+ gtk_get_micro_version ());
+
+ gtk_show_about_dialog (GTK_WINDOW (gtk_application_get_active_window (app)),
+ "program-name", "GTK Node Editor",
+ "version", version,
+ "copyright", "© 2019—2020 The GTK Team",
+ "license-type", GTK_LICENSE_LGPL_2_1,
+ "website", "http://www.gtk.org",
+ "comments", "Program to test GTK rendering",
+ "authors", (const char *[]){ "Benjamin Otte", "Timm Bäder", NULL},
+ "logo-icon-name", "text-editor-symbolic",
+ "title", "About GTK Node Editor",
+ "system-information", s->str,
+ NULL);
+
+ g_string_free (s, TRUE);
+ g_free (version);
+}
+
+static void
+activate_quit (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer data)
{
g_application_quit (G_APPLICATION (data));
}
+static void
+activate_inspector (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ gtk_window_set_interactive_debugging (TRUE);
+}
+
static GActionEntry app_entries[] =
{
- { "quit", quit_activated, NULL, NULL, NULL }
+ { "about", activate_about, NULL, NULL, NULL },
+ { "quit", activate_quit, NULL, NULL, NULL },
+ { "inspector", activate_inspector, NULL, NULL, NULL },
};
static void
diff --git a/demos/node-editor/node-editor-window.ui b/demos/node-editor/node-editor-window.ui
index 835b154ec6..1b49269ab1 100644
--- a/demos/node-editor/node-editor-window.ui
+++ b/demos/node-editor/node-editor-window.ui
@@ -1,5 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
+ <menu id="gear_menu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Inspector</attribute>
+ <attribute name="action">app.inspector</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_About Node Editor</attribute>
+ <attribute name="action">app.about</attribute>
+ </item>
+ </section>
+ </menu>
+
<object class="GtkPopover" id="testcase_popover">
<child>
<object class="GtkGrid">
@@ -119,6 +132,13 @@
<property name="popover">testcase_popover</property>
</object>
</child>
+ <child type="end">
+ <object class="GtkMenuButton" id="gear_menu_button">
+ <property name="valign">center</property>
+ <property name="menu-model">gear_menu</property>
+ <property name="icon-name">open-menu-symbolic</property>
+ </object>
+ </child>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]