[polari/wip/fmuellner/roomlist-filtering: 10/12] serverRoomList: Include custom room item in list
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/roomlist-filtering: 10/12] serverRoomList: Include custom room item in list
- Date: Mon, 13 Mar 2017 02:51:40 +0000 (UTC)
commit 906c54c780ec3fa4760a14f442371542e0c21d00
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Mar 11 01:44:45 2017 +0100
serverRoomList: Include custom room item in list
While creating new rooms (by joining a non-existent room) isn't a very
common operation, allowing users to enter a custom room name is still
important, as it means they can join rooms while the list hasn't been
loaded yet.
To account for that case, include an additional row in the list that
uses the current filter text as room name.
data/resources/server-room-list.ui | 6 ++++
src/serverRoomManager.js | 49 ++++++++++++++++++++++++++++++------
2 files changed, 47 insertions(+), 8 deletions(-)
---
diff --git a/data/resources/server-room-list.ui b/data/resources/server-room-list.ui
index fb117c7..8bdc74e 100644
--- a/data/resources/server-room-list.ui
+++ b/data/resources/server-room-list.ui
@@ -11,6 +11,12 @@
<!-- column-name sensitive -->
<column type="gboolean"/>
</columns>
+ <data>
+ <row>
+ <col id="2">+</col>
+ <col id="3">True</col>
+ </row>
+ </data>
</object>
<object class="GtkTreeModelFilter" id="modelFilter">
<property name="child-model">store</property>
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index 9d479ac..4548f47 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -140,9 +140,18 @@ const ServerRoomList = new Lang.Class({
if (!name)
return false;
+ if (this._isCustomRoomItem(iter))
+ return true;
+
return this._filterTerms.every((term) => name.indexOf(term) != -1);
});
+ [, this._customRoomItem] = this._store.get_iter_first();
+ this._list.model.refilter();
+
+ this._filterEntry.connect('changed', () => {
+ this._updateCustomRoomName();
+ });
this._filterEntry.connect('search-changed', () => {
if (!Utils.updateTerms(this._filterTerms, this._filterEntry.text))
return;
@@ -197,7 +206,7 @@ const ServerRoomList = new Lang.Class({
this._account = account;
this._pendingInfos = [];
- this._store.clear();
+ this._clearList();
this._filterEntry.set_text('');
this._onLoadingChanged(this._manager, account);
},
@@ -206,6 +215,29 @@ const ServerRoomList = new Lang.Class({
this._filterEntry.grab_focus();
},
+ _isCustomRoomItem: function(iter) {
+ let path = this._store.get_path(iter);
+ let customPath = this._store.get_path(this._customRoomItem);
+ return path.compare(customPath) == 0;
+ },
+
+ _updateCustomRoomName: function() {
+ let newName = this._filterEntry.text.trim();
+ if (newName.search(/\s/) != -1)
+ newName = '';
+
+ this._store.set_value(this._customRoomItem, RoomListColumn.NAME, newName);
+ },
+
+ _clearList: function() {
+ let [valid, iter] = this._store.get_iter_first();
+ if (this._isCustomRoomItem(iter))
+ return;
+ this._store.move_before(this._customRoomItem, iter);
+ while (this._store.remove(iter))
+ ;
+ },
+
_onLoadingChanged: function(mgr, account) {
if (account != this._account)
return;
@@ -215,7 +247,7 @@ const ServerRoomList = new Lang.Class({
if (this.loading)
return;
- this._store.clear();
+ this._clearList();
if (this._idleId)
Mainloop.source_remove(this._idleId);
@@ -250,12 +282,13 @@ const ServerRoomList = new Lang.Class({
let checked = !sensitive;
let count = '%d'.format(roomInfo.get_members_count(null));
- store.insert_with_valuesv(-1,
- [RoomListColumn.CHECKED,
- RoomListColumn.NAME,
- RoomListColumn.COUNT,
- RoomListColumn.SENSITIVE],
- [checked, name, count, sensitive]);
+ let iter = store.insert_with_valuesv(-1,
+ [RoomListColumn.CHECKED,
+ RoomListColumn.NAME,
+ RoomListColumn.COUNT,
+ RoomListColumn.SENSITIVE],
+ [checked, name, count, sensitive]);
+ store.move_before(iter, this._customRoomItem);
});
if (this._pendingInfos.length)
return GLib.SOURCE_CONTINUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]