[blam/gtk-builder] Wire up the channel remove dialog
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam/gtk-builder] Wire up the channel remove dialog
- Date: Sun, 6 Oct 2013 20:49:45 +0000 (UTC)
commit a43f41bd83a650bfce7dcc9fbf9089ae61da5d07
Author: Carlos Martín Nieto <cmn dwim me>
Date: Sun Oct 6 22:50:03 2013 +0200
Wire up the channel remove dialog
blam.csproj | 6 +-
src/Blam.cs | 6 ++
src/Channel.cs | 2 +-
src/ChannelDialog.cs | 2 +-
src/ChannelList.cs | 30 +++++++++-
src/Dialogs.cs | 39 +++++++++++++
src/{edit-channel.ui => dialogs.ui} | 102 +++++++++++++++++++++++++++++++++--
7 files changed, 175 insertions(+), 12 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index 382a59b..572bd3f 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -136,12 +136,12 @@
<EmbeddedResource Include="gtk-gui\gui.stetic">
<LogicalName>gui.stetic</LogicalName>
</EmbeddedResource>
- <EmbeddedResource Include="src\edit-channel.ui">
- <LogicalName>edit-channel.ui</LogicalName>
- </EmbeddedResource>
<EmbeddedResource Include="src\blam.ui">
<LogicalName>blam.ui</LogicalName>
</EmbeddedResource>
+ <EmbeddedResource Include="src\dialogs.ui">
+ <LogicalName>dialogs.ui</LogicalName>
+ </EmbeddedResource>
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
diff --git a/src/Blam.cs b/src/Blam.cs
index 7fd2884..6c29e2c 100644
--- a/src/Blam.cs
+++ b/src/Blam.cs
@@ -3,6 +3,8 @@ using Gtk;
using ChannelCollection = Imendio.Blam.ChannelCollection;
using ChannelList = Imendio.Blam.ChannelList;
using Defines = Imendio.Blam.Defines;
+using Mono.Unix;
+using System.Threading;
namespace Blam
{
@@ -23,9 +25,12 @@ namespace Blam
ChannelCollection channels;
+ public static SynchronizationContext Context { get; private set; }
+
public BlamApplication()
{
ItemStore.Load();
+ Context = new GLib.GLibSynchronizationContext();
var bld = new Builder();
bld.AddFromResource("blam.ui");
@@ -36,6 +41,7 @@ namespace Blam
channels = ChannelCollection.LoadFromFile (Defines.APP_HOMEDIR + "/collection.xml");
FeedListSw = bld.GetObject<ScrolledWindow>("feed-list-scroll");
FeedList = new FeedList(channels.Channels, channels.Groups);
+ FeedList.MainWindow = MainWindow;
FeedListSw.Child = FeedList;
ItemList = new ItemList();
diff --git a/src/Channel.cs b/src/Channel.cs
index 1ccc5cf..a3d50c3 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -20,7 +20,7 @@ using System.Runtime.CompilerServices;
namespace Imendio.Blam {
- public interface IChannel
+ public interface IChannel : INotifyPropertyChanged
{
int NrOfItems {get; }
int NrOfUnreadItems {get; }
diff --git a/src/ChannelDialog.cs b/src/ChannelDialog.cs
index 4c5d5c6..6df152a 100644
--- a/src/ChannelDialog.cs
+++ b/src/ChannelDialog.cs
@@ -22,7 +22,7 @@ namespace Blam
public ChannelDialog()
{
var bld = new Builder();
- bld.AddFromResource("edit-channel.ui");
+ bld.AddFromResource("dialogs.ui");
Dialog = bld.GetObject<Dialog>("edit-channel");
diff --git a/src/ChannelList.cs b/src/ChannelList.cs
index f8f9370..02b94b3 100644
--- a/src/ChannelList.cs
+++ b/src/ChannelList.cs
@@ -25,9 +25,17 @@ namespace Blam
public class FeedList : Gtk.TreeView
{
+ public Gtk.Window MainWindow;
+
TreeViewColumn name_col;
ChannelMenu Popup;
+ void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
+ {
+ var chan = (IChannel)sender;
+ BlamApplication.Context.Post((state) =>
Model.EmitRowChanged(Model.GetPath(chan.Iter), chan.Iter), null);
+ }
+
public FeedList(IEnumerable<Channel> channels, IEnumerable<ChannelGroup> groups)
{
name_col = new TreeViewColumn();
@@ -50,20 +58,28 @@ namespace Blam
var model = Model as TreeStore;
- foreach (IChannel chan in channels)
+ 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)
+ foreach(IChannel chan in group.Channels) {
chan.Iter = model.AppendValues(group.Iter, chan);
+ chan.PropertyChanged += OnPropertyChanged;
+ }
}
Popup = new ChannelMenu();
- Popup.RefreshSelected += () => GetSelected().RefreshAsync();
+ Popup.RefreshSelected += async () => {
+ var chan = GetSelected();
+ await chan.RefreshAsync();
+ };
Popup.MarkAsReadSelected += () => GetSelected().MarkAsRead();
Popup.EditSelected += () => {
var chan = GetSelected();
@@ -73,6 +89,14 @@ namespace Blam
var diag = new ChannelDialog();
diag.Show((Channel)chan);
};
+ Popup.RemoveSelected += () => {
+ var chan = GetSelected();
+ var del = new RemoveChannelDialog(MainWindow).Run(chan);
+ if (del) {
+ var iter = chan.Iter;
+ model.Remove(ref iter);
+ }
+ };
}
void NamesCellDataFunc(TreeViewColumn col, CellRenderer _cell, TreeModel model, TreeIter iter)
diff --git a/src/Dialogs.cs b/src/Dialogs.cs
index 1c2d679..85fc293 100644
--- a/src/Dialogs.cs
+++ b/src/Dialogs.cs
@@ -11,6 +11,45 @@ using Gdk;
using Mono.Unix;
using System;
+namespace Blam
+{
+ using ChannelCollection = Imendio.Blam.ChannelCollection;
+ using IChannel = Imendio.Blam.IChannel;
+
+ class RemoveChannelDialog
+ {
+ Dialog Dialog;
+ Label Label;
+
+ public RemoveChannelDialog(Gtk.Window parent)
+ {
+ var bld = new Builder();
+ bld.AddFromResource("dialogs.ui");
+
+ Dialog = bld.GetObject<Dialog>("remove-channel");
+ Dialog.TransientFor = parent;
+ Dialog.IconName = "blam";
+ Label = bld.GetObject<Label>("remove-channel-label");
+ }
+
+ public bool Run(IChannel chan)
+ {
+ var text = String.Format(_("Do you want to remove the channel or group <b>{0}</b>
from the channel list?"), chan.Name);
+ Label.Markup = text;
+
+ var res = Dialog.Run();
+ Dialog.Hide();
+
+ return res == (int)ResponseType.Accept;
+ }
+
+ static string _(string msg)
+ {
+ return Catalog.GetString(msg);
+ }
+ }
+}
+
namespace Imendio.Blam {
class AddGroupDialog
{
diff --git a/src/edit-channel.ui b/src/dialogs.ui
similarity index 69%
rename from src/edit-channel.ui
rename to src/dialogs.ui
index 5ca2178..7442d8b 100644
--- a/src/edit-channel.ui
+++ b/src/dialogs.ui
@@ -17,7 +17,7 @@
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="cancel-button">
+ <object class="GtkButton" id="edit-channel-cancel">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -32,7 +32,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="ok-button">
+ <object class="GtkButton" id="edit-channel-ok">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -217,8 +217,102 @@
</object>
</child>
<action-widgets>
- <action-widget response="0">cancel-button</action-widget>
- <action-widget response="0">ok-button</action-widget>
+ <action-widget response="0">edit-channel-cancel</action-widget>
+ <action-widget response="0">edit-channel-ok</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkDialog" id="remove-channel">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="remove-channel-cancel">
+ <property name="label">gtk-cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="remove-channel-remove">
+ <property name="label">gtk-remove</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImage" id="remove-channel-image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-missing-image</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="remove-channel-label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">label</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">remove-channel-cancel</action-widget>
+ <action-widget response="-3">remove-channel-remove</action-widget>
</action-widgets>
</object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]