2
* Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
* Authored by Michal Hruby <michal.mhr@gmail.com>
26
public class SearchEntry: Entry
28
public bool delayed_clear { get; set; default = false; }
29
public signal void search (string text);
30
public signal void clear ();
32
// FIXME: once we properly support gettext
33
//private string default_text = _("Search...");
34
private string default_text = "Search...";
35
private uint search_timeout;
43
this.set_text (default_text);
44
this.set_size_request (225, -1);
45
this.changed.connect (this.queue_search);
46
this.focus_in_event.connect (this.focus_in);
47
this.focus_out_event.connect (this.focus_out);
49
this.icon_press.connect (this.icon_pressed);
51
this.set_icon_from_stock (EntryIconPosition.PRIMARY, STOCK_FIND);
52
this.set_icon_from_stock (EntryIconPosition.SECONDARY, STOCK_CLEAR);
55
private bool focus_in ()
57
if (this.get_text () == default_text)
65
private bool focus_out ()
67
if (this.get_text () == "")
69
this.set_text (this.default_text);
75
private void icon_pressed (EntryIconPosition pos, Gdk.Event event)
77
if (pos == EntryIconPosition.SECONDARY &&
78
this.get_text () != default_text)
84
private void queue_search ()
86
if (this.search_timeout != 0)
88
GLib.Source.remove (this.search_timeout);
89
this.search_timeout = 0;
92
unowned string t = this.get_text ();
93
if ((t == default_text || t == "") && !delayed_clear)
99
this.search_timeout = Timeout.add (500, this.typing_timeout);
103
private bool typing_timeout ()
105
unowned string term = this.get_text ();
106
if (term != default_text && term != "")
110
else if (delayed_clear)
115
this.search_timeout = 0;