[gnome-documents/wip/rishi/split-view: 3/16] Merge CollectionManager into DocumentManager
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/rishi/split-view: 3/16] Merge CollectionManager into DocumentManager
- Date: Mon, 9 Feb 2015 18:08:44 +0000 (UTC)
commit 3ddfac17de3c5301b78bbbdf7a879c38f5e25889
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Sep 24 17:10:48 2014 +0200
Merge CollectionManager into DocumentManager
https://bugzilla.gnome.org/show_bug.cgi?id=686461
src/application.js | 4 +-
src/documents.js | 111 ++++++++++++++++++++++++++++++++++++--------
src/embed.js | 7 +--
src/mainToolbar.js | 8 ++--
src/mainWindow.js | 2 +-
src/query.js | 2 +-
src/search.js | 3 +-
src/searchbar.js | 4 +-
src/selections.js | 14 +++---
src/shellSearchProvider.js | 2 +-
src/trackerController.js | 2 +-
11 files changed, 113 insertions(+), 46 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 0c86d93..d400a8d 100644
--- a/src/application.js
+++ b/src/application.js
@@ -73,7 +73,6 @@ let settings = null;
// used by the application, but not by the search provider
let changeMonitor = null;
-let collectionManager = null;
let cssProvider = null;
let documentManager = null;
let modeController = null;
@@ -476,13 +475,12 @@ const Application = new Lang.Class({
}
connectionQueue = new TrackerController.TrackerConnectionQueue();
+ changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
// now init application components
Search.initSearch(imports.application);
Search.initSearch(imports.shellSearchProvider);
- changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
- documentManager = new Documents.DocumentManager();
modeController = new WindowMode.ModeController();
trackerController = new TrackerController.TrackerController();
selectionController = new Selections.SelectionController();
diff --git a/src/documents.js b/src/documents.js
index c562d14..4d39b79 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -1097,6 +1097,9 @@ const DocumentManager = new Lang.Class({
this._activeDocModelIds = [];
this._loaderCancellable = null;
+ this._activeCollection = null;
+ this._collections = {};
+
// a stack containing the collections which were used to
// navigate to the active document or collection
this._collectionPath = [];
@@ -1122,9 +1125,6 @@ const DocumentManager = new Lang.Class({
if (doc) {
doc.destroy();
this.removeItemById(changeEvent.urn);
-
- if (doc.collection)
- Application.collectionManager.removeItemById(changeEvent.urn);
}
}
}
@@ -1181,14 +1181,27 @@ const DocumentManager = new Lang.Class({
} else {
doc = this.createDocumentFromCursor(cursor);
this.addItem(doc);
- if (doc.collection)
- Application.collectionManager.addItem(doc);
}
return doc;
},
+ addItem: function(doc) {
+ if (doc.collection) {
+ let oldCollection = this._collections[doc.id];
+ if (oldCollection)
+ this.removeItem(oldCollection);
+
+ this._collections[doc.id] = doc;
+ }
+
+ this.parent(doc);
+ },
+
clear: function() {
+ this._collections = {};
+ this._activeCollection = null;
+
let items = this.getItems();
for (let idx in items) {
items[idx].destroy();
@@ -1197,6 +1210,23 @@ const DocumentManager = new Lang.Class({
this.parent();
},
+ getActiveCollection: function() {
+ return this._activeCollection;
+ },
+
+ getCollections: function() {
+ return this._collections;
+ },
+
+ getWhere: function() {
+ let retval = '';
+
+ if (this._activeCollection)
+ retval = this._activeCollection.getWhere();
+
+ return retval;
+ },
+
_humanizeError: function(error) {
let message = error.message;
if (error.domain == GData.ServiceError) {
@@ -1272,33 +1302,74 @@ const DocumentManager = new Lang.Class({
this.emit('load-started', doc);
},
+ removeItemById: function(id) {
+ if (this._collections[id]) {
+ delete this._collections[id];
+ }
+
+ this.parent(id);
+ },
+
setActiveItem: function(doc) {
- if (!this.parent(doc))
- return;
+ let activeCollectionChanged = false;
+ let activeDoc = this.getActiveItem();
+ let retval = false;
+ let startLoading = false;
+
+ // Passing null is a way to go back to the current collection or
+ // overview from the preview. However, you can't do that when you
+ // are looking at a collection. Use activatePreviousCollection for
+ // unwinding the collection stack.
+ if (!doc) {
+ if (activeDoc != this._activeCollection)
+ doc = this._activeCollection;
+ else
+ return false;
+ }
// cleanup any state we have for previously loaded model
this._clearActiveDocModel();
- if (!doc)
- return;
-
- if (doc.collection) {
- this._collectionPath.push(Application.collectionManager.getActiveItem());
- Application.collectionManager.setActiveItem(doc);
- return;
+ // If doc is null then we are going back to the overview from
+ // the preview.
+ if (doc) {
+ if (doc.collection) {
+ // If doc is the active collection then we are going back to the
+ // collection from the preview.
+ if (doc != this._activeCollection) {
+ this._collectionPath.push(this._activeCollection);
+ this._activeCollection = doc;
+ activeCollectionChanged = true;
+ }
+ } else {
+ startLoading = true;
+ }
}
- let recentManager = Gtk.RecentManager.get_default();
- recentManager.add_item(doc.uri);
+ retval = this.parent(doc);
- this._loaderCancellable = new Gio.Cancellable();
- doc.load(null, this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
- this.emit('load-started', doc);
+ if (retval && activeCollectionChanged)
+ this.emit('active-collection-changed', this._activeCollection);
+
+ if (retval && startLoading) {
+ let recentManager = Gtk.RecentManager.get_default();
+ recentManager.add_item(doc.uri);
+
+ this._loaderCancellable = new Gio.Cancellable();
+ doc.load(null, this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
+ this.emit('load-started', doc);
+ }
+
+ return retval;
},
activatePreviousCollection: function() {
this._clearActiveDocModel();
- Application.collectionManager.setActiveItem(this._collectionPath.pop());
+
+ let collection = this._collectionPath.pop();
+ this._activeCollection = collection;
+ Manager.BaseManager.prototype.setActiveItem.call(this, collection);
+ this.emit('active-collection-changed', this._activeCollection);
},
_clearActiveDocModel: function() {
diff --git a/src/embed.js b/src/embed.js
index b14b64c..0b6546e 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -374,11 +374,8 @@ const Embed = new Lang.Class({
},
_onActiveItemChanged: function(manager, doc) {
- if (doc) {
- let collection = Application.collectionManager.getItemById(doc.id);
- if (!collection)
- return;
- }
+ if (doc && !doc.collection)
+ return;
Application.modeController.setWindowMode(WindowMode.WindowMode.OVERVIEW);
},
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 90ea778..836913b 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -154,7 +154,7 @@ const OverviewToolbar = new Lang.Class({
_setToolbarTitle: function() {
let selectionMode = Application.selectionController.getSelectionMode();
- let activeCollection = Application.collectionManager.getActiveItem();
+ let activeCollection = Application.documentManager.getActiveCollection();
let primary = null;
if (!selectionMode) {
@@ -213,7 +213,7 @@ const OverviewToolbar = new Lang.Class({
},
_checkCollectionBackButton: function() {
- let item = Application.collectionManager.getActiveItem();
+ let item = Application.documentManager.getActiveCollection();
if (item && !this._collBackButton) {
this._collBackButton = this.addBackButton();
@@ -251,7 +251,7 @@ const OverviewToolbar = new Lang.Class({
// connect to active collection changes while in this mode
this._collectionId =
- Application.collectionManager.connect('active-changed',
+ Application.documentManager.connect('active-collection-changed',
Lang.bind(this, this._onActiveCollectionChanged));
},
@@ -263,7 +263,7 @@ const OverviewToolbar = new Lang.Class({
this.toolbar.set_custom_title(null);
if (this._collectionId != 0) {
- Application.collectionManager.disconnect(this._collectionId);
+ Application.documentManager.disconnect(this._collectionId);
this._collectionId = 0;
}
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 244d3e2..2a3798c 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -149,7 +149,7 @@ const MainWindow = new Lang.Class({
_goBack: function() {
let windowMode = Application.modeController.getWindowMode();
- let activeCollection = Application.collectionManager.getActiveItem();
+ let activeCollection = Application.documentManager.getActiveCollection();
let handled = true;
if (windowMode == WindowMode.WindowMode.PREVIEW ||
diff --git a/src/query.js b/src/query.js
index 0566fce..467a556 100644
--- a/src/query.js
+++ b/src/query.js
@@ -100,7 +100,7 @@ const QueryBuilder = new Lang.Class({
if ((flags & QueryFlags.UNFILTERED) == 0) {
if (global)
part += this._context.searchCategoryManager.getWhere() +
- this._context.collectionManager.getWhere();
+ this._context.documentManager.getWhere();
part += this._buildFilterString(currentType);
}
diff --git a/src/search.js b/src/search.js
index 8e8751c..256d061 100644
--- a/src/search.js
+++ b/src/search.js
@@ -20,6 +20,7 @@
*/
const Application = imports.application;
+const Documents = imports.documents;
const Manager = imports.manager;
const Query = imports.query;
@@ -34,7 +35,7 @@ const _ = imports.gettext.gettext;
const C_ = imports.gettext.pgettext;
function initSearch(context) {
- context.collectionManager = new Manager.BaseManager(context);
+ context.documentManager = new Documents.DocumentManager();
context.sourceManager = new SourceManager(context);
context.searchCategoryManager = new SearchCategoryManager(context);
context.searchMatchManager = new SearchMatchManager(context);
diff --git a/src/searchbar.js b/src/searchbar.js
index 24e3f59..9644071 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -166,7 +166,7 @@ const OverviewSearchbar = new Lang.Class({
Lang.bind(this, this._onActiveTypeChanged));
this._searchMatchId = Application.searchMatchManager.connect('active-changed',
Lang.bind(this, this._onActiveMatchChanged));
- this._collectionId = Application.collectionManager.connect('active-changed',
+ this._collectionId = Application.documentManager.connect('active-collection-changed',
Lang.bind(this, this._onActiveCollectionChanged));
this._onActiveSourceChanged();
@@ -312,7 +312,7 @@ const OverviewSearchbar = new Lang.Class({
}
if (this._collectionId != 0) {
- Application.collectionManager.disconnect(this._collectionId);
+ Application.documentManager.disconnect(this._collectionId);
this._collectionId = 0;
}
diff --git a/src/selections.js b/src/selections.js
index cd2485c..3b06802 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -138,7 +138,7 @@ const FetchCollectionStateForSelectionJob = new Lang.Class({
_emitCallback: function() {
let collectionState = {};
- let collections = Application.collectionManager.getItems();
+ let collections = Application.documentManager.getCollections();
// for all the registered collections...
for (let collIdx in collections) {
@@ -325,9 +325,9 @@ const OrganizeCollectionModel = new Lang.Class({
GObject.TYPE_STRING,
GObject.TYPE_INT ]);
- this._collAddedId = Application.collectionManager.connect('item-added',
+ this._collAddedId = Application.documentManager.connect('item-added',
Lang.bind(this, this._onCollectionAdded));
- this._collRemovedId = Application.collectionManager.connect('item-removed',
+ this._collRemovedId = Application.documentManager.connect('item-removed',
Lang.bind(this, this._onCollectionRemoved));
let iter;
@@ -372,7 +372,7 @@ const OrganizeCollectionModel = new Lang.Class({
_onFetchCollectionStateForSelection: function(collectionState) {
for (let idx in collectionState) {
- let item = Application.collectionManager.getItemById(idx);
+ let item = Application.documentManager.getItemById(idx);
if ((collectionState[item.id] & OrganizeCollectionState.HIDDEN) != 0)
continue;
@@ -410,12 +410,12 @@ const OrganizeCollectionModel = new Lang.Class({
destroy: function() {
if (this._collAddedId != 0) {
- Application.collectionManager.disconnect(this._collAddedId);
+ Application.documentManager.disconnect(this._collAddedId);
this._collAddedId = 0;
}
if (this._collRemovedId != 0) {
- Application.collectionManager.disconnect(this._collRemovedId);
+ Application.documentManager.disconnect(this._collRemovedId);
this._collRemovedId = 0;
}
}
@@ -610,7 +610,7 @@ const OrganizeCollectionView = new Lang.Class({
_detailCellFunc: function(col, cell, model, iter) {
let id = model.get_value(iter, OrganizeModelColumns.ID);
- let item = Application.collectionManager.getItemById(id);
+ let item = Application.documentManager.getItemById(id);
if (item && item.identifier.indexOf(Query.LOCAL_COLLECTIONS_IDENTIFIER) == -1) {
cell.text = Application.sourceManager.getItemById(item.resourceUrn).name;
diff --git a/src/shellSearchProvider.js b/src/shellSearchProvider.js
index 8bdf211..2711714 100644
--- a/src/shellSearchProvider.js
+++ b/src/shellSearchProvider.js
@@ -38,7 +38,7 @@ const Search = imports.search;
const TrackerUtils = imports.trackerUtils;
const Utils = imports.utils;
-let collectionManager = null;
+let documentManager = null;
let offsetController = null;
let queryBuilder = null;
let searchCategoryManager = null;
diff --git a/src/trackerController.js b/src/trackerController.js
index e2107b9..d21553e 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -135,7 +135,7 @@ const TrackerController = new Lang.Class({
Application.offsetController.connect('offset-changed', Lang.bind(this, this._performCurrentQuery));
- Application.collectionManager.connect('active-changed', Lang.bind(this, this._refreshForObject));
+ Application.documentManager.connect('active-collection-changed', Lang.bind(this,
this._refreshForObject));
Application.searchController.connect('search-string-changed', Lang.bind(this,
this._refreshForObject));
Application.searchCategoryManager.connect('active-changed', Lang.bind(this, this._refreshForObject));
Application.searchTypeManager.connect('active-changed', Lang.bind(this, this._refreshForObject));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]