[blam/gtk-builder] FeedList: wire up PropertyChanged with Rx



commit 9ad14b74f4e950a398efd14bd452516c094d604d
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Wed Oct 9 18:42:22 2013 +0200

    FeedList: wire up PropertyChanged with Rx

 src/ChannelList.cs |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/src/ChannelList.cs b/src/ChannelList.cs
index 7419ae7..b4c11aa 100644
--- a/src/ChannelList.cs
+++ b/src/ChannelList.cs
@@ -38,13 +38,6 @@ namespace Blam
                ObservableCollection<Channel> channels;
                ObservableCollection<ChannelGroup> groups;
 
-               void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
-               {
-                       var chan = (IChannel)sender;
-                       var sc = SynchronizationContext.Current;
-                       sc.Post((state) => Model.EmitRowChanged(Model.GetPath(chan.Iter), chan.Iter), null);
-               }
-
                IEnumerable<IChannel> enumerateChannels(IList chans)
                {
                        foreach (IChannel chan in chans)
@@ -138,29 +131,34 @@ namespace Blam
                                .SelectMany(x => enumerateChannels(x.EventArgs.OldItems));
 
                        additions.Subscribe(chan => {
-                               Gtk.TreeIter iter = (model as TreeStore).AppendValues(chan);
+                               Gtk.TreeIter iter = model.AppendValues(chan);
                                chan.Iter = iter;
                        });
 
                        removals.Subscribe(chan => {
                                var iter = chan.Iter;
-                               (model as TreeStore).Remove(ref iter);
+                               model.Remove(ref iter);
                        });
 
+                       var chanChanges = Observable
+                               .Merge(channels.Select(c => 
Observable.FromEventPattern<PropertyChangedEventArgs>(c, "PropertyChanged")))
+                               .Merge(Observable.Merge(groups.Select(grp => 
Observable.FromEventPattern<PropertyChangedEventArgs>(grp, "PropertyChanged"))))
+                               .Merge(Observable.Merge(groups.SelectMany(grp => grp.Channels.Select(c => 
Observable.FromEventPattern<PropertyChangedEventArgs>(c, "PropertyChanged")))))
+                               .Select(x => ((IChannel)x.Sender).Iter);
+
+                       chanChanges.Subscribe(iter => model.EmitRowChanged(model.GetPath(iter), iter));
+
                        foreach (Channel chan in channels) {
                                chan.Iter = model.AppendValues(chan);
-                               chan.PropertyChanged += OnPropertyChanged;
                        }
 
                        foreach (ChannelGroup group in groups) {
                                var iter = model.AppendValues(group);
                                group.Iter = iter;
-                               group.PropertyChanged += OnPropertyChanged;
                                //SetDragDestRow(Model.GetPath(iter), TreeViewDropPosition.IntoOrAfter);
 
                                foreach(IChannel chan in group.Channels) {
                                        chan.Iter = model.AppendValues(group.Iter, chan);
-                                       chan.PropertyChanged += OnPropertyChanged;
                                }
                        }
 


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