[polari/user-list-update: 4/5] userList: Add UserListRow class
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/user-list-update: 4/5] userList: Add UserListRow class
- Date: Fri, 4 Oct 2013 10:17:53 +0000 (UTC)
commit c63494d2b32c65a7aa6d69d9b5c4645637cb4571
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Oct 3 23:03:58 2013 +0200
userList: Add UserListRow class
src/userList.js | 50 +++++++++++++++++++++++++++++++-------------------
1 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index 47ce4f5..627011d 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -103,6 +103,27 @@ const UserListSidebar = new Lang.Class({
}
});
+const UserListRow = new Lang.Class({
+ Name: 'UserListRow',
+
+ _init: function(user) {
+ this._createWidget(user);
+
+ this.widget.user = user;
+ },
+
+ _createWidget: function(user) {
+ this.widget = new Gtk.ListBoxRow();
+ let box = new Gtk.Box({ margin: 4, spacing: 4 });
+ box.add(new Gtk.Image({ icon_name: 'avatar-default-symbolic' }));
+ box.add(new Gtk.Label({ label: user.alias,
+ halign: Gtk.Align.START,
+ ellipsize: Pango.EllipsizeMode.END }));
+ this.widget.add(box);
+ this.widget.show_all();
+ }
+});
+
const UserList = new Lang.Class({
Name: 'UserList',
@@ -119,6 +140,7 @@ const UserList = new Lang.Class({
this._list.set_sort_func(Lang.bind(this, this._sort));
this._room = room;
+ this._rows = {};
room.connect('member-renamed',
Lang.bind(this, this._onMemberRenamed));
@@ -159,36 +181,26 @@ const UserList = new Lang.Class({
},
_addMember: function(member) {
- let row = new Gtk.ListBoxRow();
- row._member = member;
- let box = new Gtk.Box({ margin: 4, spacing: 4 });
- box.add(new Gtk.Image({ icon_name: 'avatar-default-symbolic' }));
- box.add(new Gtk.Label({ label: member.alias,
- halign: Gtk.Align.START,
- ellipsize: Pango.EllipsizeMode.END }));
- row.add(box);
- row.show_all();
- this._list.add(row);
+ let row = new UserListRow(member);
+ this._rows[member.alias] = row;
+ this._list.add(row.widget);
},
_removeMember: function(member) {
- let rows = this._list.get_children();
- for (let i = 0; i < rows.length; i++) {
- if (rows[i]._member != member)
- continue;
- this._list.remove(rows[i]);
- break;
- }
+ let row = this._rows[member.alias];
+ if (row.widget.get_parent())
+ this._list.remove(row.widget);
+ delete this._rows[member.alias];
},
_sort: function(row1, row2) {
- return (row1._member.alias < row2._member.alias) ? -1 : 1;
+ return (row1.user.alias < row2.user.alias) ? -1 : 1;
},
_filterRows: function(row) {
if (!this._filter)
return true;
- return row._member.alias.indexOf(this._filter) != -1;
+ return row.user.alias.indexOf(this._filter) != -1;
},
_updateHeader: function(row, before) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]