[polari/wip/fmuellner/combined-gsoc: 47/136] mainWindow: Adjust mode switch conditions



commit bc76b88567b6025145daa82329a691d6bb3ed4e5
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 21 13:26:38 2016 +0200

    mainWindow: Adjust mode switch conditions

 data/resources/main-window.ui |    4 ++--
 src/mainWindow.js             |   30 ++++++++++++++++++++++--------
 2 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index e71852e..0c49be7 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -221,7 +221,7 @@
                                         <child>
                                             <object class="GtkStack" id="leftStack">
                                                 <property name="visible">True</property>
-                                                <property name="transition-type">slide-left-right</property>
+                                                <property name="transition-type">crossfade</property>
                                                 <property name="hexpand">true</property>
                                                 <!-- <property name="resize-mode">queue</property> -->
                                                 <property name="visible-child-name" 
bind-source="Gjs_MainWindow"
@@ -282,7 +282,7 @@
                         <child>
                             <object class="GtkStack" id="rightStack">
                                 <property name="visible">True</property>
-                                <property name="transition-type">slide-left-right</property>
+                                <property name="transition-type">crossfade</property>
                                 <property name="hexpand">true</property>
                                 <property name="visible-child-name" bind-source="Gjs_MainWindow"
                                     bind-property="mode" bind-flags="sync-create"/>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 8b093f4..51d7b16 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -232,6 +232,8 @@ const MainWindow = new Lang.Class({
                            GObject.BindingFlags.BIDIRECTIONAL);
 
         this._searchBar.connect_entry(this._searchEntry);
+        this._searchBar.connect('notify::search-mode-enabled',
+                                Lang.bind(this, this._updateMode));
         this._searchEntry.connect('search-changed',
                                    Lang.bind(this, this._handleSearchChanged));
 
@@ -260,19 +262,31 @@ const MainWindow = new Lang.Class({
         return this._mode;
     },
 
-    _handleSearchChanged: function(entry) {
-        let text = entry.get_text().replace(/^\s+|\s+$/g, '');
-        let app = this.application;
-        let action = app.lookup_action('search-terms');
-        action.change_state(GLib.Variant.new('s', text));
-        if(text!='') {
-            this._mode='search';
+    _updateMode: function() {
+        let mode;
+        if (this._mode == 'search') {
+            mode = this._searchBar.search_mode_enabled ? 'search' : 'chat';
         } else {
-            this._mode='chat';
+            let state = this.application.get_action_state('search-terms');
+            let [terms, ] = state.get_string();
+            mode = terms.length > 0 ? 'search' : 'chat';
         }
+
+        if (mode == this._mode)
+            return;
+
+        this._mode = mode;
         this.notify('mode');
     },
 
+    _handleSearchChanged: function(entry) {
+        let text = entry.get_text().replace(/^\s+|\s+$/g, '');
+        let terms = new GLib.Variant('s',
+                                     text.length < MIN_SEARCH_WIDTH ? '' : text);
+        this.application.change_action_state('search-terms', terms);
+        this._updateMode();
+    },
+
     _onWindowStateEvent: function(widget, event) {
         let state = event.get_window().get_state();
 


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