]> Pileus Git - ~andy/gtk/commitdiff
Plugman: Find the plugins menu in a better way
authorMatthias Clasen <mclasen@redhat.com>
Wed, 14 Dec 2011 11:32:13 +0000 (06:32 -0500)
committerRyan Lortie <desrt@desrt.ca>
Mon, 19 Dec 2011 17:51:12 +0000 (12:51 -0500)
Now that GtkBuilder finds named submenus, there's no need for
the clumsy menumodel navigation anymore.

examples/plugman.c

index e9b6249155df6294b36f75a3c44d2fca290c06cd..ee49a172ef024cbd3f0a601b5590f6b33d6a30af 100644 (file)
@@ -187,30 +187,7 @@ plugin_enabled (const gchar *name)
 static GMenuModel *
 find_plugin_menu (void)
 {
-  GMenuModel *menubar;
-  GMenuModel *menu;
-  gint i, j;
-  const gchar *label, *id;
-
-  menubar = g_application_get_menubar (g_application_get_default ());
-  for (i = 0; i < g_menu_model_get_n_items (menubar); i++)
-    {
-       if (g_menu_model_get_item_attribute (menubar, i, "label", "s", &label) &&
-           g_strcmp0 (label, "_Edit") == 0)
-         {
-            menu = g_menu_model_get_item_link (menubar, i, "submenu");
-            for (j = 0; j < g_menu_model_get_n_items (menu); j++)
-              {
-                if (g_menu_model_get_item_attribute (menu, j, "id", "s", &id) &&
-                    g_strcmp0 (id, "plugins") == 0)
-                  {
-                    return g_menu_model_get_item_link (menu, j, "section");
-                  }
-              }
-         }
-    }
-
-  return NULL;
+  return (GMenuModel*) g_object_get_data (G_OBJECT (g_application_get_default ()), "plugin-menu");
 }
 
 static void
@@ -425,8 +402,8 @@ plug_man_startup (GApplication *application)
                                "        <item label='_Copy' action='win.copy'/>"
                                "        <item label='_Paste' action='win.paste'/>"
                                "      </section>"
-                               "      <section id='plugins'>"
-                               "      </section>"
+                               "      <item><link name='section' id='plugins'>"
+                               "      </link></item>"
                                "      <section>"
                                "        <item label='Plugins' action='app.plugins'/>"
                                "      </section>"
@@ -440,6 +417,7 @@ plug_man_startup (GApplication *application)
                                "</interface>", -1, NULL);
   g_application_set_app_menu (application, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
   g_application_set_menubar (application, G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+  g_object_set_data_full (G_OBJECT (application), "plugin-menu", gtk_builder_get_object (builder, "plugins"), g_object_unref);
   g_object_unref (builder);
 }