[polari/wip/fmuellner/roomlist-filtering: 8/8] serverRoomList: Provide an efficient way to join a single room



commit 860c7038d6564cccd0c7653d4c8bb983cb6aba1a
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Mar 11 03:10:33 2017 +0100

    serverRoomList: Provide an efficient way to join a single room
    
    The ability to join multiple rooms at once is neat, but most useful
    right after setting up a new network. After that, by far the most
    common case is to join a single room, so it's worth making that
    case as efficient as possible. Right now we require users to select
    a room by selecting a row via mouse or keynav, and then activate
    the join button. This is often slower than the pre-room-list dialog,
    where a room was joined by hitting Enter after typing the (full)
    room name - to improve on both current and old behavior, keep the
    top result selected when filtering and toggle the selected row
    when the entry is activated.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779960

 src/serverRoomManager.js |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index 105c61c..fd9b841 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -155,12 +155,14 @@ const ServerRoomList = new Lang.Class({
 
         this._filterEntry.connect('changed', () => {
             this._updateCustomRoomName();
+            this._updateSelection();
         });
         this._filterEntry.connect('search-changed', () => {
             if (!Utils.updateTerms(this._filterTerms, this._filterEntry.text))
                 return;
 
             this._list.model.refilter();
+            this._updateSelection();
         });
         this._filterEntry.connect('stop-search', () => {
             if (this._filterEntry.get_text_length() > 0)
@@ -168,6 +170,14 @@ const ServerRoomList = new Lang.Class({
             else if (this.get_toplevel() instanceof Gtk.Dialog)
                 this.get_toplevel().response(Gtk.ResponseType.CANCEL);
         });
+        this._filterEntry.connect('activate', () => {
+            if (this._filterEntry.text.trim().length == 0)
+                return;
+
+            let [selected, model, iter] = this._list.get_selection().get_selected();
+            if (selected)
+                this._toggleChecked(this._list.model.get_path(iter));
+        });
 
         this._list.connect('row-activated', (view, path, column) => {
             this._toggleChecked(path);
@@ -247,6 +257,19 @@ const ServerRoomList = new Lang.Class({
         this._store.set_value(this._customRoomItem, RoomListColumn.NAME, newName);
     },
 
+    _updateSelection: function() {
+        if (this._filterEntry.text.trim().length == 0)
+            return;
+
+        let model = this._list.model;
+        let [valid, iter] = model.get_iter_first();
+        if (!valid)
+            return;
+
+        this._list.get_selection().select_iter(iter);
+        this._list.scroll_to_cell(model.get_path(iter), null, true, 0.0, 0.0);
+    },
+
     _clearList: function() {
         let [valid, iter] = this._store.get_iter_first();
         if (this._isCustomRoomItem(iter))


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