[blam/gtk-builder] FeedList: react to subchannel removals



commit f8c025b0864d2086d53c3671bd32047e32899459
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Wed Oct 9 16:40:04 2013 +0200

    FeedList: react to subchannel removals

 src/Channel.cs      |    6 ++++--
 src/ChannelGroup.cs |    9 +++++++++
 src/ChannelList.cs  |   28 ++++++++++++++++++++++++----
 3 files changed, 37 insertions(+), 6 deletions(-)
---
diff --git a/src/Channel.cs b/src/Channel.cs
index 5c53b37..7cf93f2 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -92,7 +92,8 @@ namespace Imendio.Blam {
             get {
                                lock (items) {
                                        return items
-                                               .Select(id => ItemStore.Get(id))
+                                               .Select(ItemStore.Get)
+                                               .Where(i => i != null)
                                                .Count(item => item.Unread);
                                }
             }
@@ -102,7 +103,8 @@ namespace Imendio.Blam {
             get {
                 lock(items){
                                        return items
-                                               .Select(id => ItemStore.Get(id))
+                                               .Select(ItemStore.Get)
+                                               .Where(i => i != null)
                                                .Count(item => item.Unread && !item.Old);
                                }
             }
diff --git a/src/ChannelGroup.cs b/src/ChannelGroup.cs
index df4968b..d9ebda1 100644
--- a/src/ChannelGroup.cs
+++ b/src/ChannelGroup.cs
@@ -78,6 +78,13 @@ namespace Imendio.Blam
             }
         }
 
+               public void OnCollectionChanged(NotifyCollectionChangedAction action, Channel channel)
+               {
+                       if (CollectionChanged != null) {
+                               CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, 
channel));
+                       }
+               }
+
                public void Add(Channel chan)
                {
                        foreach(Channel ch in Channels){
@@ -89,11 +96,13 @@ namespace Imendio.Blam
                                chan.Name = chan.Url;
 
                        Channels.Add(chan);
+                       OnCollectionChanged(NotifyCollectionChangedAction.Add, chan);
                }
 
                public void Remove(Channel channel)
                {
                        Channels.Remove(channel);
+                       OnCollectionChanged(NotifyCollectionChangedAction.Remove, channel);
                }
 
                public void RemoveItems()
diff --git a/src/ChannelList.cs b/src/ChannelList.cs
index 7bce0b5..7419ae7 100644
--- a/src/ChannelList.cs
+++ b/src/ChannelList.cs
@@ -9,6 +9,7 @@ using Gdk;
 using Gtk;
 using GtkSharp;
 using System;
+using System.Linq;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Specialized;
@@ -70,14 +71,29 @@ namespace Blam
 
                void removeCurrent()
                {
-                       var chan = GetSelected();
+                       TreeIter  iter, parent;
+                       bool hasParent;
+                       TreeModel model;
+
+                       if (!this.Selection.GetSelected(out model, out iter)) {
+                               return;
+                       }
+
+                       var chan = (IChannel)model.GetValue(iter, 0);
+
+                       hasParent = Model.IterParent(out parent, iter);
+
                        using (var dialog = new RemoveChannelDialog(MainWindow, chan))
                        {
                                if (dialog.Run()) {
-                                       if (chan is Channel)
+                                       if (hasParent) {
+                                               var grp = (ChannelGroup)model.GetValue(parent, 0);
+                                               grp.Remove((Channel)chan);
+                                       } else if (chan is Channel) {
                                                channels.Remove((Channel)chan);
-                                       else
+                                       } else {
                                                groups.Remove((ChannelGroup)chan);
+                                       }
                                }
                        }
                }
@@ -107,9 +123,13 @@ namespace Blam
 
                        var model = Model as TreeStore;
 
+                       var subchanges = Observable.Merge(
+                               groups.Select(grp => 
Observable.FromEventPattern<NotifyCollectionChangedEventArgs>(grp, "CollectionChanged")));
                        var changes = Observable.Merge(
                                Observable.FromEventPattern<NotifyCollectionChangedEventArgs>(channels, 
"CollectionChanged"),
-                               Observable.FromEventPattern<NotifyCollectionChangedEventArgs>(groups, 
"CollectionChanged"));
+                               Observable.FromEventPattern<NotifyCollectionChangedEventArgs>(groups, 
"CollectionChanged"))
+                               .Merge(subchanges);
+
 
                        var additions = changes.Where(x => x.EventArgs.Action == 
NotifyCollectionChangedAction.Add)
                                .SelectMany(x => enumerateChannels(x.EventArgs.NewItems));


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