Index: sources/rb-library-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-library-source.c,v
retrieving revision 1.152
diff -u -r1.152 rb-library-source.c
--- sources/rb-library-source.c	28 Feb 2006 10:31:22 -0000	1.152
+++ sources/rb-library-source.c	6 Mar 2006 00:11:17 -0000
@@ -112,6 +112,7 @@
 
 void rb_library_source_browser_views_activated_cb (GtkWidget *widget,
 						 RBLibrarySource *source);
+static GPtrArray * construct_query_without_browser (RBLibrarySource *source);
 static GPtrArray * construct_query_from_selection (RBLibrarySource *source);
 static void songs_view_drag_data_received_cb (GtkWidget *widget,
 					      GdkDragContext *dc,
@@ -623,6 +624,8 @@
 impl_search (RBSource *asource, const char *search_text)
 {
 	RBLibrarySource *source = RB_LIBRARY_SOURCE (asource);
+	RhythmDBQueryModel *query_model;
+	GPtrArray *query;  
 
 	if (search_text == NULL && source->priv->search_text == NULL)
 		return;
@@ -640,6 +643,17 @@
 	source->priv->search_text = g_strdup (search_text);
 	rb_library_source_do_query (source);
 
+	/* construct a query model based only on search text */
+	query_model = rhythmdb_query_model_new_empty (source->priv->db);
+	query = construct_query_without_browser (source); 
+	rhythmdb_do_full_query_parsed (source->priv->db, 
+				       RHYTHMDB_QUERY_RESULTS (query_model), 
+				       query); 
+	rhythmdb_query_free (query); 
+	
+	/* use query model to constrain browser */
+	rb_library_browser_set_model(source->priv->browser, query_model);   
+	
 	rb_source_notify_filter_changed (RB_SOURCE (source));
 }
 
@@ -1089,11 +1103,10 @@
 }
 
 static GPtrArray *
