[banshee] Add some more features to DictionaryComboBox



commit 75f5d9a1b2b5496614e7182f79dee93378c50601
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Mon Dec 14 16:01:47 2009 -0800

    Add some more features to DictionaryComboBox

 .../Banshee.Widgets/DictionaryComboBox.cs          |   81 +++++++++++++-------
 1 files changed, 54 insertions(+), 27 deletions(-)
---
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/DictionaryComboBox.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/DictionaryComboBox.cs
index 59d00e3..8f13772 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/DictionaryComboBox.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/DictionaryComboBox.cs
@@ -34,20 +34,45 @@ namespace Banshee.Widgets
     public class DictionaryComboBox<T> : ComboBox
     {
         private ListStore store;
+        private int row;
 
-        public DictionaryComboBox()
+        public DictionaryComboBox ()
         {
-            store = new ListStore(typeof(string), typeof(T));
+            store = new ListStore (typeof (string), typeof (T), typeof (int));
+            store.SetSortColumnId (2, SortType.Ascending);
             Model = store;
 
-            CellRendererText text_renderer = new CellRendererText();
-            PackStart(text_renderer, true);
-            AddAttribute(text_renderer, "text", 0);
+            CellRendererText text_renderer = new CellRendererText ();
+            PackStart (text_renderer, true);
+            AddAttribute (text_renderer, "text", 0);
         }
 
-        public TreeIter Add(string key, T value)
+        public TreeIter Add (string str, T value)
         {
-            return store.AppendValues(key, value);
+            return store.AppendValues (str, value, row++);
+        }
+
+        public TreeIter Add (T value, string str, int order)
+        {
+            return store.AppendValues (str, value, order);
+        }
+
+        public bool Remove (T value)
+        {
+            var iter = IterFor (value);
+            return store.Remove (ref iter);
+        }
+
+        public bool Remove (ref TreeIter iter)
+        {
+            return store.Remove (ref iter);
+        }
+
+        public void Update (T value, string str, int order)
+        {
+            var iter = IterFor (value);
+            store.SetValue (iter, 0, str);
+            store.SetValue (iter, 2, order);
         }
 
         public new void Clear ()
@@ -55,33 +80,35 @@ namespace Banshee.Widgets
             store.Clear ();
         }
 
-        public T ActiveValue {
-            get {
+        private TreeIter IterFor (T val)
+        {
+            if (val == null) {
+                return TreeIter.Zero;
+            }
+
+            for (int i = 0, n = store.IterNChildren (); i < n; i++) {
                 TreeIter iter;
-                if(GetActiveIter(out iter)) {
-                    return (T)store.GetValue(iter, 1);
+                if (store.IterNthChild (out iter, i)) {
+                    T compare = (T)store.GetValue (iter, 1);
+                    if (val.Equals (compare)) {
+                        return iter;
+                    }
                 }
-
-                return default(T);
             }
 
-            set {
-                if(value == null) {
-                    SetActiveIter(TreeIter.Zero);
-                    return;
-                }
+            return TreeIter.Zero;
+        }
 
-                for(int i = 0, n = store.IterNChildren(); i < n; i++) {
-                    TreeIter iter;
-                    if(store.IterNthChild(out iter, i)) {
-                        T compare = (T)store.GetValue(iter, 1);
-                        if(value.Equals(compare)) {
-                            SetActiveIter(iter);
-                            return;
-                        }
-                    }
+        public T ActiveValue {
+            get {
+                TreeIter iter;
+                if (GetActiveIter (out iter)) {
+                    return (T)store.GetValue (iter, 1);
                 }
+
+                return default (T);
             }
+            set { SetActiveIter (IterFor (value)); }
         }
     }
 }



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