[polari/wip/kunaljain/polari-search] search-bar



commit 60f557478c25ed1c396d273355ab38c66cf15c32
Author: Kunaal Jain <kunaalus gmail com>
Date:   Sun Jun 5 20:26:35 2016 +0530

    search-bar

 data/resources/main-window.ui |   49 +++++++++++++++++++++++++++++++++++++++++
 src/mainWindow.js             |   34 +++++++++++++++++++++++++++-
 src/utils.js                  |   17 ++++++++++++++
 3 files changed, 99 insertions(+), 1 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 78a38b5..445b1bb 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -60,6 +60,34 @@
                 <property name="pack-type">end</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkToggleButton" id="search-active-button">
+                <property name="visible">True</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <property name="margin-start">5</property>
+                <property name="margin-end">5</property>
+                <style>
+                  <class name="image-button"/>
+                </style>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon-name">edit-find-symbolic</property>
+                    <property name="icon-size">1</property>
+                  </object>
+                </child>
+                <child internal-child="accessible">
+                  <object class="AtkObject">
+                    <property name="AtkObject::accessible-name"
+                              translatable="yes">Add rooms and networks</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="pack-type">end</property>
+              </packing>
+            </child>
           </object>
         </child>
         <child>
@@ -170,6 +198,25 @@
             <property name="hexpand">False</property>
             <property name="transition-type">slide-right</property>
             <child>
+         <object class="GtkGrid" id="sidebar-grid">
+            <property name="can_focus">False</property>
+            <property name="visible">True</property>
+            <property name="hexpand">False</property>
+            <property name="vexpand">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+      <object class="GtkSearchBar" id="search-bar">
+        <property name="visible">True</property>
+        <property name="halign">fill</property>
+        <child>
+          <object class="GtkSearchEntry" id="search-entry">
+      <property name="can_focus">True</property>
+      <property name="halign">fill</property>
+          </object>
+        </child>
+      </object>
+    </child>
+            <child>
               <object class="Gjs_FixedSizeFrame" id="roomSidebar">
                 <property name="visible">True</property>
                 <property name="hexpand">False</property>
@@ -199,6 +246,8 @@
             </child>
           </object>
         </child>
+          </object>
+        </child>
         <child>
           <object class="GtkOverlay" id="overlay">
             <property name="visible">True</property>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index a46b113..0bcb65f 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -94,6 +94,9 @@ const MainWindow = new Lang.Class({
     InternalChildren: ['titlebarRight',
                        'titlebarLeft',
                        'joinButton',
+                       'search-active-button',
+                        'search-bar',
+                        'search-entry',
                        'showUserListButton',
                        'userListPopover',
                        'roomListRevealer',
@@ -109,7 +112,10 @@ const MainWindow = new Lang.Class({
                                                       'subtitle-visible',
                                                       'subtitle-visible',
                                                       GObject.ParamFlags.READABLE,
-                                                      false)
+                                                      false),
+        'search-active': GObject.ParamSpec.boolean(
+            'search-active', '', '',
+            GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE, false)
     },
 
     _init: function(params) {
@@ -123,6 +129,8 @@ const MainWindow = new Lang.Class({
         this._rooms = {};
         this._entries = {};
 
+        this._searchActive = false;
+
         this._room = null;
         this._settings = new Gio.Settings({ schema_id: 'org.gnome.Polari' });
         this._gtkSettings = Gtk.Settings.get_default();
@@ -195,6 +203,26 @@ const MainWindow = new Lang.Class({
                             Lang.bind(this, this._onSizeAllocate));
         this.connect('delete-event',
                             Lang.bind(this, this._onDelete));
+        this.connect('key-press-event', Lang.bind(this, this._handleKeyPress));
+
+        // search start
+        Utils.initActions(this,
+                         [
+                          { name: 'search-active',
+                            activate: this._toggleSearch,
+                            parameter_type: new GLib.VariantType('b'),
+                            state: new GLib.Variant('b', false) }
+                         ]);
+        this.bind_property('search-active', this._search_active_button, 'active',
+                           GObject.BindingFlags.SYNC_CREATE |
+                           GObject.BindingFlags.BIDIRECTIONAL);
+        this.bind_property('search-active',
+                           this._search_bar,
+                           'search-mode-enabled',
+                           GObject.BindingFlags.SYNC_CREATE |
+                           GObject.BindingFlags.BIDIRECTIONAL);
+        this._search_bar.connect_entry(this._search_entry);
+        // search end
 
         let size = this._settings.get_value('window-size').deep_unpack();
         if (size.length == 2)
@@ -221,6 +249,10 @@ const MainWindow = new Lang.Class({
         this._isMaximized = (state & Gdk.WindowState.MAXIMIZED) != 0;
     },
 
+    _handleKeyPress: function(self, event) {
+        return this._search_bar.handle_event(event);
+    },
+
     _onSizeAllocate: function(widget, allocation) {
         if (!this._isFullscreen && !this._isMaximized)
             this._currentSize = this.get_size(this);
diff --git a/src/utils.js b/src/utils.js
index edb9e5d..b555634 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -109,6 +109,23 @@ function getURISchemes() {
     return schemes;
 }
 
+function initActions(actionMap, simpleActionEntries, context) {
+    simpleActionEntries.forEach(function(actionEntry) {
+        let props = {};
+                ['name', 'state', 'parameter_type'].forEach(
+                    function(prop) {
+                        if (actionEntry[prop])
+                            props[prop] = actionEntry[prop];
+                    });
+                let action = new Gio.SimpleAction(props);
+                if (actionEntry.create_hook)
+                    actionEntry.create_hook(action);
+                if (actionEntry.activate)
+                    action.connect('activate', actionEntry.activate);
+    });
+}
+
+
 function getTpEventTime() {
     let time = Gtk.get_current_event_time ();
     if (time == 0)


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