[geary] Use built-in GTK signals for the search bar



commit f80f52fbe65b0d676cfcd4372c6b9fd62beb8e19
Author: Oskar Viljasaar <oskar viljasaar gmail com>
Date:   Fri Jul 1 22:13:10 2016 +0200

    Use built-in GTK signals for the search bar
    
    - Make use of the "search-changed" signal to handle user input, this
    lets us get rid of the built-in timeout mechanism. This reduces the
    timeout from 250ms to 150ms after user input before doing the search
    though.
    
    - Use the "activate" and "stop-search" signals for the entry. This
    lets us remove our handling of key events.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=720993

 src/client/application/geary-controller.vala |   17 +------------
 src/client/components/search-bar.vala        |   33 +++++++------------------
 2 files changed, 10 insertions(+), 40 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 98cb728..2080f27 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -84,7 +84,6 @@ public class GearyController : Geary.BaseObject {
     private const string MOVE_MESSAGE_TOOLTIP_MULTIPLE = _("Move conversations");
     
     private const int SELECT_FOLDER_TIMEOUT_USEC = 100 * 1000;
-    private const int SEARCH_TIMEOUT_MSEC = 250;
     
     private const string PROP_ATTEMPT_OPEN_ACCOUNT = "attempt-open-account";
     
@@ -122,7 +121,6 @@ public class GearyController : Geary.BaseObject {
     private Geary.Nonblocking.Mutex select_folder_mutex = new Geary.Nonblocking.Mutex();
     private Geary.Account? account_to_select = null;
     private Geary.Folder? previous_non_search_folder = null;
-    private uint search_timeout_id = 0;
     private UpgradeDialog upgrade_dialog;
     private Gee.List<string> pending_mailtos = new Gee.ArrayList<string>();
     private Geary.Nonblocking.Mutex untrusted_host_prompt_mutex = new Geary.Nonblocking.Mutex();
@@ -2796,20 +2794,7 @@ public class GearyController : Geary.BaseObject {
     }
     
     private void on_search_text_changed(string search_text) {
-        // So we don't thrash the disk as the user types, we run the actual
-        // search after a quick delay when they finish typing.
-        if (search_timeout_id != 0)
-            Source.remove(search_timeout_id);
-        
-        search_timeout_id = Timeout.add(SEARCH_TIMEOUT_MSEC, on_search_timeout, Priority.LOW);
-    }
-    
-    private bool on_search_timeout() {
-        search_timeout_id = 0;
-        
-        do_search(main_window.search_bar.search_text);
-        
-        return false;
+        do_search(search_text);
     }
     
     /**
diff --git a/src/client/components/search-bar.vala b/src/client/components/search-bar.vala
index 2db74a6..4275a00 100644
--- a/src/client/components/search-bar.vala
+++ b/src/client/components/search-bar.vala
@@ -5,8 +5,6 @@
  */
 
 public class SearchBar : Gtk.SearchBar {
-    private const string ICON_CLEAR_NAME = "edit-clear-symbolic";
-    private const string ICON_CLEAR_RTL_NAME = "edit-clear-rtl-symbolic";
     private const string DEFAULT_SEARCH_TEXT = _("Search");
     
     public string search_text { get { return search_entry.text; } }
@@ -23,9 +21,15 @@ public class SearchBar : Gtk.SearchBar {
         // Search entry.
         search_entry.width_chars = 28;
         search_entry.tooltip_text = _("Search all mail in account for keywords (Ctrl+S)");
-        search_entry.changed.connect(on_search_entry_changed);
-        search_entry.key_press_event.connect(on_search_key_press);
-        on_search_entry_changed(); // set initial state
+        search_entry.search_changed.connect(() => {
+            search_text_changed(search_entry.text);
+        });
+        search_entry.stop_search.connect(() => {
+            search_entry.text = "";
+        });
+        search_entry.activate.connect(() => {
+            search_text_changed(search_entry.text);
+        });
         search_entry.has_focus = true;
         
         // Search upgrade progress bar.
@@ -54,25 +58,6 @@ public class SearchBar : Gtk.SearchBar {
         search_entry.placeholder_text = placeholder;
     }
     
-    private void on_search_entry_changed() {
-        search_text_changed(search_entry.text);
-        // Enable/disable clear button.
-        search_entry.secondary_icon_name = search_entry.text != "" ?
-            (get_direction() == Gtk.TextDirection.RTL ? ICON_CLEAR_RTL_NAME : ICON_CLEAR_NAME) : null;
-    }
-    
-    private bool on_search_key_press(Gdk.EventKey event) {
-        // Clear box if user hits escape.
-        if (Gdk.keyval_name(event.keyval) == "Escape")
-            search_entry.text = "";
-        
-        // Force search if user hits enter.
-        if (Gdk.keyval_name(event.keyval) == "Return")
-            on_search_entry_changed();
-        
-        return false;
-    }
-    
     private void on_search_upgrade_start() {
         // Set the progress bar's width to match the search entry's width.
         int minimum_width = 0;


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