[gtk+] gtk3-demo-application: add an example for the new api



commit d818bdc297675a723869604f604e497ae53b6ea0
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 24 22:27:28 2012 -0500

    gtk3-demo-application: add an example for the new api
    
    Turn the menutoolbutton menu into one that is gmenu/gaction backed.

 demos/gtk-demo/application.c  |    8 ++++++++
 demos/gtk-demo/application.ui |   15 ++++-----------
 2 files changed, 12 insertions(+), 11 deletions(-)
---
diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c
index 95d4be9..7bce9fd 100644
--- a/demos/gtk-demo/application.c
+++ b/demos/gtk-demo/application.c
@@ -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);
 
diff --git a/demos/gtk-demo/application.ui b/demos/gtk-demo/application.ui
index af92b1c..b99e5ca 100644
--- a/demos/gtk-demo/application.ui
+++ b/demos/gtk-demo/application.ui
@@ -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>
@@ -106,4 +96,7 @@
       </packing>
     </child>
   </object>
+  <menu id="toolmenu">
+    <item label='File1' action='win.file1'/>
+  </menu>
 </interface>



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