[gnome-documents/gnome-3-4] selections: use a tree path when applying current collection state



commit 4730507d244303945d877d5435c9393450203e89
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Apr 18 18:13:10 2012 -0400

    selections: use a tree path when applying current collection state
    
    Return a GtkTreePath when iterating the model, since the iter might
    become invalid at the time we eventually call gtk_list_store_set().

 src/selections.js |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/src/selections.js b/src/selections.js
index 7aed96c..5ee96ec 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -344,21 +344,24 @@ OrganizeCollectionModel.prototype = {
     },
 
     _findCollectionIter: function(item) {
-        let retval = null;
+        let collPath = null;
 
         this.model.foreach(Lang.bind(this,
             function(model, path, iter) {
                 let id = model.get_value(iter, OrganizeModelColumns.ID);
 
                 if (item.id == id) {
-                    retval = iter;
+                    collPath = path.copy();
                     return true;
                 }
 
                 return false;
             }));
 
-        return retval;
+        if (collPath)
+            return this.model.get_iter(collPath)[1];
+
+        return null;
     },
 
     _onFetchCollectionStateForSelection: function(collectionState) {
@@ -366,18 +369,17 @@ OrganizeCollectionModel.prototype = {
 
         for (idx in collectionState) {
             let item = Global.collectionManager.getItemById(idx);
-            let iter = null;
 
             if ((collectionState[item.id] & OrganizeCollectionState.HIDDEN) != 0)
                 continue;
 
-            iter = this._findCollectionIter(item);
+            let iter = this._findCollectionIter(item);
+
             if (!iter)
                 iter = this.model.append();
 
-            if (iter)
-                Gd.organize_store_set(this.model, iter,
-                                      item.id, item.name, collectionState[item.id]);
+            Gd.organize_store_set(this.model, iter,
+                                  item.id, item.name, collectionState[item.id]);
         }
     },
 



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