[blam/gtk-builder] FeedList: factor out editing and removing a channel
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam/gtk-builder] FeedList: factor out editing and removing a channel
- Date: Wed, 9 Oct 2013 09:33:31 +0000 (UTC)
commit 9917fc2e79aa680025c11d02cf812a79213c704e
Author: Carlos Martín Nieto <cmn dwim me>
Date: Wed Oct 9 11:33:53 2013 +0200
FeedList: factor out editing and removing a channel
src/ChannelList.cs | 83 ++++++++++++++++++++++++++++-----------------------
1 files changed, 46 insertions(+), 37 deletions(-)
---
diff --git a/src/ChannelList.cs b/src/ChannelList.cs
index 443798a..c7ef740 100644
--- a/src/ChannelList.cs
+++ b/src/ChannelList.cs
@@ -34,6 +34,9 @@ namespace Blam
TreeViewColumn name_col;
ChannelMenu Popup;
+ ObservableCollection<Channel> channels;
+ ObservableCollection<ChannelGroup> groups;
+
void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
{
var chan = (IChannel)sender;
@@ -47,8 +50,43 @@ namespace Blam
yield return chan;
}
+ void editCurrent()
+ {
+ var chan = GetSelected();
+ if (chan is ChannelGroup)
+ return;
+
+ var channel = (Channel)chan;
+ using (var dialog = new ChannelDialog(MainWindow, channel))
+ {
+ if (dialog.Run()) {
+ channel.Name = dialog.Name;
+ channel.Url = dialog.Url;
+ channel.http_username = dialog.Username;
+ channel.http_password = dialog.Password;
+ }
+ }
+ }
+
+ void removeCurrent()
+ {
+ var chan = GetSelected();
+ using (var dialog = new RemoveChannelDialog(MainWindow, chan))
+ {
+ if (dialog.Run()) {
+ if (chan is Channel)
+ channels.Remove((Channel)chan);
+ else
+ groups.Remove((ChannelGroup)chan);
+ }
+ }
+ }
+
public FeedList(ObservableCollection<Channel> channels, ObservableCollection<ChannelGroup>
groups)
{
+ this.channels = channels;
+ this.groups = groups;
+
name_col = new TreeViewColumn();
var renderer = new CellRendererText();
name_col.PackStart(renderer, true);
@@ -84,11 +122,10 @@ namespace Blam
chan.Iter = iter;
});
- // let's not wire this up until we know how to deal with arbitrary removals
- //removals.Subscribe(chan => {
- // var iter = chan.Iter;
- // (model as TreeStore).Remove(ref iter);
- //});
+ removals.Subscribe(chan => {
+ var iter = chan.Iter;
+ (model as TreeStore).Remove(ref iter);
+ });
foreach (Channel chan in channels) {
chan.Iter = model.AppendValues(chan);
@@ -113,37 +150,9 @@ namespace Blam
await chan.RefreshAsync();
};
Popup.MarkAsReadSelected += () => GetSelected().MarkAsRead();
- Popup.EditSelected += () => {
- var chan = GetSelected();
- if (chan is ChannelGroup)
- return;
+ Popup.EditSelected += editCurrent;
- Channel channel = (Channel) chan;
- using (var dialog = new ChannelDialog(MainWindow, channel))
- {
- if (dialog.Run() == true) {
- channel.Name = dialog.Name;
- channel.Url = dialog.Url;
- channel.http_username = dialog.Username;
- channel.http_password = dialog.Password;
- }
- }
- };
- Popup.RemoveSelected += () => {
- var chan = GetSelected();
- using (var dialog = new RemoveChannelDialog(MainWindow, chan))
- {
- if (dialog.Run()) {
- var iter = chan.Iter;
- if (chan is Channel)
- channels.Remove((Channel)chan);
- else
- groups.Remove((ChannelGroup)chan);
-
- model.Remove(ref iter);
- }
- }
- };
+ Popup.RemoveSelected += removeCurrent;
}
void NamesCellDataFunc(TreeViewColumn col, CellRenderer _cell, TreeModel model, TreeIter iter)
@@ -185,7 +194,7 @@ namespace Blam
switch (bEvent.Button) {
case 1:
if (bEvent.Type == EventType.TwoButtonPress) {
- //EditChannelCb();
+ editCurrent();
} else {
return base.OnButtonPressEvent (bEvent);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]