[gnome-documents/wip/cosimoc/view-rework: 17/20] embed: move handling of load signals to preview base class
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/cosimoc/view-rework: 17/20] embed: move handling of load signals to preview base class
- Date: Mon, 8 Aug 2016 15:07:54 +0000 (UTC)
commit 05432222a88fccb0a8cac6e0bd141416a005a967
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Aug 7 16:40:01 2016 -0700
embed: move handling of load signals to preview base class
This can be handled entirely within the preview now.
src/embed.js | 64 --------------------------------------------------------
src/preview.js | 50 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 64 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index 284bc64..4454b72 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -40,16 +40,12 @@ const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
-const _ICON_SIZE = 32;
-const _PDF_LOADER_TIMEOUT = 400;
-
const Embed = new Lang.Class({
Name: 'Embed',
Extends: Gtk.Box,
_init: function(mainWindow) {
this._currentView = null;
- this._loadShowId = 0;
this._searchState = null;
this._window = mainWindow;
@@ -85,13 +81,6 @@ const Embed = new Lang.Class({
this._search = new View.ViewContainer(WindowMode.WindowMode.SEARCH);
this._stack.add_named(this._search, 'search');
- this._spinner = new Gtk.Spinner({ width_request: _ICON_SIZE,
- height_request: _ICON_SIZE,
- halign: Gtk.Align.CENTER,
- valign: Gtk.Align.CENTER });
- this._spinner.show();
- this._stack.add_named(this._spinner, 'spinner');
-
this._stack.connect('notify::visible-child',
Lang.bind(this, this._onVisibleChildChanged));
@@ -102,14 +91,6 @@ const Embed = new Lang.Class({
Application.documentManager.connect('active-changed',
Lang.bind(this, this._onActiveItemChanged));
- Application.documentManager.connect('load-started',
- Lang.bind(this, this._onLoadStarted));
- Application.documentManager.connect('load-finished',
- Lang.bind(this, this._onLoadFinished));
- Application.documentManager.connect('load-error',
- Lang.bind(this, this._onLoadError));
- Application.documentManager.connect('password-needed',
- Lang.bind(this, this._onPasswordNeeded));
Application.searchTypeManager.connect('active-changed',
Lang.bind(this, this._onSearchChanged));
@@ -284,50 +265,6 @@ const Embed = new Lang.Class({
Application.application.change_action_state('search', GLib.Variant.new('b', showSearch));
},
- _clearLoadTimer: function() {
- if (this._loadShowId != 0) {
- Mainloop.source_remove(this._loadShowId);
- this._loadShowId = 0;
- }
- },
-
- _onLoadStarted: function(manager, doc) {
- this._clearLoadTimer();
- this._loadShowId = Mainloop.timeout_add(_PDF_LOADER_TIMEOUT, Lang.bind(this,
- function() {
- this._loadShowId = 0;
-
- this._stack.set_visible_child_name('spinner');
- this._spinner.start();
- return false;
- }));
- },
-
- _onLoadFinished: function(manager, doc, docModel) {
- this._clearLoadTimer();
- this._spinner.stop();
-
- this._stack.set_visible_child_name('preview');
- },
-
- _onLoadError: function(manager, doc, message, exception) {
- this._clearLoadTimer();
- this._spinner.stop();
- },
-
- _onPasswordNeeded: function(manager, doc) {
- this._clearLoadTimer();
- this._spinner.stop();
-
- let dialog = new Password.PasswordDialog(doc);
- dialog.connect('response', Lang.bind(this,
- function(widget, response) {
- dialog.destroy();
- if (response == Gtk.ResponseType.CANCEL || response == Gtk.ResponseType.DELETE_EVENT)
- Application.documentManager.setActiveItem(null);
- }));
- },
-
_clearViewState: function() {
this._clearingView = true;
if (this._preview) {
@@ -372,7 +309,6 @@ const Embed = new Lang.Class({
this._titlebar.add(this._toolbar);
}
- this._spinner.stop();
this._stack.set_visible_child(visibleChild);
this._currentView = visibleChild;
},
diff --git a/src/preview.js b/src/preview.js
index d00bf76..ae304aa 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -15,12 +15,16 @@ const Properties = imports.properties;
const Searchbar = imports.searchbar;
const Utils = imports.utils;
+const _ICON_SIZE = 32;
+const _PDF_LOADER_TIMEOUT = 400;
+
const Preview = new Lang.Class({
Name: 'Preview',
Extends: Gtk.Stack,
_init: function(overlay, mainWindow) {
this._lastSearch = '';
+ this._loadShowId = 0;
this.overlay = overlay;
this.mainWindow = mainWindow;
@@ -34,6 +38,12 @@ const Preview = new Lang.Class({
this._errorBox = new ErrorBox.ErrorBox();
this.add_named(this._errorBox, 'error');
+ this._spinner = new Gtk.Spinner({ width_request: _ICON_SIZE,
+ height_request: _ICON_SIZE,
+ halign: Gtk.Align.CENTER,
+ valign: Gtk.Align.CENTER });
+ this.add_named(this._spinner, 'spinner');
+
this.view = this.createView();
this.add_named(this.view, 'view');
this.view.show();
@@ -53,6 +63,8 @@ const Preview = new Lang.Class({
Lang.bind(this, this.onLoadFinished));
this._loadErrorId = Application.documentManager.connect('load-error',
Lang.bind(this, this.onLoadError));
+ this._passwordNeededId = Application.documentManager.connect('password-needed',
+ Lang.bind(this, this.onPasswordNeeded));
},
_getDefaultActions: function() {
@@ -98,6 +110,10 @@ const Preview = new Lang.Class({
Application.documentManager.disconnect(this._loadErrorId);
this._loadErrorId = 0;
}
+ if (this._passwordNeededId > 0) {
+ Application.documentManager.disconnect(this._passwordNeededId);
+ this._passwordNeededId = 0;
+ }
if (this.navControls) {
this.navControls.destroy();
this.navControls = null;
@@ -129,14 +145,48 @@ const Preview = new Lang.Class({
return Gtk.Menu.new_from_model(model);
},
+ _clearLoadTimer: function() {
+ if (this._loadShowId != 0) {
+ Mainloop.source_remove(this._loadShowId);
+ this._loadShowId = 0;
+ }
+ },
+
+ onPasswordNeeded: function(manager, doc) {
+ this._clearLoadTimer();
+ this._spinner.stop();
+
+ let dialog = new Password.PasswordDialog(doc);
+ dialog.connect('response', Lang.bind(this, function(widget, response) {
+ dialog.destroy();
+ if (response == Gtk.ResponseType.CANCEL || response == Gtk.ResponseType.DELETE_EVENT)
+ Application.documentManager.setActiveItem(null);
+ }));
+ },
+
onLoadStarted: function(manager, doc) {
+ this._clearLoadTimer();
+ this._loadShowId = Mainloop.timeout_add(_PDF_LOADER_TIMEOUT, Lang.bind(this, function() {
+ this._loadShowId = 0;
+
+ this.set_visible_child_name('spinner');
+ this._spinner.start();
+ return false;
+ }));
},
onLoadFinished: function(manager, doc) {
+ this._clearLoadTimer();
+ this._spinner.stop();
+
+ this.set_visible_child_name('view');
this.getAction('open-current').enabled = (doc.defaultApp != null);
},
onLoadError: function(manager, doc, message, exception) {
+ this._clearLoadTimer();
+ this._spinner.stop();
+
this._errorBox.update(message, exception.message);
this.set_visible_child_name('error');
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]