blam r664 - trunk/src



Author: cmartin
Date: Fri Oct 10 12:38:25 2008
New Revision: 664
URL: http://svn.gnome.org/viewvc/blam?rev=664&view=rev

Log:
Implement removing from a group.

There is a lot of duplicate code and we return null at times.

Modified:
   trunk/src/ChannelList.cs

Modified: trunk/src/ChannelList.cs
==============================================================================
--- trunk/src/ChannelList.cs	(original)
+++ trunk/src/ChannelList.cs	Fri Oct 10 12:38:25 2008
@@ -405,10 +405,11 @@
                                     "gtk-remove",
                                     new EventHandler (EmitRemoveCb), true);
             popup_menu.Append(BuildGroupMenu());
+            popup_menu.Append(BuildRemoveFromGroupMenu());
             popup_menu.Popup (null, null, null, 
                               eb.Button, eb.Time);
-        }
-
+        }        
+        
         private Gtk.MenuItem BuildGroupMenu()
         {
             MenuItem item = new MenuItem(Catalog.GetString("M_ove to group"));
@@ -452,6 +453,57 @@
             //Application.TheApp.CCollection.Remove(chan as IChannel);
         }
 
+        Gtk.MenuItem BuildRemoveFromGroupMenu()
+        {
+            bool ingroup = false;
+            TreeModel model;
+            TreeIter iter;
+            Application.TheApp.ChannelList.Selection.GetSelected(out model, out iter);
+            Channel lookfor = (model as TreeStore).GetValue(iter, 0) as Channel;
+            
+            foreach(ChannelGroup group in Application.TheApp.CCollection.Groups){
+                foreach(Channel chan in group.Channels){
+                    if(chan == lookfor){
+                        ingroup = true;
+                        break;
+                    }
+                }
+            }
+            
+            if(ingroup == true){
+                MenuItem item = new MenuItem("Remove from _Group");
+                item.Sensitive = true;
+                item.Activated += RemoveChannelFromGroupCb;
+                item.Show();
+                
+                return item;
+            }
+            
+            return null;
+        }
+        
+        public void RemoveChannelFromGroupCb(object obj, EventArgs args)
+        {
+            ChannelGroup ingroup = null;
+
+            TreeModel model;
+            TreeIter iter;
+            Application.TheApp.ChannelList.Selection.GetSelected(out model, out iter);
+            Channel lookfor = (model as TreeStore).GetValue(iter, 0) as Channel;
+           
+            foreach(ChannelGroup group in Application.TheApp.CCollection.Groups){
+                foreach(Channel chan in group.Channels){
+                    if(chan == lookfor){
+                        ingroup = group;
+                        break;
+                    }
+                }
+            }
+            
+            lookfor.Iter = (model as TreeStore).AppendValues(lookfor as IChannel);
+            (model as TreeStore).Remove(ref iter);
+        }
+
         public void EmitMarkAsReadCb (object obj, EventArgs args)
         {
             if (MarkAsReadSelected != null) {



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