[gnome-documents/gnome-3-10] searchbar: Allow enter to activate first search item



commit ab0e121cbbf9b282d6c3564717b40f16f5ea1152
Author: Pranav Kant <pranav913 gmail com>
Date:   Mon Feb 24 16:56:00 2014 +0530

    searchbar: Allow enter to activate first search item
    
    https://bugzilla.gnome.org/show_bug.cgi?id=719920

 src/embed.js       |   11 +++++++++++
 src/mainToolbar.js |    8 ++++----
 src/searchbar.js   |    4 ++++
 src/view.js        |   12 ++++++------
 4 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index 2dee431..8471da8 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -34,6 +34,7 @@ const WindowMode = imports.windowMode;
 const Documents = imports.documents;
 
 const EvView = imports.gi.EvinceView;
+const Gd = imports.gi.Gd;
 const Gdk = imports.gi.Gdk;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
@@ -280,6 +281,14 @@ const Embed = new Lang.Class({
             this._onWindowModeChanged(Application.modeController, windowMode, WindowMode.WindowMode.NONE);
     },
 
+    _onActivateResult: function() {
+        let iter = this._view.model.model.get_iter_first()[1];
+        if (iter) {
+            let id = this._view.model.model.get_value(iter, Gd.MainColumns.ID);
+            Application.documentManager.setActiveItem(Application.documentManager.getItemById(id))
+        };
+    },
+
     _onQueryStatusChanged: function() {
         let windowMode = Application.modeController.getWindowMode();
         if (windowMode != WindowMode.WindowMode.OVERVIEW)
@@ -354,6 +363,8 @@ const Embed = new Lang.Class({
             throw(new Error('Not handled'));
             break;
         }
+        this._toolbar.searchbar.connect('activate-result',
+                                        Lang.bind(this, this._onActivateResult));
     },
 
     _onActiveItemChanged: function(manager, doc) {
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 4503609..a9e2786 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -49,9 +49,9 @@ const MainToolbar = new Lang.Class({
         this.widget.add(this.toolbar);
         this.toolbar.show();
 
-        this._searchbar = this.createSearchbar();
-        if (this._searchbar)
-            this.widget.add(this._searchbar.widget);
+        this.searchbar = this.createSearchbar();
+        if (this.searchbar)
+            this.widget.add(this.searchbar.widget);
 
         Application.documentManager.connect('load-started', Lang.bind(this,
             function() {
@@ -70,7 +70,7 @@ const MainToolbar = new Lang.Class({
         if (!this._handleEvent)
             return false;
 
-        let res = this._searchbar.handleEvent(event);
+        let res = this.searchbar.handleEvent(event);
         return res;
     },
 
diff --git a/src/searchbar.js b/src/searchbar.js
index d8382c0..f7d1082 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -67,6 +67,9 @@ const Searchbar = new Lang.Class({
                 if (keyval == Gdk.KEY_Escape) {
                     Application.application.change_action_state('search', GLib.Variant.new('b', false));
                     return true;
+                } else if (keyval == Gdk.KEY_Return) {
+                    this.emit('activate-result');
+                    return true;
                 }
 
                 return false;
@@ -201,6 +204,7 @@ const Searchbar = new Lang.Class({
         this._searchEntry.set_text('');
     }
 });
+Signals.addSignalMethods(Searchbar.prototype);
 
 const Dropdown = new Lang.Class({
     Name: 'Dropdown',
diff --git a/src/view.js b/src/view.js
index a52194a..0dd02de 100644
--- a/src/view.js
+++ b/src/view.js
@@ -187,7 +187,7 @@ const ViewContainer = new Lang.Class({
         this._adjustmentChangedId = 0;
         this._scrollbarVisibleId = 0;
 
-        this._model = new ViewModel();
+        this.model = new ViewModel();
 
         this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL });
         this.view = new Gd.MainView({ shadow_type: Gtk.ShadowType.NONE });
@@ -332,7 +332,7 @@ const ViewContainer = new Lang.Class({
 
         if (!status) {
             // setup a model if we're not querying
-            this.view.set_model(this._model.model);
+            this.view.set_model(this.model.model);
 
             // unfreeze selection
             Application.selectionController.freezeSelection(false);
@@ -356,13 +356,13 @@ const ViewContainer = new Lang.Class({
 
         let generic = this.view.get_generic_view();
         let first = true;
-        this._model.model.foreach(Lang.bind(this,
+        this.model.model.foreach(Lang.bind(this,
             function(model, path, iter) {
-                let id = this._model.model.get_value(iter, Gd.MainColumns.ID);
+                let id = this.model.model.get_value(iter, Gd.MainColumns.ID);
                 let idIndex = selected.indexOf(id);
 
                 if (idIndex != -1) {
-                    this._model.model.set_value(iter, Gd.MainColumns.SELECTED, true);
+                    this.model.model.set_value(iter, Gd.MainColumns.SELECTED, true);
                     newSelection.push(id);
 
                     if (first) {
@@ -388,7 +388,7 @@ const ViewContainer = new Lang.Class({
     _onViewSelectionChanged: function() {
         // update the selection on the controller when the view signals a change
         let selectedURNs = Utils.getURNsFromPaths(this.view.get_selection(),
-                                                  this._model.model);
+                                                  this.model.model);
         Application.selectionController.setSelection(selectedURNs);
     },
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]