From a3b04be4f0788104ba7f7e12abff000f573ec439 Mon Sep 17 00:00:00 2001 From: Hans Petter Jansson Date: Wed, 17 Dec 2003 00:50:03 +0000 Subject: Use e_source_equal() instead of comparing pointers. This allows user to 2003-12-16 Hans Petter Jansson * misc/e-source-option-menu.c (select_source_foreach_menu_item): Use e_source_equal() instead of comparing pointers. This allows user to pass in a source that was obtained from somewhere else. Set the matching internal source as "selected" instead of the one passed in. (select_source): Emit signal only if we found a match. Don't ref/unref anything, since the selected source will always be from our internal list. svn path=/trunk/; revision=23954 --- widgets/ChangeLog | 10 ++++++++++ widgets/misc/e-source-option-menu.c | 22 ++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'widgets') diff --git a/widgets/ChangeLog b/widgets/ChangeLog index 0cd57d5557..0ee7c01e56 100644 --- a/widgets/ChangeLog +++ b/widgets/ChangeLog @@ -1,3 +1,13 @@ +2003-12-16 Hans Petter Jansson + + * misc/e-source-option-menu.c (select_source_foreach_menu_item): + Use e_source_equal() instead of comparing pointers. This allows user + to pass in a source that was obtained from somewhere else. Set the + matching internal source as "selected" instead of the one passed in. + (select_source): Emit signal only if we found a match. Don't ref/unref + anything, since the selected source will always be from our internal + list. + 2003-12-10 Not Zed * menus/gal-view-menus.c (remove_instance): NULL out diff --git a/widgets/misc/e-source-option-menu.c b/widgets/misc/e-source-option-menu.c index f2b5b4b5cc..fd1fd3de1f 100644 --- a/widgets/misc/e-source-option-menu.c +++ b/widgets/misc/e-source-option-menu.c @@ -59,6 +59,8 @@ static uint signals[NUM_SIGNALS] = { 0 }; typedef struct { ESourceOptionMenu *option_menu; + ESource *source; + ESource *found_source; int i; } ForeachMenuItemData; @@ -68,8 +70,13 @@ select_source_foreach_menu_item (GtkWidget *menu_item, { ESource *source = gtk_object_get_data (GTK_OBJECT (menu_item), MENU_ITEM_SOURCE_DATA_ID); - if (source == data->option_menu->priv->selected_source) + if (data->found_source) + return; + + if (source && e_source_equal (source, data->source)) { + data->found_source = source; gtk_option_menu_set_history (GTK_OPTION_MENU (data->option_menu), data->i); + } data->i ++; } @@ -80,20 +87,19 @@ select_source (ESourceOptionMenu *menu, { ForeachMenuItemData *foreach_data; - if (menu->priv->selected_source != NULL) - g_object_unref (menu->priv->selected_source); - menu->priv->selected_source = source; - foreach_data = g_new0 (ForeachMenuItemData, 1); foreach_data->option_menu = menu; + foreach_data->source = source; gtk_container_foreach (GTK_CONTAINER (GTK_OPTION_MENU (menu)->menu), (GtkCallback) select_source_foreach_menu_item, foreach_data); - g_free (foreach_data); - g_object_ref (source); + if (foreach_data->found_source) { + menu->priv->selected_source = foreach_data->found_source; + g_signal_emit (menu, signals[SOURCE_SELECTED], 0, foreach_data->found_source); + } - g_signal_emit (menu, signals[SOURCE_SELECTED], 0, source); + g_free (foreach_data); } -- cgit v1.2.3