[california] Use "edit-clear-symbolic" icons in all GtkEntry's



commit db4347828e1bbd7badc3800269d1e1bcd1214ab7
Author: Jim Nelson <jim yorba org>
Date:   Wed Jul 23 17:04:22 2014 -0700

    Use "edit-clear-symbolic" icons in all GtkEntry's

 src/Makefile.am                                    |    1 +
 .../google/activator-google-login-pane.vala        |    6 ++
 src/activator/webcal/activator-webcal-pane.vala    |    5 ++
 src/host/host-create-update-event.vala             |    5 ++
 src/host/host-quick-create-event.vala              |   12 +----
 src/rc/quick-create-event.ui                       |    1 -
 .../toolkit-entry-clear-text-connector.vala        |   54 ++++++++++++++++++++
 7 files changed, 73 insertions(+), 11 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3976255..62c334a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -122,6 +122,7 @@ california_VALASOURCES = \
        toolkit/toolkit-deck.vala \
        toolkit/toolkit-deck-window.vala \
        toolkit/toolkit-editable-label.vala \
+       toolkit/toolkit-entry-clear-text-connector.vala \
        toolkit/toolkit-event-connector.vala \
        toolkit/toolkit-listbox-model.vala \
        toolkit/toolkit-motion-connector.vala \
