[blam/gtk-builder] Wire up the preference spin-buttons



commit 0aa2339039e516437f82b748d7c4738892f9b98b
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Fri Oct 11 23:46:47 2013 +0200

    Wire up the preference spin-buttons

 blam.csproj      |    3 ++-
 src/Dialogs.cs   |   14 +++++++++-----
 src/Spinnable.cs |   25 +++++++++++++++++++++++++
 src/Togglable.cs |   25 +++++++++++++++++++++++++
 src/dialogs.ui   |   23 ++++++++++++++++++++---
 5 files changed, 81 insertions(+), 9 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index 707d3e5..3b4a53a 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -125,7 +125,8 @@
     <Compile Include="src\EntryExtensions.cs" />
     <Compile Include="src\ClipboardExtensions.cs" />
     <Compile Include="src\MenuItemExtensions.cs" />
-    <Compile Include="src\Toggable.cs" />
+    <Compile Include="src\Togglable.cs" />
+    <Compile Include="src\Spinnable.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ItemGroup>
diff --git a/src/Dialogs.cs b/src/Dialogs.cs
index 59ce904..a38e52a 100644
--- a/src/Dialogs.cs
+++ b/src/Dialogs.cs
@@ -261,33 +261,37 @@ namespace Blam
 
                Togglable reverseEntries;
                Togglable autoRefresh;
-               SpinButton autoRefreshInterval;
+               Spinnable autoRefreshInterval;
                Togglable ignoreCertErrors;
                Togglable refreshOnStartup;
                ComboBox theme;
                Togglable markReadDelay;
-               SpinButton markReadDelayTime;
+               Spinnable markReadDelayTime;
 
                public PreferencesDialog(Gtk.Window parent)
                        : base(parent, "preferences")
                {
                        reverseEntries = new Togglable(bld, "reverse-entries", Preference.REVERSE_ENTRIES);
                        autoRefresh = new Togglable(bld, "auto-refresh", Preference.AUTO_REFRESH);
+                       autoRefreshInterval = new Spinnable(bld, "auto-refresh-interval", 
Preference.AUTO_REFRESH_RATE, 15, 1);
                        ignoreCertErrors = new Togglable(bld, "ignore-cert-errors", 
Preference.IGNORE_SSL_ERR);
                        refreshOnStartup = new Togglable(bld, "refresh-on-startup", 
Preference.REFRESH_AT_START);
                        markReadDelay = new Togglable(bld, "mark-read-delay", Preference.MARK_ITEMS_READ);
+                       markReadDelayTime = new Spinnable(bld,"mark-read-delay-time", 
Preference.MARK_ITEMS_READ_TIMEOUT, 3000, 1000);
                }
 
                public new void Run()
                {
-                       var toggles = Observable.Merge(
+                       var changes = Observable.Merge(
                                reverseEntries.Toggle,
                                autoRefresh.Toggle,
+                               autoRefreshInterval.Change,
                                ignoreCertErrors.Toggle,
                                refreshOnStartup.Toggle,
-                               markReadDelay.Toggle);
+                               markReadDelay.Toggle,
+                               markReadDelayTime.Change);
 
-                       var sub = toggles.Subscribe(kv => Conf.Set(kv.Key, kv.Value));
+                       var sub = changes.Subscribe(kv => Conf.Set(kv.Key, kv.Value));
 
                        base.Run();
 
diff --git a/src/Spinnable.cs b/src/Spinnable.cs
new file mode 100644
index 0000000..4a16b48
--- /dev/null
+++ b/src/Spinnable.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Reactive.Linq;
+using System.Collections.Generic;
+using Gtk;
+
+namespace Blam
+{
+       public class Spinnable
+       {
+               SpinButton button;
+
+               public IObservable<KeyValuePair<string, object>> Change { get; private set; }
+
+               public Spinnable(Builder bld, string name, string option, int def, int div)
+               {
+                       button = bld.GetObject<SpinButton>(name);
+                       button.Value = Conf.Get(option, def) / div;
+
+                       Change = Observable.FromEventPattern(button, "Changed")
+                               .Select(x => ((SpinButton)x.Sender).ValueAsInt)
+                               .Select(v => new KeyValuePair<string, object>(option, v * div));
+               }
+       }
+}
+
diff --git a/src/Togglable.cs b/src/Togglable.cs
new file mode 100644
index 0000000..ff97471
--- /dev/null
+++ b/src/Togglable.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Reactive.Linq;
+using System.Collections.Generic;
+using Gtk;
+
+namespace Blam
+{
+       public class Togglable
+       {
+               ToggleButton button;
+
+               public IObservable<KeyValuePair<string, object>> Toggle { get; private set; }
+
+               public Togglable(Builder bld, string name, string option)
+               {
+                       button = bld.GetObject<ToggleButton>(name);
+                       button.Active = Conf.Get(option, false);
+
+                       Toggle = Observable.FromEventPattern(button, "Toggled")
+                               .Select(x => ((ToggleButton)x.Sender).Active)
+                               .Select(v => new KeyValuePair<string, object>(option, v));
+               }
+       }
+}
+
diff --git a/src/dialogs.ui b/src/dialogs.ui
index 334b6e1..7c1ffa5 100644
--- a/src/dialogs.ui
+++ b/src/dialogs.ui
@@ -562,6 +562,11 @@
       <action-widget response="-10">edit-channel-apply</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkAdjustment" id="mark-read-adjustment">
+    <property name="upper">100</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkDialog" id="preferences">
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
@@ -713,8 +718,10 @@
                             <property name="secondary_icon_activatable">False</property>
                             <property name="primary_icon_sensitive">True</property>
                             <property name="secondary_icon_sensitive">True</property>
-                            <property name="adjustment"/>
+                            <property name="adjustment">refresh-adjustment</property>
                             <property name="climb_rate">1</property>
+                            <property name="snap_to_ticks">True</property>
+                            <property name="numeric">True</property>
                           </object>
                           <packing>
                             <property name="expand">True</property>
@@ -903,12 +910,15 @@
                         <property name="can_focus">True</property>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | 
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="invisible_char">●</property>
-                        <property name="invisible_char_set">True</property>
+                        <property name="caps_lock_warning">False</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>
-                        <property name="adjustment"/>
+                        <property name="adjustment">mark-read-adjustment</property>
+                        <property name="climb_rate">1</property>
+                        <property name="snap_to_ticks">True</property>
+                        <property name="numeric">True</property>
                       </object>
                       <packing>
                         <property name="expand">True</property>
@@ -956,6 +966,13 @@
       <action-widget response="-7">closeButton</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkAdjustment" id="refresh-adjustment">
+    <property name="lower">1</property>
+    <property name="upper">100</property>
+    <property name="value">15</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkDialog" id="remove-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]