[blam/gtk-builder] Get some Rx going
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam/gtk-builder] Get some Rx going
- Date: Mon, 7 Oct 2013 11:30:10 +0000 (UTC)
commit b8b8f0e644a1c8d3e30ed67d5a9d4aa0df7f1820
Author: Carlos Martín Nieto <cmn dwim me>
Date: Mon Oct 7 09:47:42 2013 +0200
Get some Rx going
blam.csproj | 13 ++++++++++-
src/Blam.cs | 45 +++++++++++----------------------------
src/ItemList.cs | 15 ++++++++++--
src/TreeSelectionExtensions.cs | 18 ++++++++++++---
src/TreeViewExtensions.cs | 18 ++++++++++++++++
5 files changed, 69 insertions(+), 40 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index 572bd3f..eb55c96 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -74,9 +74,19 @@
<Package>gtk-sharp-2.0</Package>
</Reference>
<Reference Include="Microsoft.CSharp" />
- <Reference Include="gconf-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
+ <Reference Include="gconf-sharp, Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
+ <Private>False</Private>
<Package>gconf-sharp-2.0</Package>
</Reference>
+ <Reference Include="System.Reactive.Core">
+
<HintPath>..\..\..\staging\mono\lib\mono\gac\System.Reactive.Core\2.1.30214.0__31bf3856ad364e35\System.Reactive.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Linq">
+ <HintPath>..\..\..\staging\mono\lib\mono\4.5\System.Reactive.Linq.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Interfaces">
+ <HintPath>..\..\..\staging\mono\lib\mono\4.5\System.Reactive.Interfaces.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="src\Application.cs" />
@@ -111,6 +121,7 @@
<Compile Include="src\BuilderExtensions.cs" />
<Compile Include="src\GLibSynchronizationContext.cs" />
<Compile Include="src\TreeSelectionExtensions.cs" />
+ <Compile Include="src\TreeViewExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
diff --git a/src/Blam.cs b/src/Blam.cs
index a5cf5d7..e356cb9 100644
--- a/src/Blam.cs
+++ b/src/Blam.cs
@@ -5,6 +5,8 @@ using ChannelList = Imendio.Blam.ChannelList;
using Defines = Imendio.Blam.Defines;
using Mono.Unix;
using System.Threading;
+using System.Reactive.Linq;
+using Imendio.Blam.TreeSelectionExtensions;
namespace Blam
{
@@ -50,8 +52,17 @@ namespace Blam
ItemViewSw = bld.GetObject<ScrolledWindow>("item-view-scroll");
ItemViewSw.Child = ItemView;
- ItemList.Selection.Changed += OnItemChange;
- FeedList.Selection.Changed += OnFeedChange;
+ ItemList.SelectionChanged()
+ .Select(obj => ((TreeSelection)obj.Sender).Item())
+ .Where(item => item != null)
+ .Subscribe(item => {
+ ItemView.Item = item;
+ item.Unread = false;
+ });
+
+ FeedList.SelectionChanged()
+ .Select(obj => ((TreeSelection)obj.Sender).Channel())
+ .Subscribe(chan => ItemList.Channel = chan);
}
public void Run()
@@ -65,36 +76,6 @@ namespace Blam
Application.Quit();
args.RetVal = true;
}
-
- void OnFeedChange(object obj, EventArgs args)
- {
- TreeSelection selection = (TreeSelection)obj;
- TreeIter iter;
- TreeModel model;
- IChannel channel;
-
- if (!selection.GetSelected(out model, out iter))
- return;
-
- channel = model.GetValue(iter, 0) as IChannel;
- ItemList.Channel = channel;
- }
-
- void OnItemChange(object obj, EventArgs args)
- {
- TreeSelection selection = (TreeSelection) obj;
- TreeIter iter;
- TreeModel model;
- Imendio.Blam.Item item;
-
- if (!selection.GetSelected (out model, out iter)) {
- return;
- }
-
- item = (Imendio.Blam.Item) model.GetValue (iter, 0);
- ItemView.Item = item;
- //item.Unread = false;
- }
}
public class Blam
diff --git a/src/ItemList.cs b/src/ItemList.cs
index bb867ba..1625676 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -17,6 +17,8 @@ using System.Threading.Tasks;
using System.ServiceModel.Syndication;
using System.ComponentModel;
using System.Runtime.CompilerServices;
+using System.Reactive.Linq;
+using Imendio.Blam.TreeSelectionExtensions;
namespace Blam
{
@@ -28,7 +30,7 @@ namespace Blam
public delegate void OnChange(Item item);
- public class ItemList : Gtk.TreeView
+ public class ItemList : Gtk.TreeView, INotifyPropertyChanged
{
public IChannel Channel {
get {
@@ -37,13 +39,21 @@ namespace Blam
set {
current = value;
UpdateList();
+ NotifyPropertyChanged();
+ }
+ }
+
+ void NotifyPropertyChanged([CallerMemberName] string name = "")
+ {
+ if (PropertyChanged != null) {
+ PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
IChannel current;
TreeViewColumn column;
- public event OnChange OnChangeEvent;
+ public event PropertyChangedEventHandler PropertyChanged;
public ItemList()
{
@@ -55,7 +65,6 @@ namespace Blam
this.Model = new ListStore (typeof(Imendio.Blam.Item));
this.HeadersVisible = false;
-
}
void CellDataFunc (TreeViewColumn col, CellRenderer _cell, TreeModel model, TreeIter iter)
diff --git a/src/TreeSelectionExtensions.cs b/src/TreeSelectionExtensions.cs
index 3d66a56..8339430 100644
--- a/src/TreeSelectionExtensions.cs
+++ b/src/TreeSelectionExtensions.cs
@@ -1,7 +1,7 @@
using System;
using Gtk;
-namespace Imendio.Blam
+namespace Imendio.Blam.TreeSelectionExtensions
{
public static class TreeSelectionExtensions
{
@@ -17,16 +17,26 @@ namespace Imendio.Blam
model.EmitRowChanged(model.GetPath(iter), iter);
}
- public static Item Item(this TreeSelection selection)
+ public static T Get<T>(this TreeSelection selection)
{
TreeIter iter;
TreeModel model;
if (!selection.GetSelected (out model, out iter)) {
- return null;
+ return default(T);
}
- return (Imendio.Blam.Item) model.GetValue (iter, 0);
+ return (T) model.GetValue(iter, 0);
+ }
+
+ public static Item Item(this TreeSelection selection)
+ {
+ return selection.Get<Item>();
+ }
+
+ public static IChannel Channel(this TreeSelection selection)
+ {
+ return selection.Get<IChannel>();
}
}
}
diff --git a/src/TreeViewExtensions.cs b/src/TreeViewExtensions.cs
new file mode 100644
index 0000000..7cf42c6
--- /dev/null
+++ b/src/TreeViewExtensions.cs
@@ -0,0 +1,18 @@
+using System;
+using Gtk;
+using System.Reactive;
+using System.Reactive.Linq;
+
+namespace Blam
+{
+ public static class TreeViewExtensions
+ {
+ public static IObservable<EventPattern<EventArgs>> SelectionChanged(this TreeView treeView)
+ {
+ return Observable.FromEventPattern<EventHandler, EventArgs>(
+ x => treeView.Selection.Changed += x,
+ x => treeView.Selection.Changed -= x);
+ }
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]