[gnome-documents] all: track item-added and item-removed from SourceManager
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] all: track item-added and item-removed from SourceManager
- Date: Wed, 19 Oct 2011 23:04:39 +0000 (UTC)
commit 18edfc34996440f15129975a29b87b23274e05c8
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Oct 18 18:08:07 2011 -0400
all: track item-added and item-removed from SourceManager
And selectively requery only if the item added or removed is interesting
(part of the current query).
src/collections.js | 16 ++++++++++++++++
src/trackerController.js | 17 +++++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/src/collections.js b/src/collections.js
index 2356dcb..d60cc36 100644
--- a/src/collections.js
+++ b/src/collections.js
@@ -69,12 +69,28 @@ CollectionManager.prototype = {
// so refresh the list when the active source changes.
Global.sourceManager.connect('active-changed',
Lang.bind(this, this._refreshCollections));
+ // when a source is removed or added, we might need to refresh
+ // the list of collections
+ Global.sourceManager.connect('item-added',
+ Lang.bind(this, this._onSourceAddedRemoved));
+ Global.sourceManager.connect('item-removed',
+ Lang.bind(this, this._onSourceAddedRemoved));
this._refreshCollections();
// TODO: keep track changes from the tracker store
},
+ _onSourceAddedRemoved: function(manager, item) {
+ // When a source is added or removed, refresh the model only if
+ // the current source is All.
+ // If it was the current source to be removed, we will get an
+ // 'active-changed' signal, so avoid refreshing twice
+ if (this._currentQuery.activeSource &&
+ this._currentQuery.activeSource.id == 'all')
+ this._refreshCollections();
+ },
+
_refreshCollections: function() {
this._currentQuery = Global.queryBuilder.buildCollectionsQuery();
Global.connection.query_async(this._currentQuery.sparql, null, Lang.bind(this,
diff --git a/src/trackerController.js b/src/trackerController.js
index f92cc32..bd6bf36 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -44,10 +44,9 @@ TrackerController.prototype = {
this._refreshMinerNow();
this._sourceManager = Global.sourceManager;
- this._sourceManager.connect('item-added',
- Lang.bind(this, this._refresh));
- this._sourceManager.connect('active-changed',
- Lang.bind(this, this._refresh));
+ this._sourceManager.connect('item-added', Lang.bind(this, this._onSourceAddedRemoved));
+ this._sourceManager.connect('item-removed', Lang.bind(this, this._onSourceAddedRemoved));
+ this._sourceManager.connect('active-changed', Lang.bind(this, this._refresh));
this._offsetController = Global.offsetController;
this._offsetController.connect('offset-changed',
@@ -130,6 +129,16 @@ TrackerController.prototype = {
_onSearchFilterChanged: function() {
this._offsetController.resetOffset();
this._refresh();
+ },
+
+ _onSourceAddedRemoved: function(manager, item) {
+ // When a source is added or removed, refresh the model only if
+ // the current source is All.
+ // If it was the current source to be removed, we will get an
+ // 'active-changed' signal, so avoid refreshing twice
+ if (this._currentQuery.activeSource &&
+ this._currentQuery.activeSource.id == 'all')
+ this._refresh();
}
};
Signals.addSignalMethods(TrackerController.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]