[gtk/no-app-menu: 1/5] gtk-demo: Stop using application menu apis



commit 3f557ddb55dcc663d77ad3495b0cc2cfde066b4d
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 21 00:34:38 2020 -0400

    gtk-demo: Stop using application menu apis
    
    The menu-related GtkApplication and GtkAppliationWindow
    apis are going away. Just use a regular menubar.

 demos/gtk-demo/application.c  |  22 ---------
 demos/gtk-demo/application.ui | 110 ++++++++++++++++++++++++++++++++++++++++++
 demos/gtk-demo/main.c         |  18 -------
 3 files changed, 110 insertions(+), 40 deletions(-)
---
diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c
index 64cf105a4e..ba0762c440 100644
--- a/demos/gtk-demo/application.c
+++ b/demos/gtk-demo/application.c
@@ -324,27 +324,6 @@ clicked_cb (GtkWidget *widget, DemoApplicationWindow *window)
   gtk_widget_hide (window->infobar);
 }
 
-static void
-startup (GApplication *app)
-{
-  GtkBuilder *builder;
-  GMenuModel *appmenu;
-  GMenuModel *menubar;
-
-  G_APPLICATION_CLASS (demo_application_parent_class)->startup (app);
-
-  builder = gtk_builder_new ();
-  gtk_builder_add_from_resource (builder, "/application_demo/menus.ui", NULL);
-
-  appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
-  menubar = (GMenuModel *)gtk_builder_get_object (builder, "menubar");
-
-  gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
-  gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
-
-  g_object_unref (builder);
-}
-
 static void
 create_window (GApplication *app,
                const char   *content)
@@ -390,7 +369,6 @@ demo_application_class_init (DemoApplicationClass *class)
 {
   GApplicationClass *app_class = G_APPLICATION_CLASS (class);
 
-  app_class->startup = startup;
   app_class->activate = activate;
 }
 
diff --git a/demos/gtk-demo/application.ui b/demos/gtk-demo/application.ui
index 14f2b22566..6d8b78988b 100644
--- a/demos/gtk-demo/application.ui
+++ b/demos/gtk-demo/application.ui
@@ -1,5 +1,106 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
+  <menu id="menubar">
+    <submenu>
+      <attribute name="label" translatable="yes">_File</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_New</attribute>
+          <attribute name="action">app.new</attribute>
+          <attribute name="accel">&lt;Control&gt;n</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Open</attribute>
+          <attribute name="action">app.open</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Save</attribute>
+          <attribute name="action">app.save</attribute>
+          <attribute name="accel">&lt;Control&gt;s</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Save _As...</attribute>
+          <attribute name="action">app.save-as</attribute>
+          <attribute name="accel">&lt;Control&gt;s</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Quit</attribute>
+          <attribute name="action">app.quit</attribute>
+          <attribute name="accel">&lt;Control&gt;q</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name="label" translatable="yes">_Preferences</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Prefer Dark Theme</attribute>
+          <attribute name="action">app.dark</attribute>
+        </item>
+        <submenu>
+          <attribute name="label" translatable="yes">_Color</attribute>
+          <section>
+            <item>
+              <attribute name="label" translatable="yes">_Red</attribute>
+              <attribute name="action">app.color</attribute>
+              <attribute name="target">red</attribute>
+              <attribute name="accel">&lt;Control&gt;r</attribute>
+            </item>
+            <item>
+              <attribute name="label" translatable="yes">_Green</attribute>
+              <attribute name="action">app.color</attribute>
+              <attribute name="target">green</attribute>
+              <attribute name="accel">&lt;Control&gt;g</attribute>
+            </item>
+            <item>
+              <attribute name="label" translatable="yes">_Blue</attribute>
+              <attribute name="action">app.color</attribute>
+              <attribute name="target">blue</attribute>
+              <attribute name="accel">&lt;Control&gt;b</attribute>
+            </item>
+          </section>
+        </submenu>
+        <submenu>
+          <attribute name="label" translatable="yes">_Shape</attribute>
+          <section>
+            <item>
+              <attribute name="label" translatable="yes">_Square</attribute>
+              <attribute name="action">win.shape</attribute>
+              <attribute name="target">square</attribute>
+              <attribute name="accel">&lt;Control&gt;s</attribute>
+            </item>
+            <item>
+              <attribute name="label" translatable="yes">_Rectangle</attribute>
+              <attribute name="action">win.shape</attribute>
+              <attribute name="target">rectangle</attribute>
+              <attribute name="accel">&lt;Control&gt;r</attribute>
+            </item>
+            <item>
+              <attribute name="label" translatable="yes">_Oval</attribute>
+              <attribute name="action">win.shape</attribute>
+              <attribute name="target">oval</attribute>
+              <attribute name="accel">&lt;Control&gt;o</attribute>
+            </item>
+          </section>
+        </submenu>
+        <item>
+          <attribute name="label" translatable="yes">_Bold</attribute>
+          <attribute name="action">win.bold</attribute>
+          <attribute name="accel">&lt;Control&gt;&lt;Shift&gt;b</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name="label" translatable="yes">_Help</attribute>
+      <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">win.about</attribute>
+        <attribute name="accel">&lt;Control&gt;a</attribute>
+      </item>
+    </submenu>
+  </menu>
   <template class="DemoApplicationWindow" parent="GtkApplicationWindow">
     <property name="title" translatable="yes">Application Class</property>
     <property name="default-width">200</property>
@@ -7,6 +108,15 @@
     <property name="icon-name">document-open</property>
     <child>
       <object class="GtkGrid">
+        <child>
+          <object class="GtkPopoverMenuBar">
+            <property name="menu-model">menubar</property>
+            <layout>
+              <property name="left-attach">0</property>
+              <property name="top-attach">-1</property>
+            </layout>
+          </object>
+        </child>
         <child>
           <object class="GtkBox">
             <property name="hexpand">1</property>
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index f8ef62d915..653e7a2f4a 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -972,23 +972,6 @@ populate_model (GtkTreeModel *model)
 
 }
 
-static void
-startup (GApplication *app)
-{
-  GtkBuilder *builder;
-  GMenuModel *appmenu;
-  const char *ids[] = { "appmenu", NULL };
-
-  builder = gtk_builder_new ();
-  gtk_builder_add_objects_from_resource (builder, "/ui/appmenu.ui", ids, NULL);
-
-  appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
-
-  gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
-
-  g_object_unref (builder);
-}
-
 static void
 row_activated_cb (GtkWidget         *tree_view,
                   GtkTreePath       *path,
@@ -1219,7 +1202,6 @@ main (int argc, char **argv)
   g_application_add_main_option (G_APPLICATION (app), "list", 0, 0, G_OPTION_ARG_NONE, "List examples", 
NULL);
   g_application_add_main_option (G_APPLICATION (app), "autoquit", 0, 0, G_OPTION_ARG_NONE, "Quit after a 
delay", NULL);
 
-  g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
   g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
   g_signal_connect (app, "handle-local-options", G_CALLBACK (local_options), NULL);


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