[gnome-documents] Move handling of in-preview find to a separate action
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] Move handling of in-preview find to a separate action
- Date: Mon, 24 Oct 2016 03:49:31 +0000 (UTC)
commit a81ffdd35fa94b7eb2dd1550495a1ceebce7f790
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Oct 23 17:49:18 2016 -0700
Move handling of in-preview find to a separate action
This is the first step in splitting out the search action between
overview and preview.
src/epubview.js | 21 +++++++++++++++++++--
src/evinceview.js | 46 +++++++++++++++++++++++++++++++---------------
src/mainToolbar.js | 9 +++++----
src/preview.js | 13 +++++--------
src/searchbar.js | 43 ++++++++++++++++++++-----------------------
5 files changed, 80 insertions(+), 52 deletions(-)
---
diff --git a/src/epubview.js b/src/epubview.js
index 923b0aa..a2c67d4 100644
--- a/src/epubview.js
+++ b/src/epubview.js
@@ -22,12 +22,14 @@
const GdPrivate = imports.gi.GdPrivate;
const Gepub = imports.gi.Gepub;
const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
const WebKit2 = imports.gi.WebKit2;
const _ = imports.gettext.gettext;
const Documents = imports.documents;
const Preview = imports.preview;
+const Utils = imports.utils;
const Lang = imports.lang;
@@ -41,6 +43,11 @@ const EPUBView = new Lang.Class({
createActions: function() {
return [
+ { name: 'find',
+ callback: Utils.actionToggleCallback,
+ state: GLib.Variant.new('b', false),
+ stateChanged: Lang.bind(this, this._findStateChanged),
+ accels: ['<Primary>f'] },
{ name: 'find-prev',
callback: Lang.bind(this, this.findPrev),
accels: ['<Shift><Primary>g'] },
@@ -124,8 +131,12 @@ const EPUBView = new Lang.Class({
fc.search(str, WebKit2.FindOptions.CASE_INSENSITIVE, 0);
},
- get canFind() {
- return true;
+ _findStateChanged: function(action) {
+ if (action.state.get_boolean()) {
+ this.toolbar.searchbar.reveal();
+ } else {
+ this.toolbar.searchbar.conceal();
+ }
},
findNext: function() {
@@ -171,6 +182,12 @@ const EPUBViewToolbar = new Lang.Class({
Name: 'EPUBViewToolbar',
Extends: Preview.PreviewToolbar,
+ _init: function(preview) {
+ this.parent(preview);
+
+ this.addSearchButton('view.find');
+ },
+
createSearchbar: function() {
return new EPUBSearchbar(this.preview);
}
diff --git a/src/evinceview.js b/src/evinceview.js
index b48bcc3..5e0f9c9 100644
--- a/src/evinceview.js
+++ b/src/evinceview.js
@@ -118,6 +118,21 @@ const EvinceView = new Lang.Class({
}));
},
+ _findStateChanged: function(action) {
+ let toolbar = this.toolbar;
+ if (this.fullscreen)
+ toolbar = this._fsToolbar.toolbar;
+
+ if (action.state.get_boolean()) {
+ if (this.fullscreen)
+ this.controlsVisible = true;
+
+ toolbar.searchbar.reveal();
+ } else {
+ toolbar.searchbar.conceal();
+ }
+ },
+
_bookmarkStateChanged: function(action) {
let pageNumber = this._model.page;
let bookmark = new GdPrivate.Bookmark({ page_number: pageNumber });
@@ -165,6 +180,11 @@ const EvinceView = new Lang.Class({
{ name: 'rotate-right',
callback: Lang.bind(this, this._rotateRight),
accels: ['<Primary>Right'] },
+ { name: 'find',
+ callback: Utils.actionToggleCallback,
+ state: GLib.Variant.new('b', false),
+ stateChanged: Lang.bind(this, this._findStateChanged),
+ accels: ['<Primary>f'] },
{ name: 'find-prev',
callback: Lang.bind(this, this.findPrev),
accels: ['<Shift><Primary>g'] },
@@ -623,10 +643,6 @@ const EvinceView = new Lang.Class({
return this._model ? this._model.document.get_n_pages() : 0;
},
- get canFind() {
- return true;
- },
-
scroll: function(direction) {
this._evView.scroll(direction, false);
},
@@ -685,18 +701,18 @@ const EvinceViewToolbar = new Lang.Class({
this.parent(preview);
this._handleEvent = false;
- this._searchAction = Application.application.lookup_action('search');
- this._searchAction.enabled = false;
+ this.preview.getAction('find').enabled = false;
this.preview.getAction('gear-menu').enabled = false;
+ this.addSearchButton('view.find');
+
if (Application.application.isBooks) {
this._addFullscreenButton();
this.addNightmodeButton();
}
this.connect('destroy', Lang.bind(this, function() {
- this._searchAction.enabled = true;
if (this._fsStateId > 0)
this.preview.getAction('fullscreen').disconnect(this._fsStateId);
}));
@@ -740,7 +756,7 @@ const EvinceViewToolbar = new Lang.Class({
}
this._handleEvent = (hasPages && canFind);
- this._searchAction.enabled = (hasPages && canFind);
+ this.preview.getAction('find').enabled = (hasPages && canFind);
},
createSearchbar: function() {
@@ -793,13 +809,13 @@ const EvinceViewFullscreenToolbar = new Lang.Class({
_init: function(previewView) {
this.parent({ valign: Gtk.Align.START });
- this._toolbar = new EvinceViewToolbar(previewView);
+ this.toolbar = new EvinceViewToolbar(previewView);
- this.add(this._toolbar);
+ this.add(this.toolbar);
this.show();
// make controls show when a toolbar action is activated in fullscreen
- let actionNames = ['gear-menu', 'search'];
+ let actionNames = ['gear-menu'];
let signalIds = [];
actionNames.forEach(Lang.bind(this,
@@ -815,7 +831,7 @@ const EvinceViewFullscreenToolbar = new Lang.Class({
signalIds.push(signalId);
}));
- this._toolbar.connect('destroy', Lang.bind(this,
+ this.toolbar.connect('destroy', Lang.bind(this,
function() {
signalIds.forEach(
function(signalId) {
@@ -825,11 +841,11 @@ const EvinceViewFullscreenToolbar = new Lang.Class({
},
handleEvent: function(event) {
- this._toolbar.handleEvent(event);
+ this.toolbar.handleEvent(event);
},
setModel: function(model) {
- this._toolbar.setModel(model);
+ this.toolbar.setModel(model);
},
reveal: function() {
@@ -838,7 +854,7 @@ const EvinceViewFullscreenToolbar = new Lang.Class({
conceal: function() {
this.set_reveal_child(false);
- Application.application.change_action_state('search', GLib.Variant.new('b', false));
+ this.toolbar.preview.getAction('find').change_state(GLib.Variant.new('b', false));
}
});
Utils.addJSSignalMethods(EvinceViewFullscreenToolbar.prototype);
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 0a8aade..98e3186 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -86,10 +86,11 @@ const MainToolbar = new Lang.Class({
return res;
},
- addSearchButton: function() {
+ addSearchButton: function(actionName) {
let searchButton = new Gtk.ToggleButton({ image: new Gtk.Image ({ icon_name: 'edit-find-symbolic' }),
tooltip_text: Gettext.pgettext("toolbar button tooltip",
"Search"),
- action_name: 'app.search' });
+ action_name: actionName,
+ visible: true });
this.toolbar.pack_end(searchButton);
return searchButton;
},
@@ -227,7 +228,7 @@ const OverviewToolbar = new Lang.Class({
Application.selectionController.connect('selection-changed',
Lang.bind(this, this._setToolbarTitle));
- this.addSearchButton();
+ this.addSearchButton('app.search');
},
_checkCollectionWidgets: function() {
@@ -283,7 +284,7 @@ const OverviewToolbar = new Lang.Class({
}));
this._addViewMenuButton();
- this.addSearchButton();
+ this.addSearchButton('app.search');
// connect to active collection changes while in this mode
this._collectionId =
diff --git a/src/preview.js b/src/preview.js
index 63ac566..f679d86 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -230,10 +230,6 @@ const Preview = new Lang.Class({
return this._lastSearch;
},
- get canFind() {
- return false;
- },
-
get fullscreen() {
return false;
},
@@ -275,10 +271,6 @@ const PreviewToolbar = new Lang.Class({
action_name: 'view.gear-menu' });
this.toolbar.pack_end(menuButton);
- // search button, on the right of the toolbar
- if (this.preview.canFind)
- this.addSearchButton();
-
this.updateTitle();
this.toolbar.show_all();
},
@@ -520,6 +512,11 @@ const PreviewSearchbar = new Lang.Class({
this.preview = preview;
this.parent();
+
+ this.connect('notify::search-mode-enabled', Lang.bind(this, function() {
+ let action = this.preview.getAction('find');
+ action.change_state(GLib.Variant.new('b', this.search_mode_enabled));
+ }));
},
createSearchWidget: function() {
diff --git a/src/searchbar.js b/src/searchbar.js
index c560063..be68599 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -52,33 +52,10 @@ const Searchbar = new Lang.Class({
this.entryChanged();
}));
- this.connect('notify::search-mode-enabled', Lang.bind(this,
- function() {
- let searchEnabled = this.search_mode_enabled;
- Application.application.change_action_state('search', GLib.Variant.new('b', searchEnabled));
- }));
-
- // connect to the search action state for visibility
- let searchStateId = Application.application.connect('action-state-changed::search',
- Lang.bind(this, this._onActionStateChanged));
- this._onActionStateChanged(Application.application, 'search',
Application.application.get_action_state('search'));
-
- this.connect('destroy', Lang.bind(this,
- function() {
- Application.application.disconnect(searchStateId);
- Application.application.change_action_state('search', GLib.Variant.new('b', false));
- }));
this.show_all();
},
- _onActionStateChanged: function(source, actionName, state) {
- if (state.get_boolean())
- this.reveal();
- else
- this.conceal();
- },
-
createSearchWidget: function() {
log('Error: Searchbar implementations must override createSearchWidget');
},
@@ -166,6 +143,17 @@ const OverviewSearchbar = new Lang.Class({
this._onActiveTypeChanged();
this._onActiveMatchChanged();
+ this.connect('notify::search-mode-enabled', Lang.bind(this,
+ function() {
+ let searchEnabled = this.search_mode_enabled;
+ Application.application.change_action_state('search', GLib.Variant.new('b', searchEnabled));
+ }));
+
+ // connect to the search action state for visibility
+ let searchStateId = Application.application.connect('action-state-changed::search',
+ Lang.bind(this, this._onActionStateChanged));
+ this._onActionStateChanged(Application.application, 'search',
Application.application.get_action_state('search'));
+
this.searchEntry.set_text(Application.searchController.getString());
this.connect('destroy', Lang.bind(this,
function() {
@@ -173,6 +161,8 @@ const OverviewSearchbar = new Lang.Class({
Application.searchTypeManager.disconnect(searchTypeId);
Application.searchMatchManager.disconnect(searchMatchId);
Application.documentManager.disconnect(collectionId);
+ Application.application.disconnect(searchStateId);
+ Application.application.change_action_state('search', GLib.Variant.new('b', false));
}));
},
@@ -285,6 +275,13 @@ const OverviewSearchbar = new Lang.Class({
this._dropdownButton.set_active(true);
},
+ _onActionStateChanged: function(source, actionName, state) {
+ if (state.get_boolean())
+ this.reveal();
+ else
+ this.conceal();
+ },
+
conceal: function() {
this._dropdownButton.set_active(false);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]