From 2df12ad5882cf78c10df47d927566a69afc3af4f Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Sun, 14 Feb 2010 19:48:51 +0100 Subject: ephy-tabs-menu: show favicons instead of radiobuttons in the tabs menu. Bug #405505 Signed-off-by: Xan Lopez --- src/ephy-tabs-menu.c | 75 ++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) (limited to 'src/ephy-tabs-menu.c') diff --git a/src/ephy-tabs-menu.c b/src/ephy-tabs-menu.c index 0d4875288..db76129e5 100644 --- a/src/ephy-tabs-menu.c +++ b/src/ephy-tabs-menu.c @@ -147,17 +147,12 @@ free_tab_id (GtkAction *action) } static void -tab_action_activate_cb (GtkToggleAction *action, +tab_action_activate_cb (GtkAction *action, EphyTabsMenu *menu) { EphyTabsMenuPrivate *priv = menu->priv; EphyEmbed *embed; - if (gtk_toggle_action_get_active (action) == FALSE) - { - return; - } - embed = g_object_get_data (G_OBJECT (action), DATA_KEY); g_return_if_fail (embed != NULL); @@ -181,6 +176,24 @@ sync_tab_title (EphyWebView *view, g_object_set (action, "label", title, NULL); } +static void +sync_tab_icon (EphyWebView *view, + GParamSpec *pspec, + GtkWidget *proxy) +{ + if (GTK_IS_MENU_ITEM (proxy)) + { + GdkPixbuf *pixbuf; + GtkWidget *image; + + pixbuf = ephy_web_view_get_icon (view); + image = gtk_image_new_from_pixbuf (pixbuf); + gtk_widget_show (image); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), image); + gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (proxy), TRUE); + } +} + static void notebook_page_added_cb (EphyNotebook *notebook, EphyEmbed *embed, @@ -190,16 +203,12 @@ notebook_page_added_cb (EphyNotebook *notebook, EphyTabsMenuPrivate *priv = menu->priv; GtkAction *action; char verb[ACTION_VERB_FORMAT_LENGTH]; - GSList *group; LOG ("tab_added_cb embed=%p", embed); g_snprintf (verb, sizeof (verb), ACTION_VERB_FORMAT, allocate_tab_id ()); - - action = g_object_new (GTK_TYPE_RADIO_ACTION, - "name", verb, - "tooltip", _("Switch to this tab"), - NULL); + + action = gtk_action_new (verb, NULL, _("Switch to this tab"), NULL); sync_tab_title (ephy_embed_get_web_view (embed), NULL, action); /* make sure the action is alive when handling the signal, see bug #169833 */ @@ -208,15 +217,6 @@ notebook_page_added_cb (EphyNotebook *notebook, gtk_action_group_add_action_with_accel (priv->action_group, action, NULL); - group = gtk_radio_action_get_group (GTK_RADIO_ACTION (priv->anchor_action)); - gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group); - - /* set this here too, since tab-added comes after notify::active-child */ - if (ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (priv->window)) == embed) - { - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); - } - g_object_set_data (G_OBJECT (embed), DATA_KEY, action); g_object_set_data (G_OBJECT (action), DATA_KEY, embed); @@ -276,36 +276,22 @@ connect_proxy_cb (GtkActionGroup *action_group, if (GTK_IS_MENU_ITEM (proxy)) { GtkLabel *label; + EphyEmbed *embed; + EphyWebView *view; label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (proxy))); gtk_label_set_use_underline (label, FALSE); gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END); gtk_label_set_max_width_chars (label, LABEL_WIDTH_CHARS); - } -} - -static void -sync_active_tab (EphyWindow *window, - GParamSpec *pspec, - EphyTabsMenu *menu) -{ - EphyEmbed *embed; - GtkAction *action; - embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); - if (embed == NULL) return; + embed = g_object_get_data (G_OBJECT (action), DATA_KEY); + view = ephy_embed_get_web_view (embed); - LOG ("active tab is embed %p", embed); - - action = g_object_get_data (G_OBJECT (embed), DATA_KEY); - /* happens initially, since the ::active-child comes before - * the ::tab-added signal - */ - /* FIXME that's not true with gtk+ 2.9 anymore */ - if (action == NULL) return; - - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); + sync_tab_icon (view, NULL, proxy); + g_signal_connect_object (view, "notify::icon", + G_CALLBACK (sync_tab_icon), proxy, 0); + } } static void @@ -332,9 +318,6 @@ ephy_tabs_menu_set_window (EphyTabsMenu *menu, g_signal_connect (priv->action_group, "connect-proxy", G_CALLBACK (connect_proxy_cb), NULL); - g_signal_connect (window, "notify::active-child", - G_CALLBACK (sync_active_tab), menu); - notebook = ephy_window_get_notebook (window); g_signal_connect_object (notebook, "page-added", G_CALLBACK (notebook_page_added_cb), menu, 0); -- cgit v1.2.3