[gnome-documents] documents: don't store EvDocumentModel here
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] documents: don't store EvDocumentModel here
- Date: Sun, 26 Jun 2016 02:21:43 +0000 (UTC)
commit 8e4395930af05fc9e20acf2229eacf41b6dbbb12
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Jun 26 10:09:23 2016 +0800
documents: don't store EvDocumentModel here
Instead, only store it in the view. This greatly simplifies code too.
https://bugzilla.gnome.org/show_bug.cgi?id=768047
src/documents.js | 45 ----------------------------
src/evinceview.js | 83 ++++++++++++++++++++++++++++-------------------------
2 files changed, 44 insertions(+), 84 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 3c08302..608891e 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -1194,8 +1194,6 @@ const DocumentManager = new Lang.Class({
_init: function() {
this.parent();
- this._activeDocModel = null;
- this._activeDocModelIds = [];
this._loaderCancellable = null;
this._activeCollection = null;
@@ -1395,14 +1393,6 @@ const DocumentManager = new Lang.Class({
return;
}
- // save loaded model and signal
- this._activeDocModel = docModel;
- if (this._activeDocModel)
- this._activeDocModel.set_continuous(false);
-
- // load metadata
- this._connectMetadata();
-
this.emit('load-finished', doc, docModel);
},
@@ -1501,40 +1491,5 @@ const DocumentManager = new Lang.Class({
this._loaderCancellable.cancel();
this._loaderCancellable = null;
}
-
- // clear any previously loaded document model
- if (this._activeDocModel) {
- this._activeDocModelIds.forEach(Lang.bind(this,
- function(id) {
- this._activeDocModel.disconnect(id);
- }));
-
- this.metadata = null;
- this._activeDocModel = null;
- this._activeDocModelIds = [];
- }
- },
-
- _connectMetadata: function() {
- if (!this._activeDocModel)
- return;
- let evDoc = this._activeDocModel.get_document();
- let file = Gio.File.new_for_uri(evDoc.get_uri());
- if (!GdPrivate.is_metadata_supported_for_file(file))
- return;
-
- this.metadata = new GdPrivate.Metadata({ file: file });
-
- let [res, val] = this.metadata.get_int('page');
- if (res)
- this._activeDocModel.set_page(val);
-
- // save current page in metadata
- this._activeDocModelIds.push(
- this._activeDocModel.connect('page-changed', Lang.bind(this,
- function(source, oldPage, newPage) {
- this.metadata.set_int('page', newPage);
- }))
- );
}
});
diff --git a/src/evinceview.js b/src/evinceview.js
index 5856a64..fbad10a 100644
--- a/src/evinceview.js
+++ b/src/evinceview.js
@@ -245,16 +245,43 @@ const EvinceView = new Lang.Class({
if (doc.viewType != Documents.ViewType.EV)
return;
- this.getAction('copy').enabled = false;
- this.getAction('edit-current').enabled = doc.canEdit();
- this.getAction('print-current').enabled = doc.canPrint(docModel);
+ this.controlsVisible = false;
+ this._lastSearch = '';
+ this._model = docModel;
if (Application.application.isBooks)
docModel.set_sizing_mode(EvView.SizingMode.FIT_PAGE);
else
docModel.set_sizing_mode(EvView.SizingMode.AUTOMATIC);
+
+ docModel.set_continuous(false);
docModel.set_page_layout(EvView.PageLayout.AUTOMATIC);
- this._setModel(docModel);
+ this._updateNightMode();
+
+ this._model.connect('page-changed', Lang.bind(this, this._onPageChanged));
+
+ this._metadata = this._loadMetadata();
+ if (this._metadata)
+ this._bookmarks = new GdPrivate.Bookmarks({ metadata: this._metadata });
+
+ this._onPageChanged();
+
+ this.getAction('copy').enabled = false;
+ this.getAction('edit-current').enabled = doc.canEdit();
+ this.getAction('print-current').enabled = doc.canPrint(docModel);
+ let presentCurrent = this.getAction('present-current');
+ if (presentCurrent)
+ presentCurrent.enabled = true;
+
+ let hasMultiplePages = (this.numPages > 1);
+ this.getAction('bookmark-page').enabled = hasMultiplePages && this._bookmarks;
+ this.getAction('places').enabled = hasMultiplePages;
+
+ this._evView.set_model(this._model);
+ this.navControls.setModel(this._model);
+ this._toolbar.setModel(this._model);
+
+ this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
this.grab_focus();
},
@@ -266,12 +293,14 @@ const EvinceView = new Lang.Class({
},
_onPageChanged: function() {
+ let pageNumber = this._model.page;
this._pageChanged = true;
+ if (this._metadata)
+ this._metadata.set_int('page', pageNumber);
if (!this._bookmarks)
return;
- let pageNumber = this._model.page;
let bookmark = new GdPrivate.Bookmark({ page_number: pageNumber });
let hasBookmark = (this._bookmarks.find_bookmark(bookmark) != null);
@@ -543,43 +572,19 @@ const EvinceView = new Lang.Class({
this.emitJS('search-changed', job.has_results());
},
- _setModel: function(model) {
- if (this._model == model)
- return;
-
- this.controlsVisible = false;
- this._lastSearch = '';
- this._model = model;
-
- this._evView.set_model(this._model);
- this.navControls.setModel(this._model);
- this._toolbar.setModel(this._model);
-
- if (this._model) {
- let presentCurrent = this.getAction('present-current');
- if (presentCurrent)
- presentCurrent.enabled = true;
-
- if (Application.documentManager.metadata)
- this._bookmarks = new GdPrivate.Bookmarks({ metadata: Application.documentManager.metadata
});
-
- let hasMultiplePages = (this._model.document.get_n_pages() > 1);
- this.getAction('bookmark-page').enabled = hasMultiplePages && this._bookmarks;
- this.getAction('places').enabled = hasMultiplePages;
+ _loadMetadata: function() {
+ let evDoc = this._model.get_document();
+ let file = Gio.File.new_for_uri(evDoc.get_uri());
+ if (!GdPrivate.is_metadata_supported_for_file(file))
+ return null;
- this._model.connect('page-changed', Lang.bind(this, this._onPageChanged));
- this._onPageChanged();
+ let metadata = new GdPrivate.Metadata({ file: file });
- this._updateNightMode();
+ let [res, val] = metadata.get_int('page');
+ if (res)
+ this._model.set_page(val);
- this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
- } else {
- if (this._jobFind) {
- if (!this._jobFind.is_finished())
- this._jobFind.cancel();
- this._jobFind = null;
- }
- }
+ return metadata;
},
_updateNightMode: function() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]