[gnome-documents] preview: move night mode toolbar button to parent class
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] preview: move night mode toolbar button to parent class
- Date: Sat, 1 Apr 2017 21:53:08 +0000 (UTC)
commit 30d5488e814a59a5dc095d820d1a1c026a1a7e3a
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Apr 1 14:51:42 2017 -0700
preview: move night mode toolbar button to parent class
So that it can be also used e.g. in the epub backend.
src/evinceview.js | 24 +++++-------------------
src/mainToolbar.js | 9 ---------
src/preview.js | 30 +++++++++++++++++++++++++++++-
3 files changed, 34 insertions(+), 29 deletions(-)
---
diff --git a/src/evinceview.js b/src/evinceview.js
index 3f49969..9ff73d6 100644
--- a/src/evinceview.js
+++ b/src/evinceview.js
@@ -52,14 +52,6 @@ const EvinceView = new Lang.Class({
this.parent(overlay, mainWindow);
this.getAction('bookmark-page').enabled = false;
-
- let nightModeId = Application.application.connect('action-state-changed::night-mode',
- Lang.bind(this, this._updateNightMode));
-
- this.connect('destroy', Lang.bind(this,
- function() {
- Application.application.disconnect(nightModeId);
- }));
},
_copy: function() {
@@ -282,7 +274,6 @@ const EvinceView = new Lang.Class({
docModel.set_continuous(false);
docModel.set_page_layout(EvView.PageLayout.AUTOMATIC);
- this._updateNightMode();
this._model.connect('page-changed', Lang.bind(this, this._onPageChanged));
@@ -559,13 +550,6 @@ const EvinceView = new Lang.Class({
return metadata;
},
- _updateNightMode: function() {
- if (this._model && !Application.application.isBooks) {
- let nightMode = Application.settings.get_boolean('night-mode');
- this._model.set_inverted_colors(nightMode);
- }
- },
-
getModel: function() {
return this._model;
},
@@ -592,6 +576,11 @@ const EvinceView = new Lang.Class({
get canFullscreen() {
return true;
+ },
+
+ set nightMode(v) {
+ if (this._model && !Application.application.isBooks)
+ this._model.set_inverted_colors(v);
}
});
@@ -641,9 +630,6 @@ const EvinceViewToolbar = new Lang.Class({
this._handleEvent = false;
this.addSearchButton('view.find');
-
- if (Application.application.isBooks)
- this.addNightmodeButton();
},
setModel: function() {
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 8aeb8dd..236ba1f 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -95,15 +95,6 @@ const MainToolbar = new Lang.Class({
return searchButton;
},
- addNightmodeButton: function() {
- let nightmodeButton = new Gtk.ToggleButton({ image: new Gtk.Image ({ icon_name:
'display-brightness-symbolic' }),
- tooltip_text: _("Night Mode"),
- action_name: 'app.night-mode',
- visible: true });
- this.toolbar.pack_end(nightmodeButton);
- return nightmodeButton;
- },
-
addBackButton: function() {
let backButton = new Gtk.Button({ image: new Gtk.Image({ icon_name: 'go-previous-symbolic' }),
tooltip_text: _("Back"),
diff --git a/src/preview.js b/src/preview.js
index 1702d71..027334d 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -71,6 +71,9 @@ const Preview = new Lang.Class({
Lang.bind(this, this.onLoadError));
this._passwordNeededId = Application.documentManager.connect('password-needed',
Lang.bind(this, this.onPasswordNeeded));
+
+ this._nightModeId = Application.application.connect('action-state-changed::night-mode',
+ Lang.bind(this, this._updateNightMode));
},
_getDefaultActions: function() {
@@ -118,6 +121,10 @@ const Preview = new Lang.Class({
doc.open(this.mainWindow, Gtk.get_current_event_time());
},
+ _updateNightMode: function() {
+ this.nightMode = Application.settings.get_boolean('night-mode');
+ },
+
_onFullscreenChanged: function(action) {
let fullscreen = action.state.get_boolean();
@@ -231,6 +238,11 @@ const Preview = new Lang.Class({
this._fullscreenAction.disconnect(this._fsStateId);
}
+ if (this._nightModeId > 0) {
+ Application.application.disconnect(this._nightModeId);
+ this._nightModeId = 0;
+ }
+
this.parent();
},
@@ -316,6 +328,7 @@ const Preview = new Lang.Class({
this.set_visible_child_name('view');
this.getAction('open-current').enabled = (doc.defaultAppName != null);
+ this._updateNightMode();
},
onLoadError: function(manager, doc, message, exception) {
@@ -374,6 +387,10 @@ const Preview = new Lang.Class({
return false;
},
+ set nightMode(v) {
+ // do nothing
+ },
+
findPrev: function() {
throw (new Error('Not implemented'));
},
@@ -403,8 +420,10 @@ const PreviewToolbar = new Lang.Class({
action_name: 'view.gear-menu' });
this.toolbar.pack_end(menuButton);
- if (this.preview.canFullscreen && Application.application.isBooks)
+ if (this.preview.canFullscreen && Application.application.isBooks) {
this._addFullscreenButton();
+ this._addNightmodeButton();
+ }
this.updateTitle();
this.toolbar.show_all();
@@ -430,6 +449,15 @@ const PreviewToolbar = new Lang.Class({
return menu;
},
+ _addNightmodeButton: function() {
+ let nightmodeButton = new Gtk.ToggleButton({ image: new Gtk.Image ({ icon_name:
'display-brightness-symbolic' }),
+ tooltip_text: _("Night Mode"),
+ action_name: 'app.night-mode',
+ visible: true });
+ this.toolbar.pack_end(nightmodeButton);
+ return nightmodeButton;
+ },
+
_addFullscreenButton: function() {
this._fullscreenButton = new Gtk.Button({ image: new Gtk.Image ({ icon_name:
'view-fullscreen-symbolic' }),
tooltip_text: _("Fullscreen"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]