[polari/wip/fmuellner/roomlist-filtering: 4/8] serverRoomList: Implement filtering



commit 20831c3c6ee1a022428a8964a07313a4c6390ae7
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Mar 11 00:50:04 2017 +0100

    serverRoomList: Implement filtering
    
    The entry already looks like it can be used to filter the list of
    rooms, now make it behave as advertised.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779960

 src/serverRoomManager.js |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index 36c2e01..b59a2d1 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -9,6 +9,7 @@ const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const RoomManager = imports.roomManager;
 const Signals = imports.signals;
+const Utils = imports.utils;
 
 const LIST_CHUNK_SIZE = 100;
 
@@ -126,6 +127,7 @@ const ServerRoomList = new Lang.Class({
     _init: function(params) {
         this._account = null;
         this._pendingInfos = [];
+        this._filterTerms = [];
 
         this.parent(params);
 
@@ -133,7 +135,21 @@ const ServerRoomList = new Lang.Class({
             this.setAccount(null);
         });
 
+        this._list.model.set_visible_func((model, iter) => {
+            let name = model.get_value(iter, RoomListColumn.NAME);
+            if (!name)
+                return false;
+
+            return this._filterTerms.every((term) => name.indexOf(term) != -1);
+        });
+
         this._filterEntry.connect('changed', () => { this.notify('can-join'); });
+        this._filterEntry.connect('search-changed', () => {
+            if (!Utils.updateTerms(this._filterTerms, this._filterEntry.text))
+                return;
+
+            this._list.model.refilter();
+        });
         this._filterEntry.connect('stop-search', () => {
             if (this._filterEntry.get_text_length() > 0)
                 this._filterEntry.set_text('');


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