diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2003-05-29 20:16:50 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2003-05-29 20:16:50 +0800 |
commit | 2c31318d613005eb170d7a06292c2b18a054adb0 (patch) | |
tree | 8761fa378c9282f253e49dac116bed295b5ff6c4 | |
parent | 3893baeacbcdc24efbd7aca4e67508ddba2a4a5c (diff) | |
download | gsoc2013-epiphany-2c31318d613005eb170d7a06292c2b18a054adb0.tar.gz gsoc2013-epiphany-2c31318d613005eb170d7a06292c2b18a054adb0.tar.zst gsoc2013-epiphany-2c31318d613005eb170d7a06292c2b18a054adb0.zip |
Get rid of MAKE_GET_TYPE; make building the tabs menu a little faster.
2003-05-29 Christian Persch <chpe@cvs.gnome.org>
* src/ephy-tabs-menu.c: (ephy_tabs_menu_get_type),
(ephy_tabs_menu_verb_cb), (ephy_tabs_menu_rebuild):
Get rid of MAKE_GET_TYPE; make building the tabs menu a little faster.
* src/ephy-window.c: (update_tabs_menu_sensitivity),
(ephy_window_get_tabs):
Remove one unnecessary call to ephy_tabs_update_menu ().
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | src/ephy-tabs-menu.c | 110 | ||||
-rw-r--r-- | src/ephy-window.c | 6 |
3 files changed, 77 insertions, 51 deletions
@@ -1,5 +1,17 @@ 2003-05-29 Christian Persch <chpe@cvs.gnome.org> + * src/ephy-tabs-menu.c: (ephy_tabs_menu_get_type), + (ephy_tabs_menu_verb_cb), (ephy_tabs_menu_rebuild): + + Get rid of MAKE_GET_TYPE; make building the tabs menu a little faster. + + * src/ephy-window.c: (update_tabs_menu_sensitivity), + (ephy_window_get_tabs): + + Remove one unnecessary call to ephy_tabs_update_menu (). + +2003-05-29 Christian Persch <chpe@cvs.gnome.org> + * lib/ephy-langs.h: * data/glade/prefs-dialog.glade: * src/prefs-dialog.c: (autodetector_info_free), (prefs_dialog_finalize), diff --git a/src/ephy-tabs-menu.c b/src/ephy-tabs-menu.c index f8b697eb0..67737997a 100644 --- a/src/ephy-tabs-menu.c +++ b/src/ephy-tabs-menu.c @@ -44,12 +44,6 @@ struct _EphyTabsMenuPrivate guint ui_id; }; -typedef struct -{ - EphyWindow *window; - EphyTab *tab; -} TabsData; - /** * Private functions, only availble from this file */ @@ -77,10 +71,34 @@ static gpointer g_object_class; /** * EphyTabsMenu object */ -MAKE_GET_TYPE (ephy_tabs_menu, - "EphyTabsMenu", EphyTabsMenu, - ephy_tabs_menu_class_init, ephy_tabs_menu_init, - G_TYPE_OBJECT); + +GType +ephy_tabs_menu_get_type (void) +{ + static GType ephy_tabs_menu_type = 0; + + if (ephy_tabs_menu_type == 0) + { + static const GTypeInfo our_info = + { + sizeof (EphyTabsMenuClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) ephy_tabs_menu_class_init, + NULL, + NULL, /* class_data */ + sizeof (EphyTab), + 0, /* n_preallocs */ + (GInstanceInitFunc) ephy_tabs_menu_init + }; + + ephy_tabs_menu_type = g_type_register_static (G_TYPE_OBJECT, + "EphyTabsMenu", + &our_info, 0); + } + + return ephy_tabs_menu_type; +} static void ephy_tabs_menu_class_init (EphyTabsMenuClass *klass) @@ -193,10 +211,14 @@ ephy_tabs_menu_new (EphyWindow *window) } static void -ephy_tabs_menu_verb_cb (EggMenuMerge *merge, - TabsData *data) +ephy_tabs_menu_verb_cb (EggAction *action, EphyTab *tab) { - ephy_window_jump_to_tab (data->window, data->tab); + EphyWindow *window; + + g_return_if_fail (IS_EPHY_TAB (tab)); + + window = ephy_tab_get_window (tab); + ephy_window_jump_to_tab (window, tab); } @@ -252,57 +274,54 @@ static void ephy_tabs_menu_rebuild (EphyTabsMenu *wrhm) { EphyTabsMenuPrivate *p = wrhm->priv; - GString *xml; - gint i; - GList *tabs; EggMenuMerge *merge = EGG_MENU_MERGE (p->window->ui_merge); + GString *xml; + guint i = 0; + guint len; + GList *tabs, *l; + GError *error = NULL; LOG ("Rebuilding open tabs menu") + START_PROFILER ("Rebuilding tabs menu") + ephy_tabs_menu_clean (wrhm); tabs = ephy_window_get_tabs (p->window); + len = g_list_length (tabs); + if (len == 0) return; + + /* it's faster to preallocate */ + xml = g_string_sized_new (52 * len + 105); - xml = g_string_new (NULL); g_string_append (xml, "<Root><menu><submenu name=\"TabsMenu\">" "<placeholder name=\"TabsOpen\">"); p->action_group = egg_action_group_new ("TabsActions"); egg_menu_merge_insert_action_group (merge, p->action_group, 0); - for (i = 0; i < g_list_length (tabs); i++) + for (l = tabs; l != NULL; l = l->next) { - char *verb = g_strdup_printf ("TabsOpen%d", i); - char *title_s; - const char *title; - xmlChar *label_x; - EphyTab *child; - TabsData *data; + gchar *verb = g_strdup_printf ("TabsOpen%d", i); + gchar *title_s; + const gchar *title; + EphyTab *tab; EggAction *action; - child = g_list_nth_data (tabs, i); + tab = (EphyTab *) l->data; - title = ephy_tab_get_title(child); + title = ephy_tab_get_title (tab); title_s = ephy_string_shorten (title, MAX_LABEL_LENGTH); - label_x = xmlEncodeSpecialChars (NULL, title_s); - - data = g_new0 (TabsData, 1); - data->window = wrhm->priv->window; - data->tab = child; action = g_object_new (EGG_TYPE_ACTION, "name", verb, - "label", label_x, - "tooltip", "Hello", + "label", title_s, + "tooltip", title, "stock_id", NULL, NULL); - g_signal_connect_closure - (action, "activate", - g_cclosure_new (G_CALLBACK (ephy_tabs_menu_verb_cb), - data, - (GClosureNotify)g_free), - FALSE); + g_signal_connect (action, "activate", + G_CALLBACK (ephy_tabs_menu_verb_cb), tab); ephy_tabs_menu_set_action_accelerator (p->action_group, action, i); @@ -316,22 +335,19 @@ ephy_tabs_menu_rebuild (EphyTabsMenu *wrhm) g_string_append (xml, verb); g_string_append (xml, "\"/>\n"); - xmlFree (label_x); g_free (title_s); g_free (verb); + + ++i; } g_string_append (xml, "</placeholder></submenu></menu></Root>"); - if (g_list_length (tabs) > 0) - { - GError *error = NULL; - LOG ("Merging ui\n%s",xml->str); - p->ui_id = egg_menu_merge_add_ui_from_string - (merge, xml->str, -1, &error); - } + p->ui_id = egg_menu_merge_add_ui_from_string (merge, xml->str, -1, &error); g_string_free (xml, TRUE); + + STOP_PROFILER ("Rebuilding tabs menu") } void ephy_tabs_menu_update (EphyTabsMenu *wrhm) diff --git a/src/ephy-window.c b/src/ephy-window.c index 69c6b3a42..20f45a8d5 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -531,8 +531,6 @@ update_tabs_menu_sensitivity (EphyWindow *window) g_object_set (action, "sensitive", move_right, NULL); action = egg_action_group_get_action (action_group, "TabsDetach"); g_object_set (action, "sensitive", detach, NULL); - - ephy_tabs_menu_update (window->priv->tabs_menu); } static void @@ -1369,11 +1367,11 @@ ephy_window_get_tabs (EphyWindow *window) tab = g_object_get_data (G_OBJECT (w), "EphyTab"); g_return_val_if_fail (IS_EPHY_TAB (G_OBJECT (tab)), NULL); - tabs = g_list_append (tabs, tab); + tabs = g_list_prepend (tabs, tab); i++; } - return tabs; + return g_list_reverse (tabs); } static void |