[blam/gtk-builder] Re-add the add-channel dialog
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam/gtk-builder] Re-add the add-channel dialog
- Date: Mon, 7 Oct 2013 11:30:15 +0000 (UTC)
commit 2150d93b4dcd6e84269ca26240483b19c58e7c03
Author: Carlos Martín Nieto <cmn dwim me>
Date: Mon Oct 7 13:06:09 2013 +0200
Re-add the add-channel dialog
blam.csproj | 9 +-
gtk-gui/Imendio.Blam.AddChannelDialog.cs | 2 +-
gtk-gui/gui.stetic | 5 -
src/Blam.cs | 27 ++++
src/Dialogs.cs | 85 ++++++++++++
src/EntryExtensions.cs | 17 +++
src/blam.ui | 118 +++++++++++++++--
src/dialogs.ui | 220 ++++++++++++++++++++++++++++++
8 files changed, 464 insertions(+), 19 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index eb55c96..fe80bdc 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -74,10 +74,6 @@
<Package>gtk-sharp-2.0</Package>
</Reference>
<Reference Include="Microsoft.CSharp" />
- <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>
@@ -87,6 +83,10 @@
<Reference Include="System.Reactive.Interfaces">
<HintPath>..\..\..\staging\mono\lib\mono\4.5\System.Reactive.Interfaces.dll</HintPath>
</Reference>
+ <Reference Include="gconf-sharp, Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
+ <Private>False</Private>
+ <Package>gconf-sharp-2.0</Package>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="src\Application.cs" />
@@ -122,6 +122,7 @@
<Compile Include="src\GLibSynchronizationContext.cs" />
<Compile Include="src\TreeSelectionExtensions.cs" />
<Compile Include="src\TreeViewExtensions.cs" />
+ <Compile Include="src\EntryExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
diff --git a/gtk-gui/Imendio.Blam.AddChannelDialog.cs b/gtk-gui/Imendio.Blam.AddChannelDialog.cs
index a35053e..96683c1 100644
--- a/gtk-gui/Imendio.Blam.AddChannelDialog.cs
+++ b/gtk-gui/Imendio.Blam.AddChannelDialog.cs
@@ -16,7 +16,7 @@ namespace Imendio.Blam
private global::Gtk.Entry UsernameEntry;
private global::Gtk.Button buttonCancel;
private global::Gtk.Button buttonOk;
-
+
protected virtual void Build ()
{
global::Stetic.Gui.Initialize (this);
diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic
index 961f76c..e0ebecb 100644
--- a/gtk-gui/gui.stetic
+++ b/gtk-gui/gui.stetic
@@ -6,8 +6,6 @@
</configuration>
<import>
<widget-library name="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
- <widget-library name="webkit-sharp, Version=1.1.15.0, Culture=neutral, PublicKeyToken=eaa1d335d2e19745"
/>
- <widget-library name="notify-sharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=2df29c54e245917a" />
<widget-library name="../bin/Debug/blam.exe" internal="true" />
</import>
<widget class="Gtk.Dialog" id="Imendio.Blam.AddChannelDialog" design-size="400 420">
@@ -130,7 +128,6 @@
<property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
- <signal name="Activated" handler="OnEntryActivated" />
</widget>
<packing>
<property name="TopAttach">2</property>
@@ -153,7 +150,6 @@
<property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
- <signal name="Activated" handler="OnEntryActivated" />
</widget>
<packing>
<property name="LeftAttach">1</property>
@@ -174,7 +170,6 @@
<property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
- <signal name="Activated" handler="OnEntryActivated" />
</widget>
<packing>
<property name="TopAttach">1</property>
diff --git a/src/Blam.cs b/src/Blam.cs
index e356cb9..1ff3a8e 100644
--- a/src/Blam.cs
+++ b/src/Blam.cs
@@ -63,6 +63,33 @@ namespace Blam
FeedList.SelectionChanged()
.Select(obj => ((TreeSelection)obj.Sender).Channel())
.Subscribe(chan => ItemList.Channel = chan);
+
+ wireMenuItems(bld);
+ }
+
+ void wireMenuItems(Builder bld)
+ {
+ var item = bld.GetObject<MenuItem>("menu-add-channel");
+ Observable.FromEventPattern<EventHandler, EventArgs>(
+ x => item.Activated += x, x => item.Activated -= x)
+ .Subscribe(obj => {
+ using (var dialog = new AddChannelDialog(MainWindow))
+ addChannel(dialog);
+ });
+ }
+
+ void addChannel(AddChannelDialog dialog)
+ {
+ var res = dialog.Run();
+ if (!res)
+ return;
+
+ var chan = new Channel();
+ chan.Url = dialog.Url;
+ chan.http_username = dialog.Username;
+ chan.http_password = dialog.Password;
+
+ channels.Add(chan, true);
}
public void Run()
diff --git a/src/Dialogs.cs b/src/Dialogs.cs
index 85fc293..c1f9966 100644
--- a/src/Dialogs.cs
+++ b/src/Dialogs.cs
@@ -10,6 +10,9 @@ using Gtk;
using Gdk;
using Mono.Unix;
using System;
+using System.Linq;
+using System.Reactive;
+using System.Reactive.Linq;
namespace Blam
{
@@ -48,6 +51,88 @@ namespace Blam
return Catalog.GetString(msg);
}
}
+
+ public class AddChannelDialog : IDisposable
+ {
+ public string Username {
+ get { return usernameEntry.Text; }
+ }
+
+ public string Password {
+ get { return passwordEntry.Text; }
+ }
+
+ public string Url {
+ get { return urlEntry.Text; }
+ set { urlEntry.Text = value; }
+ }
+
+ Entry urlEntry;
+ Entry usernameEntry;
+ Entry passwordEntry;
+ Dialog dialog;
+
+ IDisposable urlChange;
+ IDisposable activation;
+
+ IObservable<EventPattern<EventArgs>> urlChanged {
+ get {
+ return Observable.FromEventPattern<EventHandler, EventArgs>(
+ x => urlEntry.Changed += x,
+ x => urlEntry.Changed -= x);
+ }
+ }
+
+ public AddChannelDialog(Gtk.Window parent)
+ {
+ var bld = new Builder();
+ bld.AddFromResource("dialogs.ui");
+
+ dialog = bld.GetObject<Dialog>("add-channel");
+ dialog.TransientFor = parent;
+
+ urlEntry = bld.GetObject<Entry>("add-channel-url");
+ usernameEntry = bld.GetObject<Entry>("add-channel-username");
+ passwordEntry = bld.GetObject<Entry>("add-channel-password");
+ var button = bld.GetObject<Button>("add-channel-ok");
+
+ var clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true));
+ clipboard.RequestText((c, text) => {
+ if (!String.IsNullOrEmpty(text) && new[] {"http://",
"https://"}.Any(text.StartsWith)) {
+ Url = text;
+ } else {
+ Url = String.Empty;
+ }
+
+ // seed a dummy event so we take the above set into account
+ var foo = new EventPattern<EventArgs>(this, null);
+ urlChange = urlChanged.StartWith(foo).Subscribe(obj => {
+ button.Sensitive = !String.IsNullOrEmpty(Url);
+ });
+
+ });
+
+ activation = Observable.Merge(urlEntry.OnActivated(), usernameEntry.OnActivated(),
passwordEntry.OnActivated())
+ .Subscribe(obj => {
+ if (button.Sensitive)
+ button.Click();
+ });
+ }
+
+ public bool Run()
+ {
+ var res = dialog.Run();
+ dialog.Hide();
+
+ return res == (int)ResponseType.Ok;
+ }
+
+ public void Dispose()
+ {
+ urlChange.Dispose();
+ activation.Dispose();
+ }
+ }
}
namespace Imendio.Blam {
diff --git a/src/EntryExtensions.cs b/src/EntryExtensions.cs
new file mode 100644
index 0000000..0265e52
--- /dev/null
+++ b/src/EntryExtensions.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Reactive;
+using System.Reactive.Linq;
+
+namespace Blam
+{
+ public static class EntryExtensions
+ {
+ public static IObservable<EventPattern<EventArgs>> OnActivated(this Gtk.Entry entry)
+ {
+ return Observable.FromEventPattern<EventHandler, EventArgs>(
+ x => entry.Activated += x,
+ x => entry.Activated -= x);
+ }
+ }
+}
+
diff --git a/src/blam.ui b/src/blam.ui
index b5c96db..c0943fd 100644
--- a/src/blam.ui
+++ b/src/blam.ui
@@ -217,6 +217,11 @@
<action-widget response="0">ok-button</action-widget>
</action-widgets>
</object>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">list-add</property>
+ </object>
<object class="GtkWindow" id="main-window">
<property name="can_focus">False</property>
<child>
@@ -355,15 +360,6 @@
</object>
</child>
<child>
- <object class="GtkMenuItem" id="menuitem3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="use_action_appearance">False</property>
- <property name="label" translatable="yes">_View</property>
- <property name="use_underline">True</property>
- </object>
- </child>
- <child>
<object class="GtkMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -388,6 +384,110 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkMenuItem" id="item2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Channel</property>
+ <child type="submenu">
+ <object class="GtkMenu" id="item2_menu">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="menu-add-channel">
+ <property name="label">gtk-add</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <accelerator key="N" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="menuitem5">
+ <property name="label" translatable="yes">Add Group</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip_markup">Create a new group</property>
+ <property name="tooltip_text" translatable="yes">Create a new group</property>
+ <property name="use_action_appearance">False</property>
+ <property name="image">image1</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separator2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="refreshChannelMenuItem">
+ <property name="label">gtk-refresh</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <accelerator key="R" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_CONTROL_MASK"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="markChannelAsReadMenuItem">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <accelerator key="K" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="editChannelMenuItem">
+ <property name="label">gtk-edit</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="removeChannelMenuItem">
+ <property name="label">gtk-remove</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separator1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="update_channels1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_stock">False</property>
+ <accelerator key="R" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="markAllAsRead">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/dialogs.ui b/src/dialogs.ui
index 7442d8b..160fd22 100644
--- a/src/dialogs.ui
+++ b/src/dialogs.ui
@@ -2,6 +2,226 @@
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
+ <object class="GtkDialog" id="add-channel">
+ <property name="can_focus">False</property>
+ <property name="border_width">6</property>
+ <property name="title" translatable="yes">Add a new channel</property>
+ <property name="resizable">False</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox13">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area13">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="add-channel-cancel">
+ <property name="label">gtk-cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">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-channel-ok">
+ <property name="label">gtk-add</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">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="vbox10">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkHBox" id="hbox7">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkImage" id="add-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">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label17">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Enter the URL of the new channel</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">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkTable" id="table2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">6</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label18">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">URL:</property>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="add-channel-url">
+ <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="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label34">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Username</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label35">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Password</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="add-channel-username">
+ <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="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="add-channel-password">
+ <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="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options"/>
+ </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">add-channel-cancel</action-widget>
+ <action-widget response="-5">add-channel-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]