[banshee] ThickClient: extract SwapView() method in CompositeTrackSourceContents



commit 7abadd673e28857fd337881c2a58700cf811f58a
Author: Tomasz Maczynski <tmtimon gmail com>
Date:   Tue Aug 13 21:33:10 2013 +0200

    ThickClient: extract SwapView() method in CompositeTrackSourceContents
    
    CompositeTrackSourceContents.OnArtistFilterChanged contains some
    code that can be abstracted away into a new private method called
    SwapView<T>(new,old) which is not coupled to ArtistListView class.
    In the very near future, by making this method public, we would
    open up enough API in this class so extensions can swap views at
    will in this container.
    
    Inspired by a suggestion from Olivier Dufour <olivier duff gmail com>
    while reviewing GSoC patches in the -devel mailing list.
    
    No change of behaviour in this commit.
    
    Signed-off-by: Andrés G. Aragoneses <knocte gmail com>

 .../CompositeTrackSourceContents.cs                |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CompositeTrackSourceContents.cs 
b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CompositeTrackSourceContents.cs
index 492a546..a0f8d96 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CompositeTrackSourceContents.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CompositeTrackSourceContents.cs
@@ -183,9 +183,15 @@ namespace Banshee.Sources.Gui
 
         private void OnArtistFilterChanged (object o, ChangedArgs args)
         {
-            Widget new_artist_view = args.Current.Value == 0 ? artist_view : albumartist_view;
-            Widget old_artist_view = args.Current.Value == 1 ? artist_view : albumartist_view;
+            var new_artist_view = args.Current.Value == 0 ? artist_view : albumartist_view;
+            var old_artist_view = args.Current.Value == 1 ? artist_view : albumartist_view;
 
+            SwapView (old_artist_view, new_artist_view);
+            ArtistFilterType.Set (args.Current.Value == 1 ? "albumartist" : "artist");
+        }
+
+        private void SwapView<T> (ListView<T> oldView, ListView<T> newView)
+        {
             List<ScrolledWindow> new_filter_list = new List<ScrolledWindow> ();
             List<ScrolledWindow> old_filter_list = new List<ScrolledWindow> (filter_scrolled_windows);
 
@@ -193,15 +199,15 @@ namespace Banshee.Sources.Gui
             {
                 bool contains = false;
                 foreach (Widget child in fw.AllChildren) {
-                    if (child == old_artist_view) {
+                    if (child == oldView) {
                         contains = true;
                     }
                 }
 
                 if (contains) {
-                    Widget view_widget = (Widget)new_artist_view;
+                    Widget view_widget = (Widget)newView;
                     if (view_widget.Parent == null) {
-                        SetupFilterView (new_artist_view as ArtistListView);
+                        SetupFilterView (newView);
                     }
 
                     ScrolledWindow win = (ScrolledWindow)view_widget.Parent;
@@ -217,8 +223,6 @@ namespace Banshee.Sources.Gui
             ClearFilterSelections ();
 
             Layout ();
-
-            ArtistFilterType.Set (args.Current.Value == 1 ? "albumartist" : "artist");
         }
 
         protected override void InitializeViews ()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]