[gnome-documents: 17/22] 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: 17/22] embed: move handling of load signals to preview base class
- Date: Sat, 3 Sep 2016 18:02:08 +0000 (UTC)
commit af2163d591f2c301dc90028be510216bb2fd78dc
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 | 65 --------------------------------------------------------
src/preview.js | 51 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 65 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index 284bc64..988eee9 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -24,7 +24,6 @@ const Mainloop = imports.mainloop;
const Application = imports.application;
const MainToolbar = imports.mainToolbar;
-const Password = imports.password;
const Edit = imports.edit;
const Search = imports.search;
const Selections = imports.selections;
@@ -40,16 +39,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 +80,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 +90,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 +264,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 +308,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..ef8f6cc 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -11,16 +11,21 @@ const Tweener = imports.tweener.tweener;
const Application = imports.application;
const ErrorBox = imports.errorBox;
const MainToolbar = imports.mainToolbar;
+const Password = imports.password;
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 +39,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 +64,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 +111,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 +146,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]