[longomatch] Fix plays treeview sort function



commit 22b89ced0ce2af2d2773e3a057cae81fe4094ec1
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Jan 6 23:00:17 2010 +0100

    Fix plays treeview sort function

 LongoMatch/Gui/TreeView/PlaysTreeView.cs |   34 +++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/LongoMatch/Gui/TreeView/PlaysTreeView.cs b/LongoMatch/Gui/TreeView/PlaysTreeView.cs
index 3bf98e3..323ed78 100644
--- a/LongoMatch/Gui/TreeView/PlaysTreeView.cs
+++ b/LongoMatch/Gui/TreeView/PlaysTreeView.cs
@@ -184,21 +184,35 @@ namespace LongoMatch.Gui.Component
 		}
 		
 		private int SortFunction(TreeModel model, TreeIter a, TreeIter b){
-			TreeIter iter;
+			TreeStore store;
+			TimeNode tna, tnb;
+			TreeIter parent;
+			int depth;
 			SectionsTimeNode category;
-			TimeNode tna;
-			TimeNode tnb;
 			
 			if (model == null)
-				return 0;
+				return 0;	
 			
-			// Don't sort categories
-			if (!model.GetPath(a).ToString().Contains(":"))
+			store = model as TreeStore;
+			
+			// Retrieve the iter parent and its depth
+			// When a new play is inserted, one of the iters is not a valid
+			// in the model. Get the values from the valid one
+			if (store.IterIsValid(a)){
+				store.IterParent(out parent, a);
+				depth = store.IterDepth(a);
+			}
+			else{
+				store.IterParent(out parent, b);
+				depth = store.IterDepth(b);
+			}		
+			
+			// Dont't store categories
+			if (depth == 0)
 				return int.Parse(model.GetPath(a).ToString()) 
-					- int.Parse(model.GetPath(b).ToString());			
-	
-			model.IterParent(out iter, a);
-			category = model.GetValue(iter,0) as SectionsTimeNode;
+					- int.Parse(model.GetPath(b).ToString());
+			
+			category = model.GetValue(parent,0) as SectionsTimeNode;
 			tna = model.GetValue (a, 0)as TimeNode;
 			tnb = model.GetValue (b, 0) as TimeNode;
 			



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