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
g_signal_connect (action, "activate", G_CALLBACK (plugin_action), (gpointer)name);
g_action_map_add_action (G_ACTION_MAP (g_application_get_default ()), action);
g_print ("Actions of '%s' plugin added\n", name);
+ g_object_unref (action);
plugin_menu = find_plugin_menu ();
if (plugin_menu)
GMenu *section;
GMenuItem *item;
gchar *label;
- gchar *action;
+ gchar *action_name;
section = g_menu_new ();
label = g_strdup_printf ("Turn text %s", name);
- action = g_strconcat ("app.", name, NULL);
- g_menu_insert (section, 0, label, action);
+ action_name = g_strconcat ("app.", name, NULL);
+ g_menu_insert (section, 0, label, action_name);
g_free (label);
- g_free (action);
+ g_free (action_name);
item = g_menu_item_new_section (NULL, (GMenuModel*)section);
g_menu_item_set_attribute (item, "id", "s", name);
g_menu_append_item (G_MENU (plugin_menu), item);
" <property name='visible'>True</property>"
" <child>"
" <object class='GtkCheckButton' id='red-plugin'>"
- " <property name='label'>Red Plugin - turn your text red</property>"
+ " <property name='label' translatable='yes'>Red Plugin - turn your text red</property>"
" <property name='visible'>True</property>"
" </object>"
" </child>"
" <child>"
" <object class='GtkCheckButton' id='black-plugin'>"
- " <property name='label'>Black Plugin - turn your text black</property>"
+ " <property name='label' translatable='yes'>Black Plugin - turn your text black</property>"
" <property name='visible'>True</property>"
" </object>"
" </child>"
" <property name='visible'>True</property>"
" <child>"
" <object class='GtkButton' id='close-button'>"
- " <property name='label'>Close</property>"
+ " <property name='label' translatable='yes'>Close</property>"
" <property name='visible'>True</property>"
" </object>"
" </child>"
"<interface>"
" <menu id='app-menu'>"
" <section>"
- " <item label='_About Plugman' action='app.about'/>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_About Plugman</attribute>"
+ " <attribute name='action'>app.about</attribute>"
+ " </item>"
" </section>"
" <section>"
- " <item label='_Quit' action='app.quit' accel='<Primary>q'/>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_Quit</attribute>"
+ " <attribute name='action'>app.quit</attribute>"
+ " <attribute name='accel'><Primary>q</attribute>"
+ " </item>"
" </section>"
" </menu>"
" <menu id='menubar'>"
- " <submenu label='_Edit'>"
+ " <submenu>"
+ " <attribute name='label' translatable='yes'>_Edit</attribute>"
" <section>"
- " <item label='_Copy' action='win.copy'/>"
- " <item label='_Paste' action='win.paste'/>"
- " </section>"
- " <section id='plugins'>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_Copy</attribute>"
+ " <attribute name='action'>win.copy</attribute>"
+ " </item>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_Paste</attribute>"
+ " <attribute name='action'>win.paste</attribute>"
+ " </item>"
" </section>"
+ " <item><link name='section' id='plugins'>"
+ " </link></item>"
" <section>"
- " <item label='Plugins' action='app.plugins'/>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>Plugins</attribute>"
+ " <attribute name='action'>app.plugins</attribute>"
+ " </item>"
" </section>"
" </submenu>"
- " <submenu label='_View'>"
+ " <submenu>"
+ " <attribute name='label' translatable='yes'>_View</attribute>"
" <section>"
- " <item label='_Fullscreen' action='win.fullscreen'/>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_Fullscreen</attribute>"
+ " <attribute name='action'>win.fullscreen</attribute>"
+ " </item>"
" </section>"
" </submenu>"
" </menu>"
"</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")));
+ gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+ gtk_application_set_menubar (GTK_APPLICATION (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);
}
PlugMan *
plug_man_new (void)
{
- g_type_init ();
-
return g_object_new (plug_man_get_type (),
"application-id", "org.gtk.Test.plugman",
"flags", G_APPLICATION_HANDLES_OPEN,