Merge lp:~gcollura/granite/delayed-searchbar into lp:~elementary-pantheon/granite/granite

Proposed by Giulio Collura
Status: Merged
Merged at revision: 82
Proposed branch: lp:~gcollura/granite/delayed-searchbar
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 58 lines (+33/-1)
1 file modified
lib/Widgets/Entries.vala (+33/-1)
To merge this branch: bzr merge lp:~gcollura/granite/delayed-searchbar
Reviewer Review Type Date Requested Status
elementary Pantheon team Pending
Review via email: mp+79166@code.launchpad.net

Description of the change

Timeout for SearchEntry

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Widgets/Entries.vala'
2--- lib/Widgets/Entries.vala 2011-08-02 17:39:48 +0000
3+++ lib/Widgets/Entries.vala 2011-10-12 18:53:23 +0000
4@@ -101,6 +101,22 @@
5 public class SearchBar : HintedEntry {
6
7 private bool is_searching = true;
8+ private uint timeout_id = 0;
9+
10+ /**
11+ * This value handles how much time (in ms) should pass
12+ * after the user stops typing. By default it is set
13+ * to 300 ms.
14+ **/
15+ public int pause_delay { get; set; default = 300; }
16+
17+ /**
18+ * text_changed () signal is emitted after a short delay,
19+ * which depends on pause_delay.
20+ * If you need a synchronous signal without any delay,
21+ * use changed () method.
22+ **/
23+ public signal void text_changed (string text);
24
25 public SearchBar (string hint_string) {
26
27@@ -110,6 +126,7 @@
28
29 // Signals and callbacks
30 changed.connect (manage_icon);
31+ changed.connect_after (on_changed);
32 focus_in_event.connect (on_focus_in);
33 focus_out_event.connect (on_focus_out);
34 icon_press.connect (on_icon_press);
35@@ -164,7 +181,22 @@
36 }
37 }
38 }
39-
40+
41+ private void on_changed () {
42+
43+ timeout_id = Timeout.add (pause_delay, emit_text_changed);
44+
45+ }
46+
47+ private bool emit_text_changed () {
48+
49+ var terms = get_text ();
50+ text_changed (terms); // Emit signal
51+
52+ return Source.remove (timeout_id);
53+
54+ }
55+
56 }
57
58 }

Subscribers

People subscribed via source and target branches