diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ephy-favorites-menu.c | 37 | ||||
-rw-r--r-- | src/ephy-tabs-menu.c | 29 |
2 files changed, 17 insertions, 49 deletions
diff --git a/src/ephy-favorites-menu.c b/src/ephy-favorites-menu.c index 99afe038c..89333809e 100644 --- a/src/ephy-favorites-menu.c +++ b/src/ephy-favorites-menu.c @@ -28,6 +28,7 @@ #include "ephy-debug.h" #include <gtk/gtkuimanager.h> +#include <glib/gprintf.h> /** * Private data @@ -115,7 +116,6 @@ static void ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm) { EphyFavoritesMenuPrivate *p = wrhm->priv; - GString *xml; gint i; EphyNode *fav; GPtrArray *children; @@ -130,21 +130,19 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm) fav = ephy_bookmarks_get_favorites (p->bookmarks); children = ephy_node_get_children (fav); - xml = g_string_new (NULL); - g_string_append (xml, "<ui><menubar><menu name=\"GoMenu\">" - "<placeholder name=\"GoFavorites\">" - "<separator name=\"GoSep3\"/>"); - p->action_group = gtk_action_group_new ("FavoritesActions"); gtk_ui_manager_insert_action_group (merge, p->action_group, 0); + p->ui_id = gtk_ui_manager_new_merge_id (merge); for (i = 0; i < children->len; i++) { - char *verb; + char verb[20]; + char name[20]; EphyNode *node; GtkAction *action; - verb = g_strdup_printf ("GoFav%d", i); + g_sprintf (verb, "GoFav%d", i); + g_sprintf (name, "GoFav%dMenu", i); node = g_ptr_array_index (children, i); @@ -155,29 +153,12 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm) g_signal_connect (action, "go_location", G_CALLBACK (go_location_cb), p->window); - g_string_append (xml, "<menuitem name=\""); - g_string_append (xml, verb); - g_string_append (xml, "Menu"); - g_string_append (xml, "\" action=\""); - g_string_append (xml, verb); - g_string_append (xml, "\"/>\n"); - - g_free (verb); + gtk_ui_manager_add_ui (merge, p->ui_id, + "/menubar/GoMenu/GoFavorites", + name, verb); } ephy_node_thaw (fav); - g_string_append (xml, "</placeholder></menu></menubar></ui>"); - - if (children->len > 0) - { - GError *error = NULL; - LOG ("Merging ui\n%s",xml->str); - p->ui_id = gtk_ui_manager_add_ui_from_string - (merge, xml->str, -1, &error); - } - - g_string_free (xml, TRUE); - STOP_PROFILER ("Rebuild favorites menu") } diff --git a/src/ephy-tabs-menu.c b/src/ephy-tabs-menu.c index 02bcd9b08..0dad11885 100644 --- a/src/ephy-tabs-menu.c +++ b/src/ephy-tabs-menu.c @@ -254,11 +254,9 @@ ephy_tabs_menu_update (EphyTabsMenu *menu) GtkUIManager *merge; EphyTab *tab; GtkAction *action; - GString *xml; guint i = 0; guint num = 0; GList *tabs = NULL, *l; - GError *error = NULL; g_return_if_fail (EPHY_IS_TABS_MENU (menu)); p = menu->priv; @@ -276,43 +274,32 @@ ephy_tabs_menu_update (EphyTabsMenu *menu) if (num == 0) return; p->action_group = gtk_action_group_new ("TabsActions"); - - /* it's faster to preallocate, MIN is sanity check */ - xml = g_string_sized_new (44 * MIN (num, 64) + 105); - - g_string_append (xml, "<ui><menubar><menu name=\"TabsMenu\">" - "<placeholder name=\"TabsOpen\">"); + p->ui_id = gtk_ui_manager_new_merge_id (merge); for (l = tabs; l != NULL; l = l->next) { const char *action_name; + char *name; + tab = (EphyTab *) l->data; action = GTK_ACTION (ephy_tab_get_action (tab)); action_name = gtk_action_get_name (action); + name = g_strdup_printf ("%sMenu", action_name); tab_set_action_accelerator (p->action_group, action, i); gtk_action_group_add_action (p->action_group, action); - g_string_append (xml, "<menuitem name=\""); - g_string_append (xml, action_name); - g_string_append (xml, "Menu\" action=\""); - g_string_append (xml, action_name); - g_string_append (xml, "\"/>\n"); - - ++i; + gtk_ui_manager_add_ui (merge, p->ui_id, + "/menubar/TabsMenu/TabsOpen", + name, action_name); + g_free (name); } g_list_free (tabs); - g_string_append (xml, "</placeholder></menu></menubar></ui>"); - gtk_ui_manager_insert_action_group (merge, p->action_group, 0); - p->ui_id = gtk_ui_manager_add_ui_from_string - (merge, xml->str, -1, &error); - - g_string_free (xml, TRUE); STOP_PROFILER ("Rebuilding tabs menu") } |