[gtk/kill-tree-menu: 27/52] gtk-demo: Convert the builder demo to a menu model
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/kill-tree-menu: 27/52] gtk-demo: Convert the builder demo to a menu model
- Date: Sun, 29 Dec 2019 03:05:06 +0000 (UTC)
commit 7485329abe045722a7988dc7955a2611a5d425ad
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Dec 28 10:57:43 2019 -0500
gtk-demo: Convert the builder demo to a menu model
demos/gtk-demo/builder.c | 55 ++++-----------
demos/gtk-demo/demo.ui | 174 +++++++++++++++++++----------------------------
2 files changed, 86 insertions(+), 143 deletions(-)
---
diff --git a/demos/gtk-demo/builder.c b/demos/gtk-demo/builder.c
index 47d7d699ea..a04088a9bd 100644
--- a/demos/gtk-demo/builder.c
+++ b/demos/gtk-demo/builder.c
@@ -38,7 +38,22 @@ help_activate (GSimpleAction *action,
g_print ("Help not available\n");
}
+static void
+not_implemented (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ g_print ("Action ā%sā not implemented\n", g_action_get_name (G_ACTION (action)));
+}
+
static GActionEntry win_entries[] = {
+ { "new", not_implemented, NULL, NULL, NULL },
+ { "open", not_implemented, NULL, NULL, NULL },
+ { "save", not_implemented, NULL, NULL, NULL },
+ { "save-as", not_implemented, NULL, NULL, NULL },
+ { "copy", not_implemented, NULL, NULL, NULL },
+ { "cut", not_implemented, NULL, NULL, NULL },
+ { "paste", not_implemented, NULL, NULL, NULL },
{ "quit", quit_activate, NULL, NULL, NULL },
{ "about", about_activate, NULL, NULL, NULL },
{ "help", help_activate, NULL, NULL, NULL }
@@ -50,8 +65,6 @@ do_builder (GtkWidget *do_widget)
static GtkWidget *window = NULL;
GtkWidget *toolbar;
GActionGroup *actions;
- GtkAccelGroup *accel_group;
- GtkWidget *item;
if (!window)
{
@@ -72,44 +85,6 @@ do_builder (GtkWidget *do_widget)
win_entries, G_N_ELEMENTS (win_entries),
window);
gtk_widget_insert_action_group (window, "win", actions);
- accel_group = gtk_accel_group_new ();
- gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "new_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_n, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "open_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_o, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "save_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "quit_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "copy_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_c, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "cut_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_x, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "paste_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_v, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "help_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_F1, 0, GTK_ACCEL_VISIBLE);
-
- item = (GtkWidget*)gtk_builder_get_object (builder, "about_item");
- gtk_widget_add_accelerator (item, "activate", accel_group,
- GDK_KEY_F7, 0, GTK_ACCEL_VISIBLE);
g_object_set_data_full (G_OBJECT(window), "builder", builder, g_object_unref);
}
diff --git a/demos/gtk-demo/demo.ui b/demos/gtk-demo/demo.ui
index 6fa269822e..7520467155 100644
--- a/demos/gtk-demo/demo.ui
+++ b/demos/gtk-demo/demo.ui
@@ -22,6 +22,75 @@
</row>
</data>
</object>
+ <menu id="menubar">
+ <submenu>
+ <attribute name="label" translatable="yes">_File</attribute>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_New</attribute>
+ <attribute name="action">win.new</attribute>
+ <attribute name="accel"><Primary>n</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Open</attribute>
+ <attribute name="action">win.open</attribute>
+ <attribute name="accel"><Primary>o</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Save</attribute>
+ <attribute name="action">win.save</attribute>
+ <attribute name="accel"><Primary>s</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Save _As</attribute>
+ <attribute name="action">win.save-as</attribute>
+ <attribute name="accel"><Primary>q</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Quit</attribute>
+ <attribute name="action">win.quit</attribute>
+ <attribute name="accel"><Primary><Shift>s</attribute>
+ </item>
+ </section>
+ </submenu>
+ <submenu>
+ <attribute name="label" translatable="yes">_Edit</attribute>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Copy</attribute>
+ <attribute name="action">win.copy</attribute>
+ <attribute name="accel"><Primary>c</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Cut</attribute>
+ <attribute name="action">win.cut</attribute>
+ <attribute name="accel"><Primary>x</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Paste</attribute>
+ <attribute name="action">win.paste</attribute>
+ <attribute name="accel"><Primary>v</attribute>
+ </item>
+ </section>
+ </submenu>
+ <submenu>
+ <attribute name="label" translatable="yes">_Help</attribute>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Help</attribute>
+ <attribute name="action">win.help</attribute>
+ <attribute name="accel">F1</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_About</attribute>
+ <attribute name="action">win.about</attribute>
+ <attribute name="accel">F7</attribute>
+ </item>
+ </section>
+ </submenu>
+ </menu>
<object class="GtkAboutDialog" id="aboutdialog1">
<property name="program-name" translatable="yes">Builder demo</property>
<property name="logo-icon-name" translatable="yes">gtk3-demo</property>
@@ -37,109 +106,8 @@
<object class="GtkBox" id="vbox1">
<property name="orientation">vertical</property>
<child>
- <object class="GtkMenuBar" id="menubar1">
- <child internal-child="accessible">
- <object class="AtkObject" id="a11y-menubar">
- <property name="AtkObject::accessible-name">The menubar</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem">
- <property name="label" translatable="yes">_File</property>
- <property name="use-underline">1</property>
- <child type="submenu">
- <object class="GtkMenu">
- <child>
- <object class="GtkMenuItem" id="new_item">
- <property name="label" translatable="yes">_New</property>
- <property name="use-underline">1</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="open_item">
- <property name="label" translatable="yes">_Open</property>
- <property name="use-underline">1</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="save_item">
- <property name="label" translatable="yes">_Save</property>
- <property name="use-underline">1</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="save_as_item">
- <property name="label" translatable="yes">Save _As</property>
- <property name="use-underline">1</property>
- <accelerator key="s" modifiers="primary | shift-mask" signal="activate"/>
- </object>
- </child>
- <child>
- <object class="GtkSeparatorMenuItem"/>
- </child>
- <child>
- <object class="GtkMenuItem" id="quit_item">
- <property name="label" translatable="yes">_Quit</property>
- <property name="use-underline">1</property>
- <property name="action-name">win.quit</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem">
- <property name="label" translatable="yes">_Edit</property>
- <property name="use-underline">1</property>
- <child type="submenu">
- <object class="GtkMenu">
- <child>
- <object class="GtkMenuItem" id="copy_item">
- <property name="label" translatable="yes">_Copy</property>
- <property name="use-underline">1</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="cut_item">
- <property name="label" translatable="yes">_Cut</property>
- <property name="use-underline">1</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="paste_item">
- <property name="label" translatable="yes">_Paste</property>
- <property name="use-underline">1</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem">
- <property name="label" translatable="yes">_Help</property>
- <property name="use-underline">1</property>
- <child type="submenu">
- <object class="GtkMenu">
- <child>
- <object class="GtkMenuItem" id="help_item">
- <property name="label" translatable="yes">_Help</property>
- <property name="use-underline">1</property>
- <property name="action-name">win.help</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="about_item">
- <property name="label" translatable="yes">_About</property>
- <property name="use-underline">1</property>
- <property name="action-name">win.about</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
+ <object class="GtkPopoverMenuBar" id="menubar1">
+ <property name="menu-model">menubar</property>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]