[gnome-documents] tracker-controller: emit query-status-changed when querying



commit 38380aa92ef7c12b66c8d6de20e77fdece8d02a2
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Oct 31 15:33:26 2011 -0400

    tracker-controller: emit query-status-changed when querying
    
    Instead of just calling freezeSelection(). This will allow other parts
    of the UI to know when the model is refreshing and act accordingly.

 src/application.js       |    2 +-
 src/selections.js        |    9 ++----
 src/trackerController.js |   17 +++++++++-
 src/view.js              |   76 +++++++++++++++++++++++++++++++++-------------
 4 files changed, 74 insertions(+), 30 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index b5d4d6f..e22788c 100644
--- a/src/application.js
+++ b/src/application.js
@@ -144,13 +144,13 @@ Application.prototype = {
                         }
 
                         Global.sourceManager = new Sources.SourceManager();
-                        Global.selectionController = new Selections.SelectionController();
                         Global.queryBuilder = new Query.QueryBuilder();
                         Global.changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
                         Global.collectionManager = new Collections.CollectionManager();
                         Global.sideFilterController = new Filters.SideFilterController();
                         Global.documentManager = new Documents.DocumentManager();
                         Global.trackerController = new TrackerController.TrackerController();
+                        Global.selectionController = new Selections.SelectionController();
                         Global.modeController = new WindowMode.ModeController();
                         Global.focusController = new WindowMode.FocusController();
 
diff --git a/src/selections.js b/src/selections.js
index ca9cf23..0c4f1f6 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -44,7 +44,7 @@ SelectionController.prototype = {
     },
 
     setSelection: function(selection) {
-        if (this._isFreezed)
+        if (this._isFrozen)
             return;
 
         if (!selection)
@@ -60,13 +60,10 @@ SelectionController.prototype = {
     },
 
     freezeSelection: function(freeze) {
-        if (freeze == this._isFreezed)
+        if (freeze == this._isFrozen)
             return;
 
-        this._isFreezed = freeze;
-
-        if (!this._isFreezed)
-            this.emit('selection-check');
+        this._isFrozen = freeze;
     },
 
     setSelectionMode: function(setting) {
diff --git a/src/trackerController.js b/src/trackerController.js
index bd6bf36..7e2fb3d 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -38,6 +38,7 @@ function TrackerController() {
 TrackerController.prototype = {
     _init: function() {
         this._currentQuery = null;
+        this._querying = false;
 
         // startup a refresh of the gdocs cache
         this._miner = new GDataMiner.GDataMiner();
@@ -76,8 +77,20 @@ TrackerController.prototype = {
         return false;
     },
 
+    _setQueryStatus: function(status) {
+        if (this._querying == status)
+            return;
+
+        this._querying = status;
+        this.emit('query-status-changed', this._querying);
+    },
+
+    getQueryStatus: function() {
+        return this._querying;
+    },
+
     _onQueryFinished: function(exception) {
-        Global.selectionController.freezeSelection(false);
+        this._setQueryStatus(false);
 
         if (exception)
             Global.errorHandler.addQueryError(exception);
@@ -119,7 +132,7 @@ TrackerController.prototype = {
     },
 
     _refresh: function() {
-        Global.selectionController.freezeSelection(true);
+        this._setQueryStatus(true);
         Global.documentManager.clear();
         this._offsetController.resetItemCount();
 
diff --git a/src/view.js b/src/view.js
index 021faea..a5894a2 100644
--- a/src/view.js
+++ b/src/view.js
@@ -109,47 +109,81 @@ function View() {
 View.prototype = {
     _init: function() {
         this._selectedURNs = null;
-
-        // setup the model
-        this._treeModel = Global.documentManager.getModel().model;
-        this.widget.set_model(this._treeModel);
+        this._updateSelectionId = 0;
 
         // setup selections
         this.setSingleClickMode(true);
 
+        // create renderers
+        this.createRenderers();
+
+        // setup selections view => controller
         this.setSelectionMode(Gtk.SelectionMode.SINGLE);
+        this.connectToSelectionChanged(Lang.bind(this, this._onSelectionChanged));
+
+        // setup selection controller => view
         this._selectionModeId =
             Global.selectionController.connect('selection-mode-changed',
                                                Lang.bind(this, this._onSelectionModeChanged));
-        this._selectionControllerId =
-            Global.selectionController.connect('selection-check',
-                                               Lang.bind(this, this._updateSelection));
         this._selectAllId =
             Global.selectionController.connect('select-all',
                                                Lang.bind(this, this._onSelectAll));
+        this._queryId =
+            Global.trackerController.connect('query-status-changed',
+                                             Lang.bind(this, this._onQueryStatusChanged));
 
+        this.widget.connect('button-press-event',
+                            Lang.bind(this, this._onButtonPressEvent));
         this.widget.connect('destroy', Lang.bind(this,
             function() {
-                Global.selectionController.disconnect(this._selectionControllerId);
+                // save selection when the view is destroyed
+                Global.selectionController.freezeSelection(true);
+
+                if (this._updateSelectionId != 0) {
+                    Mainloop.source_remove(this._updateSelectionId);
+                    this._updateSelectionId = 0;
+                }
+
+                Global.trackerController.disconnect(this._queryId);
                 Global.selectionController.disconnect(this._selectionModeId);
                 Global.selectionController.disconnect(this._selectAllId);
             }));
-        this.widget.connect('button-press-event', Lang.bind(this, this._onButtonPressEvent));
-
-        this.createRenderers();
 
-        // HACK: give the view some time to setup the scrolled window
-        // allocation, as updateSelection() might call scrollToPath().
-        // Is there anything better we can do here?
-        Mainloop.timeout_add(100, Lang.bind(this,
-            function() {
-                this._updateSelection();
-                return false;
-            }));
+        // this will create the model if we're done querying
+        this._onQueryStatusChanged();
+        this.widget.show();
+    },
 
-        this.connectToSelectionChanged(Lang.bind(this, this._onSelectionChanged));
+    _onQueryStatusChanged: function() {
+        let status = Global.trackerController.getQueryStatus();
+
+        if (!status) {
+            // setup a model if we're not querying
+            this._treeModel = Global.documentManager.getModel().model;
+            this.widget.set_model(this._treeModel);
+
+            // unfreeze selection
+            Global.selectionController.freezeSelection(false);
+
+            // HACK: give the view some time to setup the scrolled window
+            // allocation, as updateSelection() might call scrollToPath().
+            // Is there anything better we can do here?
+            this._updateSelectionId =
+                Mainloop.timeout_add(100, Lang.bind(this,
+                    function() {
+                        this._updateSelectionId = 0;
+                        this._updateSelection();
+                        return false;
+                    }));
+        } else {
+            // save the last selection
+            Global.selectionController.freezeSelection(true);
 
-        this.widget.show();
+            // if we're querying, clear the model from the view,
+            // so that we don't uselessly refresh the rows
+            this._treeModel = null;
+            this.widget.set_model(null);
+        }
     },
 
     _updateSelection: function() {



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