[polari] userList: Add UserListSidebar class
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] userList: Add UserListSidebar class
- Date: Mon, 14 Oct 2013 20:12:39 +0000 (UTC)
commit e3a4c118025e57c516ffa0d11b15aa73e3b4b790
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Oct 2 23:46:41 2013 +0200
userList: Add UserListSidebar class
We will start to add more functionality to the sidebar, so split out
a dedicated class instead of managing it entirely from MainWindow.
data/resources/main-window.ui | 13 +---------
src/mainWindow.js | 17 ++++----------
src/userList.js | 49 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+), 23 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index ac3ffe9..ef3e5a5 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -351,7 +351,7 @@
<property name="hexpand">False</property>
<property name="transition_type">slide-left</property>
<child>
- <object class="PolariFixedSizeFrame" id="frame2">
+ <object class="PolariFixedSizeFrame" id="user_list_sidebar">
<property name="visible">True</property>
<property name="hexpand">False</property>
<property name="width">200</property>
@@ -361,16 +361,7 @@
<class name="polari-user-list"/>
</style>
<child>
- <object class="GtkStack" id="user_list_stack">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hexpand">True</property>
- <property name="halign">fill</property>
- <property name="transition_type">crossfade</property>
- <child>
- <placeholder/>
- </child>
- </object>
+ <placeholder/>
</child>
</object>
</child>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 15b827c..dd4f91a 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -83,7 +83,9 @@ const MainWindow = new Lang.Class({
this._roomList = new RoomList.RoomList();
scroll.add(this._roomList.widget);
- this._userListStack = builder.get_object('user_list_stack');
+ let sidebar = builder.get_object('user_list_sidebar');
+ this._userListSidebar = new UserList.UserListSidebar();
+ sidebar.add(this._userListSidebar.widget);
let revealer = builder.get_object('user_list_revealer');
app.connect('action-state-changed::user-list', Lang.bind(this,
@@ -259,22 +261,14 @@ const MainWindow = new Lang.Class({
_roomAdded: function(roomManager, room) {
- let userList;
let chatView = new ChatView.ChatView(room);
+ this._rooms[room.id] = chatView;
- if (room.channel.handle_type == Tp.HandleType.ROOM)
- userList = new UserList.UserList(room);
- else
- userList = { widget: new Gtk.Label() };
-
- this._rooms[room.id] = [chatView, userList];
-
- this._userListStack.add_named(userList.widget, room.id);
this._chatStack.add_named(chatView.widget, room.id);
},
_roomRemoved: function(roomManager, room) {
- this._rooms[room.id].forEach(function(w) { w.widget.destroy(); });
+ this._rooms[room.id].widget.destroy();
delete this._rooms[room.id];
},
@@ -315,7 +309,6 @@ const MainWindow = new Lang.Class({
this._updateNick));
this._chatStack.set_visible_child_name(this._room.id);
- this._userListStack.set_visible_child_name(this._room.id);
},
_setNick: function(nick) {
diff --git a/src/userList.js b/src/userList.js
index 0287829..3832e13 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -1,9 +1,58 @@
const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;
const Pango = imports.gi.Pango;
+const Tp = imports.gi.TelepathyGLib;
+const ChatroomManager = imports.chatroomManager;
const Lang = imports.lang;
+const UserListSidebar = new Lang.Class({
+ Name: 'UserListSidebar',
+
+ _init: function() {
+ this._createWidget();
+
+ this._rooms = {};
+
+ this._roomManager = new ChatroomManager.getDefault();
+ this._roomManager.connect('room-added',
+ Lang.bind(this, this._roomAdded));
+ this._roomManager.connect('room-removed',
+ Lang.bind(this, this._roomRemoved));
+ this._roomManager.connect('active-changed',
+ Lang.bind(this, this._activeRoomChanged));
+ },
+
+ _createWidget: function() {
+ this.widget = new Gtk.Stack({ hexpand: true, visible: true });
+ this.widget.transition_type = Gtk.StackTransitionType.CROSSFADE;
+ },
+
+ _roomAdded: function(roomManager, room) {
+ if (room.channel.handle_type != Tp.HandleType.ROOM)
+ return;
+
+ let userList = new UserList(room);
+ this._rooms[room.id] = userList;
+
+ this.widget.add_named(userList.widget, room.id);
+ },
+
+ _roomRemoved: function(roomManager, room) {
+ if (!this._rooms[room.id])
+ return;
+ this._rooms[room.id].widget.destroy();
+ delete this._rooms[room.id];
+ },
+
+ _activeRoomChanged: function(manager, room) {
+ if (!room || !this._rooms[room.id])
+ return;
+ this.widget.set_visible_child_name(room.id);
+ },
+
+});
+
const UserList = new Lang.Class({
Name: 'UserList',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]