-construct_query_from_selection (RBLibrarySource *source)
+construct_query_without_browser (RBLibrarySource *source)
 {
 	GPtrArray *query;
 	RhythmDBEntryType entry_type;
-	GPtrArray *browser_query;
 
 	g_object_get (G_OBJECT (source), "entry-type", &entry_type, NULL);
 	query = rhythmdb_query_parse (source->priv->db,
@@ -1103,7 +1116,7 @@
 				      RHYTHMDB_QUERY_END);
 
 	/* select where type="song"
-	 */
+`	 */
 
 	if (source->priv->search_text) {
 		GPtrArray *subquery = rhythmdb_query_parse (source->priv->db,
@@ -1121,7 +1134,16 @@
 		 */
 	}
 
-	
+	return query;
+}
+
+static GPtrArray *
+construct_query_from_selection (RBLibrarySource *source)
+{
+	GPtrArray *query;
+	GPtrArray *browser_query;
+
+	query = construct_query_without_browser (source);
 	browser_query = rb_library_browser_construct_query (source->priv->browser);
 	rhythmdb_query_concatenate (query, browser_query);
 	rhythmdb_query_free (browser_query);
Index: sources/rb-auto-playlist-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-auto-playlist-source.c,v
retrieving revision 1.6
diff -u -r1.6 rb-auto-playlist-source.c
--- sources/rb-auto-playlist-source.c	28 Feb 2006 09:45:13 -0000	1.6
+++ sources/rb-auto-playlist-source.c	6 Mar 2006 00:11:17 -0000
@@ -45,6 +45,8 @@
 static void impl_search (RBSource *asource, const char *search_text);
 static void impl_reset_filters (RBSource *asource);
 static void impl_browser_toggled (RBSource *source, gboolean enabled);
+static GPtrArray * construct_query_without_browser (RBAutoPlaylistSource *source);
+static GPtrArray * construct_query_from_selection (RBAutoPlaylistSource *source);
 
 /* playlist methods */
 static void impl_save_contents_to_xml (RBPlaylistSource *source,
@@ -283,6 +285,10 @@
 impl_search (RBSource *source, const char *search_text)
 {
 	RBAutoPlaylistSourcePrivate *priv = RB_AUTO_PLAYLIST_SOURCE_GET_PRIVATE (source);
+	RhythmDB *db = rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (source));
+	RhythmDBQueryModel *query_model;
+	GPtrArray *query;  
+
 
 	if (search_text == NULL && priv->search_text == NULL)
 		return;
@@ -299,6 +305,17 @@
 	priv->search_text = g_strdup (search_text);
 	rb_auto_playlist_source_do_query (RB_AUTO_PLAYLIST_SOURCE (source));
 
+	/* construct a query model based only on search text */
+	query_model = rhythmdb_query_model_new_empty (db);
+	query = construct_query_without_browser (RB_AUTO_PLAYLIST_SOURCE (source)); 
+	rhythmdb_do_full_query_parsed (db,
+				       RHYTHMDB_QUERY_RESULTS (query_model), 
+				       query); 
+	rhythmdb_query_free (query); 
+	
+	/* use query model to constrain browser */
+	rb_library_browser_set_model(priv->browser, query_model);   
+
 	rb_source_notify_filter_changed (source);
 }
 
@@ -438,12 +455,11 @@
 }
 
 static GPtrArray *
-construct_query_from_selection (RBAutoPlaylistSource *source)
+construct_query_without_browser (RBAutoPlaylistSource *source)
 {
 	RBAutoPlaylistSourcePrivate *priv = RB_AUTO_PLAYLIST_SOURCE_GET_PRIVATE (source);
 	RhythmDB *db = rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (source));
 	GPtrArray *query = rhythmdb_query_copy (priv->query);
-	GPtrArray *browser_query;
 
 	if (priv->search_text) {
 		rhythmdb_query_append (db,
@@ -454,6 +470,17 @@
 				       RHYTHMDB_QUERY_END);
 	}
 
+	return query;
+}
+
+static GPtrArray *
+construct_query_from_selection (RBAutoPlaylistSource *source)
+{
+	RBAutoPlaylistSourcePrivate *priv = RB_AUTO_PLAYLIST_SOURCE_GET_PRIVATE (source);
+	GPtrArray *query = rhythmdb_query_copy (priv->query);
+	GPtrArray *browser_query;
+
+	query = construct_query_without_browser (source);
 	browser_query = rb_library_browser_construct_query (priv->browser);
 	rhythmdb_query_concatenate (query, browser_query);
 	rhythmdb_query_free (browser_query);
Index: sources/rb-static-playlist-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-static-playlist-source.c,v
retrieving revision 1.12
diff -u -r1.12 rb-static-playlist-source.c
--- sources/rb-static-playlist-source.c	28 Feb 2006 11:45:11 -0000	1.12
+++ sources/rb-static-playlist-source.c	6 Mar 2006 00:11:17 -0000
@@ -48,6 +48,7 @@
 static void impl_browser_toggled (RBSource *source, gboolean enabled);
 static void impl_reset_filters (RBSource *asource);
 static gboolean impl_receive_drag (RBSource *source, GtkSelectionData *data);
+static GPtrArray *construct_query_from_selection (RBStaticPlaylistSource *source);
 
 /* playlist methods */
 static void impl_save_contents_to_xml (RBPlaylistSource *source,
@@ -304,6 +305,10 @@
 impl_search (RBSource *source, const char *search_text)
 {
 	RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source);
+	RBPlaylistSource *psource = RB_PLAYLIST_SOURCE (source);
+	RhythmDB *db = rb_playlist_source_get_db (psource);
+	RhythmDBQueryModel *query_model; 
+	GPtrArray *query;  
 
 	if (search_text == NULL && priv->search_text == NULL)
 		return;
@@ -320,6 +325,21 @@
 	priv->search_text = g_strdup (search_text);
 	rb_static_playlist_source_do_query (RB_STATIC_PLAYLIST_SOURCE (source));
 
+	/* construct a query model based only on search text */
+	query_model = rhythmdb_query_model_new_empty (db);
+	g_object_set (G_OBJECT (query_model), "base-model", priv->base_model, NULL);
+	query = construct_query_from_selection (RB_STATIC_PLAYLIST_SOURCE (source));
+
+	g_object_set (G_OBJECT (query_model), "query", query, NULL);
+	rhythmdb_do_full_query_parsed (db,
+				       RHYTHMDB_QUERY_RESULTS (query_model), 
+				       query);  
+	rhythmdb_query_model_reapply_query (query_model, TRUE);  
+	rhythmdb_query_free (query);
+
+	/* use query model to constrain browser */
+	rb_library_browser_set_model(priv->browser, query_model); 
+
 	rb_source_notify_filter_changed (source);
 }
 
@@ -347,13 +367,35 @@
 		gtk_widget_hide (GTK_WIDGET (priv->browser));
 }
 
+static GPtrArray *
+construct_query_from_selection (RBStaticPlaylistSource *source)
+{
+	RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source);
+	RBPlaylistSource *psource = RB_PLAYLIST_SOURCE (source);
+	RhythmDB *db = rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (psource));
+	GPtrArray *query = NULL;
+
+	query = g_ptr_array_new();
+
+	if (priv->search_text) {
+		rhythmdb_query_append (db,
+				       query,
+				       RHYTHMDB_QUERY_PROP_LIKE,
+				       RHYTHMDB_PROP_SEARCH_MATCH,
+				       priv->search_text,
+				       RHYTHMDB_QUERY_END);
+	}
+
+	return query;
+}
+
 static void
 rb_static_playlist_source_do_query (RBStaticPlaylistSource *source)
 {
 	RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source);
 	RBPlaylistSource *psource = RB_PLAYLIST_SOURCE (source);
 	RhythmDB *db = rb_playlist_source_get_db (psource);
-	GPtrArray *query = NULL;
+	GPtrArray *query;
 	GPtrArray *browser_query;
 	
 	if (priv->filter_model)
@@ -361,14 +403,7 @@
 	priv->filter_model = rhythmdb_query_model_new_empty (db);
 	g_object_set (G_OBJECT (priv->filter_model), "base-model", priv->base_model, NULL);
 
-	query = g_ptr_array_new();
-
-	if (priv->search_text) {
-		rhythmdb_query_append (db,
-				       query,
-				       RHYTHMDB_QUERY_PROP_LIKE, RHYTHMDB_PROP_SEARCH_MATCH, priv->search_text,
-				       RHYTHMDB_QUERY_END);
-	}
+	query = construct_query_from_selection (source);
 
 	browser_query = rb_library_browser_construct_query (priv->browser);
 	rhythmdb_query_concatenate (query, browser_query);
Index: widgets/rb-library-browser.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-library-browser.c,v
retrieving revision 1.4
diff -u -r1.4 rb-library-browser.c
--- widgets/rb-library-browser.c	2 Mar 2006 06:50:08 -0000	1.4
+++ widgets/rb-library-browser.c	6 Mar 2006 00:11:17 -0000
@@ -500,6 +500,12 @@
 	RBLibraryBrowserPrivate *priv = RB_LIBRARY_BROWSER_GET_PRIVATE (widget);
 	RBPropertyView *view;
 	RhythmDBPropertyModel *prop_model;
+	GList *saved_selections;  
+
+	/* save the current selections */
+	saved_selections = g_hash_table_lookup (priv->selections,
+						(gpointer)browser_properties[0].type);
+	saved_selections = rb_string_list_copy (saved_selections);   
 	
 	if (priv->model)
 		g_object_unref (G_OBJECT (priv->model));
@@ -512,4 +518,9 @@
 	g_object_set (G_OBJECT (prop_model), "query-model", priv->model, NULL);
 
 	rebuild_child_model (widget, 0);
+
+	/* restore the old selection */
+	rb_property_view_set_selection (view, saved_selections);
+	rb_list_deep_free (saved_selections);  
+
 }
