[gnome-documents] documents: simplify doc model loading code
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] documents: simplify doc model loading code
- Date: Tue, 26 Jun 2012 17:45:08 +0000 (UTC)
commit 0b76eabf40e9bc95f7e395692fe26cc2437afb11
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Jun 26 13:29:59 2012 -0400
documents: simplify doc model loading code
src/documents.js | 36 +++++++++++++++++++++++-------------
src/embed.js | 13 ++++---------
2 files changed, 27 insertions(+), 22 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 7255ebc..3dc9ba9 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -19,6 +19,7 @@
*
*/
+const EvView = imports.gi.EvinceView;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Gio = imports.gi.Gio;
const Gd = imports.gi.Gd;
@@ -604,6 +605,17 @@ const DocCommon = new Lang.Class({
retval = '{ ?urn nie:isPartOf <' + this.id + '> }';
return retval;
+ },
+
+ _finishLoad: function(document, callback, exception) {
+ let docModel = null;
+ if (exception) {
+ Global.errorHandler.addLoadError(this, exception);
+ } else {
+ docModel = EvView.DocumentModel.new_with_document(document);
+ }
+
+ callback(this, docModel, exception);
}
});
Signals.addSignalMethods(DocCommon.prototype);
@@ -638,9 +650,9 @@ const LocalDocument = new Lang.Class({
function(source, res) {
try {
let document = Gd.pdf_loader_load_uri_finish(res);
- callback(this, document, null);
+ this._finishLoad(document, callback, null);
} catch (e) {
- callback(this, null, e);
+ this._finishLoad(null, callback, e);
}
}));
},
@@ -709,11 +721,10 @@ const GoogleDocument = new Lang.Class({
function(source, res) {
try {
let document = Gd.pdf_loader_load_uri_finish(res);
- callback(this, document, null);
+ this._finishLoad(document, callback, null);
} catch (e) {
// report the outmost error only
- callback(this, null, exception);
- return;
+ this._finishLoad(null, callback, exception);
}
}));
@@ -724,10 +735,10 @@ const GoogleDocument = new Lang.Class({
(entry, service, cancellable, Lang.bind(this,
function(source, res) {
try {
- let document = Gd.pdf_loader_load_gdata_entry_finish(res);
- callback(this, document, null);
+ let document = Gd.pdf_loader_load_uri_finish(res);
+ this._finishLoad(document, callback, null);
} catch (e) {
- callback(this, null, e);
+ this._finishLoad(null, callback, e);
}
}));
}));
@@ -849,11 +860,10 @@ const SkydriveDocument = new Lang.Class({
function(source, res) {
try {
let document = Gd.pdf_loader_load_uri_finish(res);
- callback(this, document, null);
+ this._finishLoad(document, callback, null);
} catch (e) {
// report the outmost error only
- callback(this, null, exception);
- return;
+ this._finishLoad(null, callback, exception);
}
}));
@@ -865,9 +875,9 @@ const SkydriveDocument = new Lang.Class({
function(source, res) {
try {
let document = Gd.pdf_loader_load_zpj_entry_finish(res);
- callback(this, document, null);
+ this._finishLoad(document, callback, null);
} catch (e) {
- callback(this, null, e);
+ this._finishLoad(null, callback, e);
}
}));
}));
diff --git a/src/embed.js b/src/embed.js
index 1502e21..3bdd10b 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -201,16 +201,13 @@ const ViewEmbed = new Lang.Class({
doc.load(this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
},
- _onDocumentLoaded: function(doc, evDoc, error) {
+ _onDocumentLoaded: function(doc, docModel, error) {
this._loaderCancellable = null;
- if (!evDoc) {
- Global.errorHandler.addLoadError(doc, error);
+ if (!docModel) {
return;
}
- let docModel = EvView.DocumentModel.new_with_document(evDoc);
-
this._toolbar.setModel(docModel);
this._preview.setModel(docModel);
this._preview.widget.grab_focus();
@@ -220,7 +217,8 @@ const ViewEmbed = new Lang.Class({
},
_prepareForOverview: function() {
- Global.documentManager.setActiveItem(null);
+ if (this._preview)
+ this._preview.setModel(null);
if (this._loaderCancellable) {
this._loaderCancellable.cancel();
@@ -230,9 +228,6 @@ const ViewEmbed = new Lang.Class({
this._spinnerBox.moveOut();
this._errorBox.moveOut();
- if (this._preview)
- this._preview.setModel(null);
-
if (!this._view) {
let grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL });
this._view = new View.View();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]