]> Pileus Git - ~andy/gtk/commitdiff
gtk3-demo-application: add an example for the new api
authorMatthias Clasen <mclasen@redhat.com>
Wed, 25 Jan 2012 03:27:28 +0000 (22:27 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 25 Jan 2012 03:27:28 +0000 (22:27 -0500)
Turn the menutoolbutton menu into one that is gmenu/gaction backed.

demos/gtk-demo/application.c
demos/gtk-demo/application.ui

index 95d4be95815a7ea85d399f6c917393a1c4f92cb8..7bce9fd6c94e3760234742defc8e442eddf237bb 100644 (file)
@@ -283,6 +283,7 @@ static GActionEntry win_entries[] = {
   { "shape", activate_radio, "s", "'oval'", change_radio_state },
   { "bold", activate_toggle, NULL, "false", NULL },
   { "about", activate_about, NULL, NULL, NULL },
+  { "file1", activate_action, NULL, NULL, NULL },
   { "logo", activate_action, NULL, NULL, NULL }
 };
 
@@ -322,6 +323,8 @@ activate (GApplication *app)
   GtkWidget *message;
   GtkWidget *button;
   GtkWidget *infobar;
+  GtkWidget *menutool;
+  GMenuModel *toolmenu;
   GtkTextBuffer *buffer;
 
   window = gtk_application_window_new (GTK_APPLICATION (app));
@@ -342,12 +345,17 @@ activate (GApplication *app)
   message = (GtkWidget *)gtk_builder_get_object (builder, "message");
   button = (GtkWidget *)gtk_builder_get_object (builder, "button");
   infobar = (GtkWidget *)gtk_builder_get_object (builder, "infobar");
+  menutool = (GtkWidget *)gtk_builder_get_object (builder, "menutool");
+  toolmenu = (GMenuModel *)gtk_builder_get_object (builder, "toolmenu");
 
   g_object_set_data (G_OBJECT (window), "message", message);
   g_object_set_data (G_OBJECT (window), "infobar", infobar);
 
   gtk_container_add (GTK_CONTAINER (window), grid);
 
+  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (menutool),
+                                 gtk_menu_new_from_model (toolmenu));
+
   gtk_widget_grab_focus (contents);
   g_signal_connect (button, "clicked", G_CALLBACK (clicked_cb), infobar);
 
index af92b1c2a487546687efac6ad47fc3feeb17bdf3..b99e5ca0d5cbe111f96054cb7752dc459322d848 100644 (file)
@@ -7,18 +7,8 @@
         <property name="halign">fill</property>
         <property name="hexpand">True</property>
         <child>
-          <object class="GtkMenuToolButton" id="menu">
+          <object class="GtkMenuToolButton" id="menutool">
             <property name="stock-id">gtk-open</property>
-            <child type="menu">
-              <object class="GtkMenu" id="m">
-                <child>
-                  <object class="GtkMenuItem" id="file">
-                    <property name="visible">True</property>
-                    <property name="label">File1</property>
-                  </object>
-                </child>
-              </object>
-            </child>
           </object>
         </child>
         <child>
       </packing>
     </child>
   </object>
+  <menu id="toolmenu">
+    <item label='File1' action='win.file1'/>
+  </menu>
 </interface>