diff --git a/src/activator/google/activator-google-login-pane.vala 
b/src/activator/google/activator-google-login-pane.vala
index 15d66fc..a66b761 100644
--- a/src/activator/google/activator-google-login-pane.vala
+++ b/src/activator/google/activator-google-login-pane.vala
@@ -27,9 +27,15 @@ internal class GoogleLoginPane : Gtk.Grid, Toolkit.Card {
     [GtkChild]
     private Gtk.Button login_button;
     
+    private Toolkit.EntryClearTextConnector account_clear_text_connector;
+    private Toolkit.EntryClearTextConnector password_clear_text_connector;
+    
     public GoogleLoginPane() {
+        account_clear_text_connector = new Toolkit.EntryClearTextConnector(account_entry);
         account_entry.bind_property("text-length", login_button, "sensitive",
             BindingFlags.SYNC_CREATE, on_entry_changed);
+        
+        password_clear_text_connector = new Toolkit.EntryClearTextConnector(password_entry);
         password_entry.bind_property("text-length", login_button, "sensitive",
             BindingFlags.SYNC_CREATE, on_entry_changed);
     }
diff --git a/src/activator/webcal/activator-webcal-pane.vala b/src/activator/webcal/activator-webcal-pane.vala
index 4d3b31e..34520c8 100644
--- a/src/activator/webcal/activator-webcal-pane.vala
+++ b/src/activator/webcal/activator-webcal-pane.vala
@@ -31,6 +31,8 @@ internal class WebCalActivatorPane : Gtk.Grid, Toolkit.Card {
     private Gtk.Button subscribe_button;
     
     private Backing.WebCalSubscribable store;
+    private Toolkit.EntryClearTextConnector name_clear_text_connector;
+    private Toolkit.EntryClearTextConnector url_clear_text_connector;
     
     public WebCalActivatorPane(Backing.WebCalSubscribable store, Soup.URI? supplied_url) {
         this.store = store;
@@ -40,8 +42,11 @@ internal class WebCalActivatorPane : Gtk.Grid, Toolkit.Card {
             url_entry.sensitive = false;
         }
         
+        name_clear_text_connector = new Toolkit.EntryClearTextConnector(name_entry);
         name_entry.bind_property("text-length", subscribe_button, "sensitive",
             BindingFlags.SYNC_CREATE, on_entry_changed);
+        
+        url_clear_text_connector = new Toolkit.EntryClearTextConnector(url_entry);
         url_entry.bind_property("text-length", subscribe_button, "sensitive",
             BindingFlags.SYNC_CREATE, on_entry_changed);
     }
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index ee19080..e05a4c8 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -76,6 +76,8 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
     private bool both_date_buttons_touched = false;
     
     private Toolkit.RotatingButtonBox rotating_button_box = new Toolkit.RotatingButtonBox();
+    private Toolkit.EntryClearTextConnector summary_clear_text_connector;
+    private Toolkit.EntryClearTextConnector location_clear_text_connector;
     
     private Gtk.Button accept_button = new Gtk.Button();
     private Gtk.Button cancel_button = new Gtk.Button.with_mnemonic(_("_Cancel"));
@@ -92,9 +94,12 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
         
         // create button is active only if summary is filled out; all other fields (so far)
         // guarantee valid values at all times
+        summary_clear_text_connector = new Toolkit.EntryClearTextConnector(summary_entry);
         summary_entry.bind_property("text-length", accept_button, "sensitive",
             BindingFlags.SYNC_CREATE);
         
+        location_clear_text_connector = new Toolkit.EntryClearTextConnector(location_entry);
+        
         // hide start/end time widgets if an all-day event ..."no-show-all" needed to avoid the
         // merciless effects of show_all()
         all_day_toggle.bind_property("active", dtstart_time_combo, "visible",
diff --git a/src/host/host-quick-create-event.vala b/src/host/host-quick-create-event.vala
index df56cef..7fc1dad 100644
--- a/src/host/host-quick-create-event.vala
+++ b/src/host/host-quick-create-event.vala
@@ -39,6 +39,7 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
     private Gtk.Button create_button;
     
     private Toolkit.ComboBoxTextModel<Backing.CalendarSource> model;
+    private Toolkit.EntryClearTextConnector entry_clear_text_connector;
     
     public QuickCreateEvent() {
         // create and initialize combo box model
@@ -50,8 +51,7 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
                 model.add(calendar_source);
         }
         
-        details_entry.secondary_icon_name = get_direction() == Gtk.TextDirection.RTL
-            ? "edit-clear-rtl-symbolic" : "edit-clear-symbolic";
+        entry_clear_text_connector = new Toolkit.EntryClearTextConnector(details_entry);
         details_entry.bind_property("text", create_button, "sensitive", BindingFlags.SYNC_CREATE,
             transform_text_to_sensitivity);
     }
@@ -87,14 +87,6 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
     }
     
     [GtkCallback]
-    private void on_details_entry_icon_release(Gtk.Entry entry, Gtk.EntryIconPosition icon,
-        Gdk.Event event) {
-        // check for clear icon being pressed
-        if (icon == Gtk.EntryIconPosition.SECONDARY)
-            details_entry.text = "";
-    }
-    
-    [GtkCallback]
     private void on_cancel_button_clicked() {
         notify_user_closed();
     }
diff --git a/src/rc/quick-create-event.ui b/src/rc/quick-create-event.ui
index d8416eb..ed0c214 100644
--- a/src/rc/quick-create-event.ui
+++ b/src/rc/quick-create-event.ui
@@ -120,7 +120,6 @@
             <property name="hexpand">True</property>
             <property name="activates_default">True</property>
             <property name="width_chars">40</property>
-            <signal name="icon-release" handler="on_details_entry_icon_release" 
object="CaliforniaHostQuickCreateEvent" swapped="no"/>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/src/toolkit/toolkit-entry-clear-text-connector.vala 
b/src/toolkit/toolkit-entry-clear-text-connector.vala
new file mode 100644
index 0000000..410ee32
--- /dev/null
+++ b/src/toolkit/toolkit-entry-clear-text-connector.vala
@@ -0,0 +1,54 @@
+/* Copyright 2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later).  See the COPYING file in this distribution.
+ */
+
+namespace California.Toolkit {
+
+/**
+ * This connector attaches signal handling to (a) display a "clear text" icon when the GtkEntry
+ * has text and (b) clear the entry when the icon is pressed.
+ */
+
+public class EntryClearTextConnector : BaseObject {
+    public Gtk.Entry entry { get; private set; }
+    
+    private Binding text_binding;
+    
+    public EntryClearTextConnector(Gtk.Entry entry) {
+        this.entry = entry;
+        
+        text_binding = entry.bind_property("text", entry, "secondary-icon-name", BindingFlags.SYNC_CREATE,
+            transform_text_to_icon_name);
+        entry.icon_release.connect(on_entry_icon_released);
+    }
+    
+    ~EntryClearTextConnector() {
+        text_binding.unref();
+        entry.icon_release.disconnect(on_entry_icon_released);
+    }
+    
+    private bool transform_text_to_icon_name(Binding binding, Value source_value, ref Value target_value) {
+        if (String.is_empty((string) source_value)) {
+            target_value = "";
+        } else {
+            target_value = entry.get_direction() == Gtk.TextDirection.RTL
+                ? "edit-clear-rtl-symbolic" : "edit-clear-symbolic";
+        }
+        
+        return true;
+    }
+    
+    private void on_entry_icon_released(Gtk.EntryIconPosition icon, Gdk.Event event) {
+        if (icon == Gtk.EntryIconPosition.SECONDARY)
+            entry.text = "";
+    }
+    
+    public override string to_string() {
+        return get_type().name();
+    }
+}
+
+}
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]