From b934ed62cfeb93b86c0f655eff39ff0de63ef7df Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 8 Apr 2003 22:42:33 +0000 Subject: Add funcs to add/remove focus monitor. Make the code nicer and fix warning 2003-04-09 Marco Pesenti Gritti * src/bookmarks/ephy-bookmarks-editor.c: (add_focus_monitor), (remove_focus_monitor), (ephy_bookmarks_editor_dispose), (ephy_bookmarks_editor_node_selected_cb), (ephy_bookmarks_editor_construct): Add funcs to add/remove focus monitor. Make the code nicer and fix warning on destroy. --- ChangeLog | 10 +++ src/bookmarks/ephy-bookmarks-editor.c | 145 ++++++++++++++++++---------------- 2 files changed, 88 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index 60fe294bc..aa6e8c49c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-04-09 Marco Pesenti Gritti + + * src/bookmarks/ephy-bookmarks-editor.c: (add_focus_monitor), + (remove_focus_monitor), (ephy_bookmarks_editor_dispose), + (ephy_bookmarks_editor_node_selected_cb), + (ephy_bookmarks_editor_construct): + + Add funcs to add/remove focus monitor. Make the code nicer + and fix warning on destroy. + 2003-04-08 Johan Dahlin * src/bookmarks/ephy-topic-action.c (build_topics_menu): If there diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index e1c8c168d..4786c9d67 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -397,48 +397,6 @@ ephy_bookmarks_editor_class_init (EphyBookmarksEditorClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } -static void -ephy_bookmarks_editor_dispose (GObject *object) -{ - EphyBookmarksEditor *editor; - long selected_id; - char *selected_id_str; - GList *selection; - - g_return_if_fail (object != NULL); - g_return_if_fail (EPHY_IS_BOOKMARKS_EDITOR (object)); - - editor = EPHY_BOOKMARKS_EDITOR (object); - - g_return_if_fail (editor->priv != NULL); - - if (editor->priv->key_view != NULL) - { - selection = ephy_node_view_get_selection (EPHY_NODE_VIEW (editor->priv->key_view)); - if (selection == NULL || selection->data == NULL) - { - editor->priv->key_view = NULL; - G_OBJECT_CLASS (parent_class)->dispose (object); - return; - } - - selected_id = ephy_node_get_id (EPHY_NODE (selection->data)); - if (selected_id >= 0) - { - selected_id_str = g_strdup_printf ("%ld", selected_id); - eel_gconf_set_string (CONF_BOOKMARKS_SELECTED_NODE, - selected_id_str); - g_free (selected_id_str); - } - - g_list_free (selection); - - editor->priv->key_view = NULL; - } - - G_OBJECT_CLASS (parent_class)->dispose (object); -} - static void ephy_bookmarks_editor_finalize (GObject *object) { @@ -551,14 +509,6 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor, g_object_set (action, "sensitive", properties, NULL); } -static void -ephy_bookmarks_editor_node_selected_cb (EphyNodeView *view, - EphyNode *node, - EphyBookmarksEditor *editor) -{ - ephy_bookmarks_editor_update_menu (editor, view); -} - static gboolean view_focus_cb (EphyNodeView *view, GdkEventFocus *event, @@ -569,6 +519,81 @@ view_focus_cb (EphyNodeView *view, return FALSE; } +static void +add_focus_monitor (EphyBookmarksEditor *editor, GtkWidget *widget) +{ + g_signal_connect (G_OBJECT (widget), + "focus_in_event", + G_CALLBACK (view_focus_cb), + editor); + g_signal_connect (G_OBJECT (widget), + "focus_out_event", + G_CALLBACK (view_focus_cb), + editor); +} + +static void +remove_focus_monitor (EphyBookmarksEditor *editor, GtkWidget *widget) +{ + g_signal_handlers_disconnect_by_func (G_OBJECT (widget), + G_CALLBACK (view_focus_cb), + editor); +} + +static void +ephy_bookmarks_editor_dispose (GObject *object) +{ + EphyBookmarksEditor *editor; + long selected_id; + char *selected_id_str; + GList *selection; + + g_return_if_fail (object != NULL); + g_return_if_fail (EPHY_IS_BOOKMARKS_EDITOR (object)); + + editor = EPHY_BOOKMARKS_EDITOR (object); + + g_return_if_fail (editor->priv != NULL); + + if (editor->priv->key_view != NULL) + { + remove_focus_monitor (editor, editor->priv->key_view); + remove_focus_monitor (editor, editor->priv->bm_view); + + selection = ephy_node_view_get_selection (EPHY_NODE_VIEW (editor->priv->key_view)); + if (selection == NULL || selection->data == NULL) + { + editor->priv->key_view = NULL; + G_OBJECT_CLASS (parent_class)->dispose (object); + return; + } + + selected_id = ephy_node_get_id (EPHY_NODE (selection->data)); + if (selected_id >= 0) + { + selected_id_str = g_strdup_printf ("%ld", selected_id); + eel_gconf_set_string (CONF_BOOKMARKS_SELECTED_NODE, + selected_id_str); + g_free (selected_id_str); + } + + g_list_free (selection); + + editor->priv->key_view = NULL; + } + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + + +static void +ephy_bookmarks_editor_node_selected_cb (EphyNodeView *view, + EphyNode *node, + EphyBookmarksEditor *editor) +{ + ephy_bookmarks_editor_update_menu (editor, view); +} + static void bookmarks_filter (EphyBookmarksEditor *editor, EphyNode *keyword) @@ -806,10 +831,11 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) ephy_node_view_set_browse_mode (EPHY_NODE_VIEW (key_view)); ephy_node_view_add_column (EPHY_NODE_VIEW (key_view), _("Topics"), EPHY_TREE_MODEL_NODE_COL_KEYWORD, TRUE, TRUE); - gtk_container_add (GTK_CONTAINER (scrolled_window), key_view); + gtk_container_add (GTK_CONTAINER (scrolled_window), key_view); gtk_widget_set_size_request (key_view, 130, -1); gtk_widget_show (key_view); editor->priv->key_view = key_view; + add_focus_monitor (editor, key_view); g_signal_connect (G_OBJECT (key_view), "key_press_event", G_CALLBACK (key_pressed_cb), @@ -818,14 +844,6 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) "node_selected", G_CALLBACK (keyword_node_selected_cb), editor); - g_signal_connect (G_OBJECT (key_view), - "focus_in_event", - G_CALLBACK (view_focus_cb), - editor); - g_signal_connect (G_OBJECT (key_view), - "focus_out_event", - G_CALLBACK (view_focus_cb), - editor); g_signal_connect (G_OBJECT (key_view), "show_popup", G_CALLBACK (keyword_node_show_popup_cb), @@ -870,6 +888,7 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) gtk_container_add (GTK_CONTAINER (scrolled_window), bm_view); gtk_widget_show (bm_view); editor->priv->bm_view = bm_view; + add_focus_monitor (editor, bm_view); g_signal_connect (G_OBJECT (bm_view), "key_press_event", G_CALLBACK (key_pressed_cb), @@ -882,14 +901,6 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) "node_selected", G_CALLBACK (ephy_bookmarks_editor_node_selected_cb), editor); - g_signal_connect (G_OBJECT (bm_view), - "focus_in_event", - G_CALLBACK (view_focus_cb), - editor); - g_signal_connect (G_OBJECT (bm_view), - "focus_out_event", - G_CALLBACK (view_focus_cb), - editor); g_signal_connect (G_OBJECT (bm_view), "show_popup", G_CALLBACK (ephy_bookmarks_editor_show_popup_cb), -- cgit v1.2.3