blam r545 - in trunk: . src



Author: cmartin
Date: Wed Apr 16 15:04:06 2008
New Revision: 545
URL: http://svn.gnome.org/viewvc/blam?rev=545&view=rev

Log:
Use a TreeCellDataFunc to automatically set the channel name and weight.

This is what is already done to set the unread/total number of items and
simplifies code, deleting duplicated logic.


Modified:
   trunk/ChangeLog
   trunk/src/ChannelList.cs

Modified: trunk/src/ChannelList.cs
==============================================================================
--- trunk/src/ChannelList.cs	(original)
+++ trunk/src/ChannelList.cs	Wed Apr 16 15:04:06 2008
@@ -44,9 +44,8 @@
             cell = new CellRendererText();
 
             nameColumn.PackStart(cell, true);
-            nameColumn.AddAttribute (cell, "text", 1);
-            nameColumn.AddAttribute (cell, "weight", 2);
             nameColumn.Sizing = TreeViewColumnSizing.Autosize;
+            nameColumn.SetCellDataFunc(cell, new TreeCellDataFunc(NamesCellDataFunc));
 
             AppendColumn(nameColumn);
 
@@ -65,8 +64,7 @@
             selectionChangedHandler = new EventHandler(SelectionChanged);
             this.Selection.Changed += selectionChangedHandler;
 
-            this.Model = new ListStore (typeof(Channel), 
-                                        typeof(string), typeof (int));
+            this.Model = new ListStore (typeof(Channel));
             this.HeadersVisible = false;
 
             // Sort the list
@@ -99,13 +97,7 @@
 
         public void Add (Channel channel)
         {
-            int weight = (int)Pango.Weight.Normal;
-
-            if (channel.NrOfUnreadItems > 0) {
-                weight = (int)Pango.Weight.Bold;
-            }
-
-            ((ListStore)this.Model).AppendValues(channel, channel.Name, weight);
+            ((ListStore)this.Model).AppendValues(channel);
         }
 
         public Channel GetSelected ()
@@ -125,18 +117,6 @@
             TreeIter iter = FindChannel (channel);
 
             if (!iter.Equals(TreeIter.Zero)) {
-                int weight = (int)Pango.Weight.Normal;
-
-                if (channel.NrOfUnreadItems > 0) {
-                    weight = (int)Pango.Weight.Bold;
-                }
-
-                string oldName = (string) this.Model.GetValue (iter, 1);
-                if (oldName != channel.Name) {
-                    this.Model.SetValue (iter, 1, channel.Name);
-                }
-                this.Model.SetValue (iter, 2, weight);
-
                 this.Model.EmitRowChanged (this.Model.GetPath(iter), iter);
             }
         }
@@ -288,6 +268,19 @@
             }
         }
 
+        private void NamesCellDataFunc(TreeViewColumn col, CellRenderer cell, TreeModel model, TreeIter iter)
+        {
+            Channel channel = model.GetValue(iter, 0) as Channel;
+            int weight = (int)Pango.Weight.Normal;
+
+            (cell as CellRendererText).Text = channel.Name;
+            if(channel.NrOfUnreadItems > 0){
+                weight = (int)Pango.Weight.Bold;
+            }
+
+            (cell as CellRendererText).Weight = weight;
+        }
+
         private void ItemsCellDataFunc(TreeViewColumn col,
                                        CellRenderer   cell,
                                        TreeModel      model,



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