[blam/gtk3] ItemList: really sort



commit d5e007b3ce440114f4b678e79b08061a7fa4818b
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Sun Oct 13 14:35:07 2013 +0200

    ItemList: really sort

 src/ItemList.cs |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/src/ItemList.cs b/src/ItemList.cs
index 464809e..4ecf1f9 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -74,6 +74,16 @@ namespace Blam
 
                        this.Model = new ListStore (typeof(Imendio.Blam.Item));
                        this.HeadersVisible = false;
+
+                       (Model as ListStore).DefaultSortFunc = CompareFunc;
+                       Observable.FromEventPattern<GLib.ChangedArgs>(Conf.Preferences, "Changed")
+                               .Where(x => x.EventArgs.Key == "reverse-entries")
+                               .Select(x => Conf.Preferences.GetBoolean("reverse-entries"))
+                               .StartWith(Conf.Preferences.GetBoolean("reverse-entries"))
+                               .Subscribe(v => {
+                                       var sorting = v ? SortType.Descending : SortType.Ascending;
+                                       (Model as ListStore).SetSortColumnId(-1, sorting);
+                               });
                }
 
                void CellDataFunc (TreeViewColumn col, CellRenderer _cell, ITreeModel model, TreeIter iter)
@@ -89,6 +99,17 @@ namespace Blam
                        cell.Ellipsize = Pango.EllipsizeMode.End;
                }
 
+               int CompareFunc(ITreeModel model, TreeIter a, TreeIter b)
+               {
+                       Item ia = Model.GetValue(a, 0) as Item;
+                       Item ib = Model.GetValue(b, 0) as Item;
+
+                       DateTimeOffset maxa = ia.PublishDate.CompareTo(ia.LastUpdatedTime) > 0 ? 
ia.PublishDate : ia.LastUpdatedTime;
+                       DateTimeOffset maxb = ib.PublishDate.CompareTo(ib.LastUpdatedTime) > 0 ? 
ib.PublishDate : ib.LastUpdatedTime;
+
+                       return maxa.CompareTo(maxb);
+               }
+
                void UpdateList()
                {
                        var list = Model as ListStore;


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