[gnome-documents] application: add keybindings for Find Previous/Next
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] application: add keybindings for Find Previous/Next
- Date: Thu, 19 Jul 2012 21:30:28 +0000 (UTC)
commit 7397c02a0d8147d221f417cbbb0688fc1fc40829
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu Jul 19 16:25:39 2012 -0400
application: add keybindings for Find Previous/Next
And add a way to tie actions to a certain window mode.
src/application.js | 35 ++++++++++++++++-------
src/preview.js | 79 +++++++++++++++++++++++++--------------------------
2 files changed, 63 insertions(+), 51 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index f384441..618dead 100644
--- a/src/application.js
+++ b/src/application.js
@@ -82,11 +82,6 @@ const Application = new Lang.Class({
function() {
action.state = Global.settings.get_value('view-as');
}));
- Global.modeController.connect('window-mode-changed', Lang.bind(this,
- function() {
- let mode = Global.modeController.getWindowMode();
- action.set_enabled(mode == WindowMode.WindowMode.OVERVIEW);
- }));
},
_onActionQuit: function() {
@@ -132,22 +127,32 @@ const Application = new Lang.Class({
{ name: 'fullscreen',
callback: this._onActionFullscreen,
create_hook: this._fullscreenCreateHook,
- accel: 'F11' },
+ accel: 'F11',
+ window_mode: WindowMode.WindowMode.PREVIEW },
{ name: 'view-as',
callback: this._onActionViewAs,
create_hook: this._viewAsCreateHook,
parameter_type: 's',
- state: Global.settings.get_value('view-as') },
+ state: Global.settings.get_value('view-as'),
+ window_mode: WindowMode.WindowMode.OVERVIEW },
{ name: 'open-current',
- callback: this._onActionOpenCurrent },
+ callback: this._onActionOpenCurrent,
+ window_mode: WindowMode.WindowMode.PREVIEW },
{ name: 'print-current',
- callback: this._onActionPrintCurrent },
+ callback: this._onActionPrintCurrent,
+ window_mode: WindowMode.WindowMode.PREVIEW },
{ name: 'search',
callback: this._onActionSearch,
state: GLib.Variant.new('b', false),
accel: '<Primary>f' },
- { name: 'zoom-in', accel: '<Primary>plus' },
- { name: 'zoom-out', accel: '<Primary>minus' }
+ { name: 'find-next', accel: '<Primary>g',
+ window_mode: WindowMode.WindowMode.PREVIEW },
+ { name: 'find-prev', accel: '<Shift><Primary>g',
+ window_mode: WindowMode.WindowMode.PREVIEW },
+ { name: 'zoom-in', accel: '<Primary>plus',
+ window_mode: WindowMode.WindowMode.PREVIEW },
+ { name: 'zoom-out', accel: '<Primary>minus',
+ window_mode: WindowMode.WindowMode.PREVIEW }
];
actionEntries.forEach(Lang.bind(this,
@@ -172,6 +177,14 @@ const Application = new Lang.Class({
if (actionEntry.accel)
this.add_accelerator(actionEntry.accel, 'app.' + actionEntry.name, null);
+ if (actionEntry.window_mode) {
+ Global.modeController.connect('window-mode-changed', Lang.bind(this,
+ function() {
+ let mode = Global.modeController.getWindowMode();
+ action.set_enabled(mode == actionEntry.window_mode);
+ }));
+ }
+
this.add_action(action);
}));
},
diff --git a/src/preview.js b/src/preview.js
index 9470afd..70b199c 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -66,6 +66,16 @@ const PreviewView = new Lang.Class({
this._model.set_sizing_mode(EvView.SizingMode.FREE);
this.view.zoom_out();
}));
+
+ this._findPrev = Global.application.lookup_action('find-prev');
+ this._findPrev.connect('activate', Lang.bind(this,
+ function() {
+ this.view.find_previous();
+ }));
+ this._findNext = Global.application.lookup_action('find-next');
+ this._findNext.connect('activate', Lang.bind(this,
+ function() {
+ }));
},
_createView: function() {
@@ -121,6 +131,24 @@ const PreviewView = new Lang.Class({
return false;
},
+ startSearch: function(str) {
+ if (!this._model)
+ return;
+
+ let evDoc = this._model.get_document();
+ let job = EvView.JobFind.new(evDoc, this._model.get_page(), evDoc.get_n_pages(),
+ str, false);
+ job.connect('updated', Lang.bind(this, this._onSearchJobUpdated));
+
+ job.scheduler_push_job(EvView.JobPriority.PRIORITY_NONE);
+ },
+
+ _onSearchJobUpdated: function(job, page) {
+ // FIXME: ev_job_find_get_results() returns a GList **
+ // and thus is not introspectable
+ Gd.ev_view_find_changed(this.view, job, page);
+ },
+
setModel: function(model) {
if (this._model == model)
return;
@@ -128,11 +156,12 @@ const PreviewView = new Lang.Class({
if (this.view)
this.view.destroy();
- this._createView();
this._model = model;
- if (this._model)
+ if (this._model) {
+ this._createView();
this.view.set_model(this._model);
+ }
},
getModel: function() {
@@ -397,7 +426,10 @@ const PreviewSearchbar = new Lang.Class({
spacing: 6 });
this._searchEntry = new Gtk.SearchEntry({ hexpand: true });
- this._searchEntry.connect('activate', Lang.bind(this, this._searchNext));
+ this._searchEntry.connect('activate', Lang.bind(this,
+ function() {
+ Global.application.activate_action('find-next', null);
+ }));
this._searchContainer.add(this._searchEntry);
let controlsBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
@@ -405,16 +437,14 @@ const PreviewSearchbar = new Lang.Class({
controlsBox.get_style_context().add_class('raised');
this._searchContainer.add(controlsBox);
- let prev = new Gtk.Button();
- prev.connect('clicked', Lang.bind(this, this._searchPrev));
+ let prev = new Gtk.Button({ action_name: 'app.find-prev' });
prev.set_image(new Gtk.Image({ icon_name: 'go-up-symbolic',
icon_size: Gtk.IconSize.MENU,
margin: 2 }));
prev.set_tooltip_text(_("Find Previous"));
controlsBox.add(prev);
- let next = new Gtk.Button();
- next.connect('clicked', Lang.bind(this, this._searchNext));
+ let next = new Gtk.Button({ action_name: 'app.find-next' });
next.set_image(new Gtk.Image({ icon_name: 'go-down-symbolic',
icon_size: Gtk.IconSize.MENU,
margin: 2 }));
@@ -424,51 +454,20 @@ const PreviewSearchbar = new Lang.Class({
entryChanged: function() {
this._previewView.view.find_search_changed();
- this._startSearch();
+ this._previewView.startSearch(this._searchEntry.get_text());
},
show: function() {
this.parent();
this._previewView.view.find_set_highlight_search(true);
- this._startSearch();
+ this._previewView.startSearch(this._searchEntry.get_text());
},
hide: function() {
this.parent();
this._previewView.view.find_set_highlight_search(false);
- },
-
- _startSearch: function() {
- let model = this._previewView.getModel();
- if (!model)
- return;
-
- let str = this._searchEntry.get_text();
- if (!str)
- return;
-
- let evDoc = model.get_document();
- let job = EvView.JobFind.new(evDoc, model.get_page(), evDoc.get_n_pages(),
- str, false);
- job.connect('updated', Lang.bind(this, this._onSearchJobUpdated));
-
- job.scheduler_push_job(EvView.JobPriority.PRIORITY_NONE);
- },
-
- _searchPrev: function() {
- this._previewView.view.find_previous();
- },
-
- _searchNext: function() {
- this._previewView.view.find_next();
- },
-
- _onSearchJobUpdated: function(job, page) {
- // FIXME: ev_job_find_get_results() returns a GList **
- // and thus is not introspectable
- Gd.ev_view_find_changed(this._previewView.view, job, page);
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]