[polari] roomStack: Use a single stack for chat view and entry area



commit 894527c90e45b180cebdad3706fb1bd06635ddf9
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Feb 28 19:20:34 2014 +0100

    roomStack: Use a single stack for chat view and entry area
    
    Since we now use one input area per room, it makes sense to combine
    it with the chat log and use a single stack to switch between rooms.

 data/resources/main-window.ui |   81 +++++++-----------------------------
 src/Makefile.am               |    1 +
 src/chatView.js               |    2 +-
 src/mainWindow.js             |   40 ++----------------
 src/roomStack.js              |   91 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 113 insertions(+), 102 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 631a77c..443ab71 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -315,84 +315,36 @@
           </packing>
         </child>
         <child>
-          <object class="GtkBox" id="box3">
+          <object class="GtkOverlay" id="overlay">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="hexpand">True</property>
-            <property name="orientation">vertical</property>
+            <property name="vexpand">True</property>
             <child>
-              <object class="GtkOverlay" id="overlay">
+              <placeholder/>
+            </child>
+            <child type="overlay">
+              <object class="GtkRevealer" id="user_list_revealer">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="vexpand">True</property>
+                <property name="halign">end</property>
+                <property name="hexpand">False</property>
+                <property name="transition_type">slide-left</property>
                 <child>
-                  <object class="GtkFrame" id="frame3">
+                  <object class="PolariFixedSizeFrame" id="user_list_sidebar">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="hexpand">False</property>
+                    <property name="width">200</property>
                     <style>
-                      <class name="polari-chat-stack"/>
+                      <class name="sidebar"/>
+                      <class name="polari-sidebar"/>
+                      <class name="polari-user-list"/>
                     </style>
                     <child>
-                      <object class="GtkStack" id="chat_stack">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="transition_type">crossfade</property>
-                        <child>
-                          <placeholder/>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child type="overlay">
-                  <object class="GtkRevealer" id="user_list_revealer">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="halign">end</property>
-                    <property name="hexpand">False</property>
-                    <property name="transition_type">slide-left</property>
-                    <child>
-                      <object class="PolariFixedSizeFrame" id="user_list_sidebar">
-                        <property name="visible">True</property>
-                        <property name="hexpand">False</property>
-                        <property name="width">200</property>
-                        <style>
-                          <class name="sidebar"/>
-                          <class name="polari-sidebar"/>
-                          <class name="polari-user-list"/>
-                        </style>
-                        <child>
-                          <placeholder/>
-                        </child>
-                      </object>
+                      <placeholder/>
                     </child>
                   </object>
                 </child>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkFrame" id="main_input_area">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <style>
-                  <class name="polari-input-area"/>
-                </style>
-                <child>
-                  <object class="GtkStack" id="input_area_stack">
-                    <property name="visible">True</property>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
             </child>
           </object>
           <packing>
@@ -415,7 +367,6 @@
       <property name="mode">vertical</property>
       <widgets>
         <widget name="selection_toolbar"/>
-        <widget name="main_input_area"/>
       </widgets>
   </object>
 </interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 9b7f594..2e02534 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,6 +42,7 @@ dist_js_DATA = \
        notify.js \
        pasteManager.js \
        roomList.js \
+       roomStack.js \
        tabCompletion.js \
        userList.js \
        utils.js \
