[blam] ItemList: simplify pre-selected item selection



commit f58ab068dc8b657c6fb25ae9065810c8cc228a6f
Author: Carlos MartÃn Nieto <cmn dwim me>
Date:   Wed Jan 16 01:22:45 2013 +0100

    ItemList: simplify pre-selected item selection
    
    Swap out the complex function running after a 100ms timeout for a
    straight comparison of the sorting order of the items.

 src/ItemList.cs |   49 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 33 insertions(+), 16 deletions(-)
---
diff --git a/src/ItemList.cs b/src/ItemList.cs
index 84a35b4..7335e4d 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -168,22 +168,39 @@ namespace Imendio.Blam {
 	    return false;
 	}
 
-	public void UpdateList ()
-	{
-	    ((ListStore)this.Model).Clear();
-            ItemStore store = ItemStore.GetInstance();
-	    if (this.channel == null) {
-		return;
-	    }
-            foreach(string id in channel.ItemList){
-                if(id == null){
-                    continue;
-                }
-                (Model as ListStore).AppendValues(store.Get(id));
-            }
+		public void UpdateList ()
+		{
+			if (channel == null)
+				return;
 
-	    GLib.Timeout.Add (100, new GLib.TimeoutHandler (IdleScrollCb));
-	}
+			var list = Model as ListStore;
+			var store = ItemStore.GetInstance();
+
+			list.Clear();
+			foreach(string id in channel.ItemList){
+				if (id == null)
+					continue;
+
+				list.AppendValues(store.Get(id));
+			}
+
+			// Now we have the current list of items, go to the first unread or latest
+			if (Next(true))
+				return;
+
+			TreeIter iter;
+			if (!Model.GetIterFirst(out iter))
+				return;
+
+			list.Foreach((TreeModel model, TreePath path, TreeIter i) => {
+				if (CompareFunc(Model, iter, i) < 0)
+					iter = i;
+
+				return false;
+			});
+
+			ScrollTo(iter);
+		}
 
 	public void Update (Item item)
 	{



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