[blam/gtk-builder] Wire up adding a group
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam/gtk-builder] Wire up adding a group
- Date: Tue, 8 Oct 2013 22:22:32 +0000 (UTC)
commit 1f380cab2fcfc117797d5d5d003c1619e559674f
Author: Carlos Martín Nieto <cmn dwim me>
Date: Tue Oct 8 23:39:48 2013 +0200
Wire up adding a group
src/Blam.cs | 11 ++++
src/ChannelCollection.cs | 10 ++++
src/Dialogs.cs | 45 +++++++++++++++++
src/blam.ui | 2 +-
src/dialogs.ui | 123 ++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 190 insertions(+), 1 deletions(-)
---
diff --git a/src/Blam.cs b/src/Blam.cs
index eebedb8..4b1e7a0 100644
--- a/src/Blam.cs
+++ b/src/Blam.cs
@@ -12,6 +12,7 @@ namespace Blam
{
using Channel = Imendio.Blam.Channel;
using IChannel = Imendio.Blam.IChannel;
+ using ChannelGroup = Imendio.Blam.ChannelGroup;
using ItemStore = Imendio.Blam.ItemStore;
public class BlamApplication
@@ -75,6 +76,16 @@ namespace Blam
using (var dialog = new AddChannelDialog(MainWindow))
addChannel(dialog);
});
+
+ item = bld.GetObject<MenuItem>("menu-add-group");
+ item.ObserveActivated().Subscribe(obj => {
+ var dialog = new AddGroupDialog(MainWindow);
+ if (dialog.Run()) {
+ var grp = new ChannelGroup();
+ grp.Name = dialog.Name;
+ channels.Groups.Add(grp);
+ }
+ });
}
void addChannel(AddChannelDialog dialog)
diff --git a/src/ChannelCollection.cs b/src/ChannelCollection.cs
index 5afd1ee..ed3ad46 100644
--- a/src/ChannelCollection.cs
+++ b/src/ChannelCollection.cs
@@ -213,6 +213,16 @@ namespace Imendio.Blam {
}
+ public void Add(ChannelGroup grp)
+ {
+ // avoid duplicates
+ if (Groups.Any(grp.Name.Equals))
+ return;
+
+ Groups.Add(grp);
+ NotifyAdd(grp);
+ }
+
public void Add(ChannelGroup group, IChannel channel)
{
group.Add(channel);
diff --git a/src/Dialogs.cs b/src/Dialogs.cs
index c88275b..c8897d9 100644
--- a/src/Dialogs.cs
+++ b/src/Dialogs.cs
@@ -188,6 +188,51 @@ namespace Blam
channel.http_password = passwordEntry.Text;
}
}
+
+ public class AddGroupDialog
+ {
+ Dialog dialog;
+ Entry name;
+ Button button;
+
+ IObservable<bool> clickable;
+ IObservable<EventPattern<EventArgs>> activation;
+
+ public string Name {
+ get {
+ return name.Text;
+ }
+ }
+
+ public AddGroupDialog(Gtk.Window parent)
+ {
+ var bld = new Builder();
+ bld.AddFromResource("dialogs.ui");
+
+ dialog = bld.GetObject<Dialog>("add-group");
+ dialog.TransientFor = parent;
+ dialog.IconName = "blam";
+
+ button = bld.GetObject<Button>("add-group-ok");
+ name = bld.GetObject<Entry>("add-group-name");
+ clickable = name.ObserveTextChanged().Select(t =>
!String.IsNullOrEmpty(t)).StartWith(false);
+ activation = name.OnActivated().Where(_ => button.Sensitive);
+ }
+
+ public bool Run()
+ {
+ var clickSub = clickable.Subscribe(v => button.Sensitive = v);
+ var actSub = activation.Subscribe(_ => button.Click());
+
+ int res = dialog.Run();
+ dialog.Hide();
+
+ clickSub.Dispose();
+ actSub.Dispose();
+
+ return res == (int)ResponseType.Ok;
+ }
+ }
}
namespace Imendio.Blam {
diff --git a/src/blam.ui b/src/blam.ui
index c0943fd..9f0bf3b 100644
--- a/src/blam.ui
+++ b/src/blam.ui
@@ -405,7 +405,7 @@
</object>
</child>
<child>
- <object class="GtkImageMenuItem" id="menuitem5">
+ <object class="GtkImageMenuItem" id="menu-add-group">
<property name="label" translatable="yes">Add Group</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
diff --git a/src/dialogs.ui b/src/dialogs.ui
index 6fd95fe..5e583ea 100644
--- a/src/dialogs.ui
+++ b/src/dialogs.ui
@@ -222,6 +222,129 @@
<action-widget response="-5">add-channel-ok</action-widget>
</action-widgets>
</object>
+ <object class="GtkDialog" id="add-group">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="window_position">center-on-parent</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox2">
+ <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_area2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button1">
+ <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="add-group-ok">
+ <property name="label">gtk-add</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="GtkVBox" id="vbox3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="label6">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Create new group</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox6">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="label7">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Name: </property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="add-group-name">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="invisible_char_set">True</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">True</property>
+ <property name="secondary_icon_sensitive">True</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>
+ <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">button1</action-widget>
+ <action-widget response="-5">add-group-ok</action-widget>
+ </action-widgets>
+ </object>
<object class="GtkDialog" id="edit-channel">
<property name="can_focus">False</property>
<property name="border_width">5</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]