[gnome-documents: 7/10] searchbar: properly set initial state on creation



commit 15bd437f1dbd12399d88e441462049b1b57e9dfb
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Dec 10 16:57:24 2012 -0500

    searchbar: properly set initial state on creation

 src/searchbar.js |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/src/searchbar.js b/src/searchbar.js
index 47d524d..3b57cc0 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -90,15 +90,20 @@ const Searchbar = new Lang.Class({
             }));
 
         // connect to the search action state for visibility
-        let searchStateId = Application.application.connect('action-state-changed::search', Lang.bind(this,
-            function(source, actionName, state) {
-                if (state.get_boolean())
-                    this.show();
-                else
-                    this.hide();
+        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'));
+
+        // connect to search string changes in the controller
+        this._searchEntry.text = Application.searchController.getString();
+        let searchChangedId = Application.searchController.connect('search-string-changed', Lang.bind(this,
+            function(controller, string) {
+                this._searchEntry.text = string;
             }));
+
         this.widget.connect('destroy', Lang.bind(this,
             function() {
+                Application.searchController.disconnect(searchChangedId);
                 Application.application.disconnect(searchStateId);
                 Application.application.change_action_state('search', GLib.Variant.new('b', false));
             }));
@@ -106,6 +111,13 @@ const Searchbar = new Lang.Class({
         this.widget.show_all();
     },
 
+    _onActionStateChanged: function(source, actionName, state) {
+        if (state.get_boolean())
+            this.show();
+        else
+            this.hide();
+    },
+
     createSearchWidgets: function() {
         log('Error: Searchbar implementations must override createSearchWidgets');
     },



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