[gnome-documents] documents: don't recreate a new GtkTreeModel when refreshing the view



commit 1ea7a92e025183e91dcd26bc7fc518ebfb34e205
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 12 17:52:50 2011 -0400

    documents: don't recreate a new GtkTreeModel when refreshing the view
    
    We can easily re-use the old GtkTreeModel and make view-switching way
    faster.

 src/documents.js |   28 ++++++++++++----------------
 src/view.js      |    3 +--
 2 files changed, 13 insertions(+), 18 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 54ae50b..8b50425 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -504,6 +504,8 @@ DocumentManager.prototype = {
         this._docs = {};
         this._activeDocument = null;
 
+        this._model = new DocumentModel();
+
         Global.changeMonitor.connect('changes-pending',
                                      Lang.bind(this, this._onChangesPending));
 
@@ -525,7 +527,7 @@ DocumentManager.prototype = {
                 let doc = this.lookupDocument(changeEvent.urn);
 
                 if (doc) {
-                    this.emit('document-removed', doc);
+                    this._model.documentRemoved(doc);
 
                     doc.destroy();
                     delete this._docs[changeEvent.urn];
@@ -577,7 +579,7 @@ DocumentManager.prototype = {
             doc = new LocalDocument(cursor);
 
         this._docs[doc.urn] = doc;
-        this.emit('document-added', doc);
+        this._model.documentAdded(doc);
     },
 
     clear: function() {
@@ -585,7 +587,7 @@ DocumentManager.prototype = {
             this._docs[idx].destroy();
         };
         this._docs = {};
-        this.emit('clear');
+        this._model.clear();
     },
 
     getDocuments: function() {
@@ -610,6 +612,10 @@ DocumentManager.prototype = {
 
     getActiveDocument: function() {
         return this._activeDocument;
+    },
+
+    getModel: function() {
+        return this._model;
     }
 };
 Signals.addSignalMethods(DocumentManager.prototype);
@@ -631,23 +637,13 @@ DocumentModel.prototype = {
         this.model = Gd.create_list_store();
         this.model.set_sort_column_id(ModelColumns.MTIME,
                                       Gtk.SortType.DESCENDING);
-
-        this._documentManager = Global.documentManager;
-
-        this._documentManager.connect('clear', Lang.bind(this, this._onManagerClear));
-        this._documentManager.connect('document-added', Lang.bind(this, this._onDocumentAdded));
-        this._documentManager.connect('document-removed', Lang.bind(this, this._onDocumentRemoved));
-
-        let documents = this._documentManager.getDocuments();
-        for (idx in this._documentManager.getDocuments())
-            this._onDocumentAdded(this._documentManager, documents[idx]);
     },
 
-    _onManagerClear: function() {
+    clear: function() {
         this.model.clear();
     },
 
-    _onDocumentAdded: function(manager, doc) {
+    documentAdded: function(doc) {
         let iter = this.model.append();
         let treePath = this.model.get_path(iter);
 
@@ -667,7 +663,7 @@ DocumentModel.prototype = {
             }));
     },
 
-    _onDocumentRemoved: function(manager, doc) {
+    documentRemoved: function(doc) {
         this.model.foreach(Lang.bind(this,
             function(model, path, iter) {
                 let urn = model.get_value(iter, ModelColumns.URN);
diff --git a/src/view.js b/src/view.js
index 28cf243..06e3449 100644
--- a/src/view.js
+++ b/src/view.js
@@ -109,8 +109,7 @@ View.prototype = {
     _init: function() {
         this._selectedURNs = null;
 
-        this._model = new Documents.DocumentModel();
-        this._treeModel = this._model.model;
+        this._treeModel = Global.documentManager.getModel().model;
         this.widget.set_model(this._treeModel);
 
         this.widget.connect('destroy', Lang.bind(this,



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