[gnome-documents/wip/rishi/split-view: 2/18] Don't clear DocumentManager on every TrackerController refresh



commit b76b087ad8c47c7980705950808cda1d14f7407b
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Sep 25 14:40:36 2014 +0200

    Don't clear DocumentManager on every TrackerController refresh
    
    We were clearing DocumentManager on every refresh of the
    TrackerController. This will be problematic when we implement the new
    split view designs because DocumentManager will have items spanning
    across multiple views. Refreshing the TrackerController for one view
    should not clear DocumentManager because it might have items for some
    other view.
    
    Instead, we can add some filtering to ViewModel so that it only picks
    those items that are relevant to the view for which it is a model.
    
    Since we are not clearing DocumentManager on every refresh, we will
    find some items that are already part of the manager. Avoid emitting
    an extra "object-removed" / "object-added" pair in these cases.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686461

 src/documents.js         |   14 ++++++++++----
 src/trackerController.js |    2 --
 src/view.js              |   11 ++++++++---
 3 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index fd00333..c562d14 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -1173,11 +1173,17 @@ const DocumentManager = new Lang.Class({
     },
 
     addDocumentFromCursor: function(cursor) {
-        let doc = this.createDocumentFromCursor(cursor);
-        this.addItem(doc);
+        let id = cursor.get_string(Query.QueryColumns.URN)[0];
+        let doc = this.getItemById(id);
 
-        if (doc.collection)
-            Application.collectionManager.addItem(doc);
+        if (doc) {
+            this.emit('item-added', doc);
+        } else {
+            doc = this.createDocumentFromCursor(cursor);
+            this.addItem(doc);
+            if (doc.collection)
+                Application.collectionManager.addItem(doc);
+        }
 
         return doc;
     },
diff --git a/src/trackerController.js b/src/trackerController.js
index 2bf227b..e2107b9 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -242,8 +242,6 @@ const TrackerController = new Lang.Class({
         }
 
         this._setQueryStatus(true);
-        Application.documentManager.clear();
-
         this._performCurrentQuery();
     },
 
diff --git a/src/view.js b/src/view.js
index 0b3002c..c18dfe3 100644
--- a/src/view.js
+++ b/src/view.js
@@ -57,8 +57,13 @@ const ViewModel = new Lang.Class({
             Lang.bind(this, this._onItemAdded));
         Application.documentManager.connect('item-removed',
             Lang.bind(this, this._onItemRemoved));
-        Application.documentManager.connect('clear',
-            Lang.bind(this, this._onClear));
+
+        Application.trackerController.connect('query-status-changed', Lang.bind(this,
+            function(o, status) {
+                if (!status)
+                    return;
+                this._clear();
+            }));
 
         // populate with the intial items
         let items = Application.documentManager.getItems();
@@ -67,7 +72,7 @@ const ViewModel = new Lang.Class({
         }
     },
 
-    _onClear: function() {
+    _clear: function() {
         this.model.clear();
     },
 


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