diff --git a/src/chatView.js b/src/chatView.js
index b8e154e..9f11626 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -210,7 +210,7 @@ const ChatView = new Lang.Class({
     },
 
     _createWidget: function() {
-        this.widget = new Gtk.ScrolledWindow();
+        this.widget = new Gtk.ScrolledWindow({ vexpand: true });
         this.widget.hscrollbar_policy = Gtk.PolicyType.NEVER;
         this.widget.resize_mode = Gtk.ResizeMode.QUEUE;
 
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 7475f91..22e2c7d 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -7,13 +7,12 @@ const Tp = imports.gi.TelepathyGLib;
 const AccountsMonitor = imports.accountsMonitor;
 const AppNotifications = imports.appNotifications;
 const ChatroomManager = imports.chatroomManager;
-const ChatView = imports.chatView;
-const EntryArea = imports.entryArea;
 const JoinDialog = imports.joinDialog;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const MessageDialog = imports.messageDialog;
 const RoomList = imports.roomList;
+const RoomStack = imports.roomStack;
 const UserList = imports.userList;
 const Utils = imports.utils;
 
@@ -44,10 +43,6 @@ const MainWindow = new Lang.Class({
                                       Lang.bind(this, this._onAccountChanged));
 
         this._roomManager = 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));
         this._roomManager.connect('active-state-changed',
@@ -186,26 +181,6 @@ const MainWindow = new Lang.Class({
             });
     },
 
-    _roomAdded: function(roomManager, room) {
-        let chatView = new ChatView.ChatView(room);
-        this._rooms[room.id] = chatView;
-
-        this._chatStack.add_named(chatView.widget, room.id);
-
-        let entryArea = new EntryArea.EntryArea(room);
-        this._entries[room.id] = entryArea;
-
-        this._inputStack.add_named(entryArea.widget, room.id);
-    },
-
-    _roomRemoved: function(roomManager, room) {
-        this._rooms[room.id].widget.destroy();
-        delete this._rooms[room.id];
-
-        this._entries[room.id].widget.destroy();
-        delete this._entries[room.id];
-    },
-
     _activeRoomChanged: function(manager, room) {
         if (this._room) {
             this._room.disconnect(this._displayNameChangedId);
@@ -221,9 +196,6 @@ const MainWindow = new Lang.Class({
 
         this._updateTitlebar();
 
-        this._inputStack.set_visible_child_name(this._room ? this._room.id
-                                                           : 'placeholder');
-
         if (!this._room)
             return; // finished
 
@@ -236,8 +208,6 @@ const MainWindow = new Lang.Class({
         this._membersChangedId =
             this._room.connect('members-changed',
                                Lang.bind(this, this._updateUserListLabel));
-
-        this._chatStack.set_visible_child_name(this._room.id);
     },
 
     _createWidget: function(app) {
@@ -248,6 +218,9 @@ const MainWindow = new Lang.Class({
         this.window.application = app;
 
         let overlay = builder.get_object('overlay');
+        let sizeGroup = builder.get_object('bottom_size_group');
+        this._roomStack = new RoomStack.RoomStack(sizeGroup);
+        overlay.add(this._roomStack.widget);
 
         this._titlebarRight = builder.get_object('titlebar_right');
         this._titlebarLeft = builder.get_object('titlebar_left');
@@ -259,11 +232,6 @@ const MainWindow = new Lang.Class({
         this._joinMenuButton = builder.get_object('join_menu_button');
         this._showUserListButton = builder.get_object('show_user_list_button');
         this._revealer = builder.get_object('room_list_revealer');
-        this._chatStack = builder.get_object('chat_stack');
-        this._inputStack = builder.get_object('input_area_stack');
-
-        let placeholderEntry = new EntryArea.EntryArea(null);
-        this._inputStack.add_named(placeholderEntry.widget, 'placeholder');
 
         let scroll = builder.get_object('room_list_scrollview');
         this._roomList = new RoomList.RoomList();
diff --git a/src/roomStack.js b/src/roomStack.js
new file mode 100644
index 0000000..1f7629c
--- /dev/null
+++ b/src/roomStack.js
@@ -0,0 +1,91 @@
+const Gtk = imports.gi.Gtk;
+
+const ChatroomManager = imports.chatroomManager;
+const ChatView = imports.chatView;
+const EntryArea = imports.entryArea;
+const Lang = imports.lang;
+
+const RoomStack = new Lang.Class({
+    Name: 'RoomStack',
+
+    _init: function(inputSizeGroup) {
+        this._inputSizeGroup = inputSizeGroup;
+
+        this._createWidget();
+
+        this._roomManager = 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));
+
+        this._rooms = {};
+
+        this._addView('placeholder', new RoomView(null));
+    },
+
+    _addView: function(id, view) {
+        this._rooms[id] = view;
+
+        this._inputSizeGroup.add_widget(view.inputWidget);
+        this._stack.add_named(view.widget, id);
+    },
+
+    _roomAdded: function(roomManager, room) {
+        this._addView(room.id, new RoomView(room));
+    },
+
+    _roomRemoved: function(roomManager, room) {
+        this._rooms[room.id].widget.destroy();
+        delete this._rooms[room.id];
+    },
+
+    _activeRoomChanged: function(manager, room) {
+        this._stack.set_visible_child_name(room ? room.id : 'placeholder');
+        this._stack.transition_type = room ? Gtk.StackTransitionType.CROSSFADE
+                                           : Gtk.StackTransitionType.NONE;
+    },
+
+    _createWidget: function() {
+        this.widget = new Gtk.Frame();
+        this.widget.get_style_context().add_class('polari-chat-stack');
+
+        this._stack = new Gtk.Stack();
+        this.widget.add(this._stack);
+
+        this.widget.show_all();
+    }
+});
+
+const ChatPlaceholder = new Lang.Class({
+    Name: 'ChatPlaceholder',
+
+    _init: function() {
+        this.widget = new Gtk.Label({ vexpand: true });
+    }
+});
+
+const RoomView = new Lang.Class({
+    Name: 'RoomView',
+
+    _init: function(room) {
+        this._view = room ? new ChatView.ChatView(room)
+                          : new ChatPlaceholder();
+
+        this._entryArea = new EntryArea.EntryArea(room);
+
+        this.widget = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
+        this.widget.add(this._view.widget);
+
+        this.inputWidget = new Gtk.Frame();
+        this.inputWidget.get_style_context().add_class('polari-input-area');
+        this.widget.add(this.inputWidget);
+
+        this.inputWidget.add(this._entryArea.widget);
+
+        this.widget.show_all();
+    }
+});


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