[smuxi/experiments/user_count_in_title: 4/4] Frontend-GNOME: use 1/6 width as default size for user list and adapt with window resize (closes: #9



commit 7dca4da78806cf1780ac17c07067686313d230f6
Author: Mirco Bauer <meebey meebey net>
Date:   Sun May 11 17:33:14 2014 +0200

    Frontend-GNOME: use 1/6 width as default size for user list and adapt with window resize (closes: #917)
    
    This fixes the bug mentioned in 32885265bd04e667b0c94caab64ee1d3b6056556

 src/Frontend-GNOME/MainWindow.cs                |   21 +++++++++-
 src/Frontend-GNOME/Views/Chats/GroupChatView.cs |   49 ++++++-----------------
 2 files changed, 32 insertions(+), 38 deletions(-)
---
diff --git a/src/Frontend-GNOME/MainWindow.cs b/src/Frontend-GNOME/MainWindow.cs
index 4cd9365..f8ef746 100644
--- a/src/Frontend-GNOME/MainWindow.cs
+++ b/src/Frontend-GNOME/MainWindow.cs
@@ -69,6 +69,7 @@ namespace Smuxi.Frontend.Gnome
         public NotificationAreaIconMode NotificationAreaIconMode { get; set; }
         public bool IsMinimized { get; private set; }
         public bool IsMaximized { get; private set; }
+        public int WindowWidth { get; private set; }
 
         public bool CaretMode {
             get {
@@ -390,7 +391,8 @@ namespace Smuxi.Frontend.Gnome
         {
             Trace.Call(e);
 
-            TreeViewHPaned.Position = e.Width / 6;
+            WindowWidth = e.Width;
+            CheckLayout();
             return base.OnConfigureEvent(e);
         }
 
@@ -520,6 +522,10 @@ namespace Smuxi.Frontend.Gnome
 #if LOG4NET
                     f_Logger.Debug("OnWindowStateEvent(): IsMaximized: " + IsMaximized);
 #endif
+                    GLib.Idle.Add(() => {
+                        CheckLayout();
+                        return false;
+                    });
                 }
             } catch (Exception ex) {
                 Frontend.ShowException(this, ex);
@@ -599,6 +605,7 @@ namespace Smuxi.Frontend.Gnome
                     }
                     UpdateTitle(groupChatView, null);
                 };
+                groupChatView.OutputHPaned.Position = (WindowWidth / 6) * 4;
             }
             UpdateProgressBar();
         }
@@ -645,6 +652,18 @@ namespace Smuxi.Frontend.Gnome
             }
         }
 
+        void CheckLayout()
+        {
+            TreeViewHPaned.Position = WindowWidth / 6;
+            foreach (var chat in ChatViewManager.Chats) {
+                if (!(chat is GroupChatView)) {
+                    continue;
+                }
+                var groupChat = (GroupChatView) chat;
+                groupChat.OutputHPaned.Position = (WindowWidth / 6) * 4;
+            }
+        }
+
         private static string _(string msg)
         {
             return Mono.Unix.Catalog.GetString(msg);
diff --git a/src/Frontend-GNOME/Views/Chats/GroupChatView.cs b/src/Frontend-GNOME/Views/Chats/GroupChatView.cs
index 8964930..1439168 100644
--- a/src/Frontend-GNOME/Views/Chats/GroupChatView.cs
+++ b/src/Frontend-GNOME/Views/Chats/GroupChatView.cs
@@ -112,6 +112,12 @@ namespace Smuxi.Frontend.Gnome
             }
         }
 
+        public Gtk.HPaned OutputHPaned {
+            get {
+                return _OutputHPaned;
+            }
+        }
+
         static GroupChatView()
         {
             IconPixbuf = Frontend.LoadIcon(
@@ -128,16 +134,6 @@ namespace Smuxi.Frontend.Gnome
             // person list
             Participants = new List<PersonModel>();
             _OutputHPaned = new Gtk.HPaned();
-            _OutputHPaned.ButtonPressEvent += (sender, e) => {;
-                // reset person list size on double click
-                if (e.Event.Type == Gdk.EventType.TwoButtonPress &&
-                    e.Event.Button == 1) {
-                    GLib.Timeout.Add(200, delegate {
-                        _OutputHPaned.Position = -1;
-                        return false;
-                    });
-                }
-            };
 
             Gtk.TreeView tv = new Gtk.TreeView();
             _PersonTreeView = tv;
@@ -145,29 +141,6 @@ namespace Smuxi.Frontend.Gnome
             PersonScrolledWindow = sw;
             sw.ShadowType = Gtk.ShadowType.None;
             sw.HscrollbarPolicy = Gtk.PolicyType.Never;
-            sw.SizeRequested += (o, args) => {
-                // predict and set useful treeview width
-                var persons = SyncedPersons;
-                if (persons == null || persons.Count == 0) {
-                    return;
-                }
-
-                int longestNameWidth = 0;
-                foreach (var person in persons.Values) {
-                    int lineWidth, lineHeigth;
-                    using (var layout = _PersonTreeView.CreatePangoLayout(person.IdentityName)) {
-                        layout.GetPixelSize(out lineWidth, out lineHeigth);
-                    }
-                    if (lineWidth > longestNameWidth) {
-                        longestNameWidth = lineWidth;
-                    }
-                }
-
-                var bestSize = new Gtk.Requisition() {
-                    Width = longestNameWidth
-                };
-                args.Requisition = bestSize;
-            };
 
             //tv.CanFocus = false;
             tv.BorderWidth = 0;
@@ -175,12 +148,15 @@ namespace Smuxi.Frontend.Gnome
             sw.Add(tv);
             
             Gtk.TreeViewColumn column;
-            Gtk.CellRendererText cellr = new Gtk.CellRendererText();
+            var cellr = new Gtk.CellRendererText() {
+                Ellipsize = Pango.EllipsizeMode.End
+            };
             IdentityNameCellRenderer = cellr;
             column = new Gtk.TreeViewColumn(String.Empty, cellr);
             column.SortColumnId = 0;
             column.Spacing = 0;
             column.SortIndicator = false;
+            column.Expand = true;
             column.Sizing = Gtk.TreeViewColumnSizing.Autosize;
             // FIXME: this callback leaks memory
             column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(RenderPersonIdentityName));
@@ -367,7 +343,6 @@ namespace Smuxi.Frontend.Gnome
                 _PersonTreeView.Model = ls;
                 _PersonTreeView.SearchColumn = 0;
 
-                PersonScrolledWindow.CheckResize();
                 OnParticipantsChanged(EventArgs.Empty);
 
                 // TRANSLATOR: this string will be appended to the one above
@@ -548,8 +523,8 @@ namespace Smuxi.Frontend.Gnome
                 _OutputHPaned.Pack1(_PersonTreeViewFrame, false, true);
                 _OutputHPaned.Pack2(_OutputVBox, true, true);
             } else if (userlist_pos == "right") {
-                _OutputHPaned.Pack1(_OutputVBox, true, true);
-                _OutputHPaned.Pack2(_PersonTreeViewFrame, false, true);
+                _OutputHPaned.Pack1(_OutputVBox, true, false);
+                _OutputHPaned.Pack2(_PersonTreeViewFrame, false, false);
             } else if (userlist_pos == "none") {
                 _OutputHPaned.Pack1(_OutputVBox, true, true);
             } else {


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