From 3844f2dc783a6e505e7f114bc1a747e5c040021c Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 24 Sep 2003 12:06:06 +0000 Subject: Dave Bordoley 2003-09-24 Marco Pesenti Gritti Dave Bordoley * src/ephy-tab.c: (ephy_tab_action_activate_cb), (ephy_tab_init): * src/ephy-tabs-menu.c: (tab_added_cb), (tab_removed_cb), (ephy_tabs_menu_set_window), (ephy_tabs_menu_set_property), (ephy_tabs_menu_class_init), (ephy_tabs_menu_init), (ephy_tabs_menu_clean), (ephy_tabs_menu_update): * src/ephy-window.c: (ephy_window_set_active_tab), (tab_added_cb), (tab_removed_cb), (tabs_reordered_cb): Use radio buttons for tabs menu. Do not recreate the action group every time but keep it synced. * src/ephy-notebook.c: (ephy_notebook_insert_page): Emit added signal before activating the page. --- src/ephy-notebook.c | 4 +-- src/ephy-tab.c | 12 +++++-- src/ephy-tabs-menu.c | 90 +++++++++++++++++++++++++++++++++------------------- src/ephy-window.c | 20 ++++++------ 4 files changed, 78 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/ephy-notebook.c b/src/ephy-notebook.c index 3c1e178f7..d9e48d17b 100644 --- a/src/ephy-notebook.c +++ b/src/ephy-notebook.c @@ -1014,6 +1014,8 @@ ephy_notebook_insert_page (EphyNotebook *nb, g_signal_connect_object (tab, "notify::load-status", G_CALLBACK (sync_load_status), label, 0); + g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, child); + if (jump_to) { gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), @@ -1021,8 +1023,6 @@ ephy_notebook_insert_page (EphyNotebook *nb, g_object_set_data (G_OBJECT (child), "jump_to", GINT_TO_POINTER (jump_to)); } - - g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, child); } static void diff --git a/src/ephy-tab.c b/src/ephy-tab.c index c5091239a..8e5b4605a 100644 --- a/src/ephy-tab.c +++ b/src/ephy-tab.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #define EPHY_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TAB, EphyTabPrivate)) @@ -70,7 +71,7 @@ struct EphyTabPrivate int total_requests; int width; int height; - GtkAction *action; + GtkRadioAction *action; float zoom; EmbedSecurityLevel security_level; TabNavigationFlags nav_flags; @@ -230,7 +231,11 @@ ephy_tab_action_activate_cb (GtkAction *action, EphyTab *tab) { g_return_if_fail (EPHY_IS_TAB (tab)); - ephy_window_jump_to_tab (tab->priv->window, tab); + if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) && + ephy_window_get_active_tab (tab->priv->window) != tab) + { + ephy_window_jump_to_tab (tab->priv->window, tab); + } } static void @@ -1005,10 +1010,11 @@ ephy_tab_init (EphyTab *tab) id = g_strdup_printf ("Tab%lu", tab_id++); - tab->priv->action = g_object_new (GTK_TYPE_ACTION, + tab->priv->action = g_object_new (GTK_TYPE_RADIO_ACTION, "name", id, "label", _("Blank page"), NULL); + g_free (id); g_signal_connect (tab->priv->action, "activate", G_CALLBACK (ephy_tab_action_activate_cb), tab); diff --git a/src/ephy-tabs-menu.c b/src/ephy-tabs-menu.c index 91e1e2ff5..a2eceb1e0 100644 --- a/src/ephy-tabs-menu.c +++ b/src/ephy-tabs-menu.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -47,6 +48,7 @@ struct _EphyTabsMenuPrivate { EphyWindow *window; GtkActionGroup *action_group; + GSList *radio_group; guint ui_id; }; @@ -55,7 +57,6 @@ struct _EphyTabsMenuPrivate */ static void ephy_tabs_menu_class_init (EphyTabsMenuClass *klass); static void ephy_tabs_menu_init (EphyTabsMenu *menu); -static void ephy_tabs_menu_finalize_impl (GObject *o); enum { @@ -63,8 +64,6 @@ enum PROP_WINDOW }; -static gpointer g_object_class; - /** * EphyTabsMenu object */ @@ -97,6 +96,58 @@ ephy_tabs_menu_get_type (void) return ephy_tabs_menu_type; } +static void +tab_added_cb (EphyNotebook *notebook, GtkWidget *child, EphyTabsMenu *menu) +{ + EphyTab *tab; + GtkAction *action; + + g_return_if_fail (EPHY_IS_EMBED (child)); + tab = EPHY_TAB (g_object_get_data (G_OBJECT (child), "EphyTab")); + + action = GTK_ACTION (ephy_tab_get_action (tab)); + gtk_action_group_add_action (menu->priv->action_group, action); + + gtk_radio_action_set_group (GTK_RADIO_ACTION (action), menu->priv->radio_group); + menu->priv->radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action)); + + ephy_tabs_menu_update (menu); +} + +static void +tab_removed_cb (EphyNotebook *notebook, GtkWidget *child, EphyTabsMenu *menu) +{ + EphyTab *tab; + + g_return_if_fail (EPHY_IS_EMBED (child)); + tab = EPHY_TAB (g_object_get_data (G_OBJECT (child), "EphyTab")); + + gtk_action_group_remove_action (menu->priv->action_group, + GTK_ACTION (ephy_tab_get_action (tab))); + + ephy_tabs_menu_update (menu); +} + +static void +ephy_tabs_menu_set_window (EphyTabsMenu *menu, EphyWindow *window) +{ + GtkWidget *notebook; + GtkUIManager *merge; + + menu->priv->window = window; + + merge = GTK_UI_MANAGER (window->ui_merge); + menu->priv->action_group = gtk_action_group_new ("TabsActions"); + gtk_ui_manager_insert_action_group (merge, menu->priv->action_group, 0); + g_object_unref (menu->priv->action_group); + + notebook = ephy_window_get_notebook (window); + g_signal_connect_object (notebook, "tab_added", + G_CALLBACK (tab_added_cb), menu, 0); + g_signal_connect_object (notebook, "tab_removed", + G_CALLBACK (tab_removed_cb), menu, 0); +} + static void ephy_tabs_menu_set_property (GObject *object, guint prop_id, @@ -108,7 +159,8 @@ ephy_tabs_menu_set_property (GObject *object, switch (prop_id) { case PROP_WINDOW: - m->priv->window = g_value_get_object (value); + ephy_tabs_menu_set_window + (m, EPHY_WINDOW (g_value_get_object (value))); break; } } @@ -134,9 +186,6 @@ ephy_tabs_menu_class_init (EphyTabsMenuClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - G_OBJECT_CLASS (klass)->finalize = ephy_tabs_menu_finalize_impl; - g_object_class = g_type_class_peek_parent (klass); - object_class->set_property = ephy_tabs_menu_set_property; object_class->get_property = ephy_tabs_menu_get_property; @@ -158,6 +207,7 @@ ephy_tabs_menu_init (EphyTabsMenu *menu) menu->priv = EPHY_TABS_MENU_GET_PRIVATE (menu); menu->priv->ui_id = 0; + menu->priv->radio_group = NULL; menu->priv->action_group = NULL; } @@ -173,29 +223,8 @@ ephy_tabs_menu_clean (EphyTabsMenu *menu) gtk_ui_manager_ensure_update (merge); p->ui_id = 0; } - - if (p->action_group != NULL) - { - gtk_ui_manager_remove_action_group (merge, p->action_group); - g_object_unref (p->action_group); - } } -static void -ephy_tabs_menu_finalize_impl (GObject *o) -{ - EphyTabsMenu *menu = EPHY_TABS_MENU (o); - EphyTabsMenuPrivate *p = menu->priv; - - if (p->action_group != NULL) - { - g_object_unref (p->action_group); - } - - G_OBJECT_CLASS (g_object_class)->finalize (o); -} - - EphyTabsMenu * ephy_tabs_menu_new (EphyWindow *window) { @@ -270,7 +299,6 @@ ephy_tabs_menu_update (EphyTabsMenu *menu) num = g_list_length (tabs); if (num == 0) return; - p->action_group = gtk_action_group_new ("TabsActions"); p->ui_id = gtk_ui_manager_new_merge_id (merge); for (l = tabs; l != NULL; l = l->next) @@ -286,8 +314,6 @@ ephy_tabs_menu_update (EphyTabsMenu *menu) tab_set_action_accelerator (p->action_group, action, i); - gtk_action_group_add_action (p->action_group, action); - gtk_ui_manager_add_ui (merge, p->ui_id, "/menubar/TabsMenu/TabsOpen", name, action_name, @@ -297,7 +323,5 @@ ephy_tabs_menu_update (EphyTabsMenu *menu) g_list_free (tabs); - gtk_ui_manager_insert_action_group (merge, p->action_group, 0); - STOP_PROFILER ("Rebuilding tabs menu") } diff --git a/src/ephy-window.c b/src/ephy-window.c index 367c91e73..bdbd7822e 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -1128,6 +1129,8 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab) if (new_tab) { + GtkToggleAction *action; + sync_tab_address (new_tab, NULL, window); sync_tab_icon (new_tab, NULL, window); sync_tab_load_progress (new_tab, NULL, window); @@ -1179,6 +1182,9 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab) g_signal_connect_object (embed, "ge_context_menu", G_CALLBACK (tab_context_menu_cb), window, 0); + + action = GTK_TOGGLE_ACTION (ephy_tab_get_action (new_tab)); + gtk_toggle_action_set_active (action, TRUE); } } @@ -1213,13 +1219,6 @@ update_tabs_menu_sensitivity (EphyWindow *window) g_object_set (action, "sensitive", detach, NULL); } -static void -update_tabs_menu (EphyWindow *window) -{ - update_tabs_menu_sensitivity (window); - ephy_tabs_menu_update (window->priv->tabs_menu); -} - static void tab_added_cb (EphyNotebook *notebook, GtkWidget *child, EphyWindow *window) { @@ -1230,7 +1229,7 @@ tab_added_cb (EphyNotebook *notebook, GtkWidget *child, EphyWindow *window) window->priv->num_tabs++; - update_tabs_menu (window); + update_tabs_menu_sensitivity (window); g_signal_connect_object (G_OBJECT (tab), "notify::visible", G_CALLBACK (sync_tab_visibility), window, 0); @@ -1257,7 +1256,7 @@ tab_removed_cb (EphyNotebook *notebook, GtkWidget *child, EphyWindow *window) } else { - update_tabs_menu (window); + update_tabs_menu_sensitivity (window); } } @@ -1280,7 +1279,8 @@ tab_detached_cb (EphyNotebook *notebook, GtkWidget *child, static void tabs_reordered_cb (EphyNotebook *notebook, EphyWindow *window) { - update_tabs_menu (window); + update_tabs_menu_sensitivity (window); + ephy_tabs_menu_update (window->priv->tabs_menu); } static GtkNotebook * -- cgit v1.2.3