forked from leonardo-bartoli/gnome-shell-extension-Recents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchItem.js
62 lines (51 loc) · 1.66 KB
/
searchItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const St = imports.gi.St;
const Lang = imports.lang;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const SearchItem = new Lang.Class({
Name: 'SearchItem',
Extends: PopupMenu.PopupBaseMenuItem,
_init: function () {
this.parent({
activate: false,
reactive: true,
can_focus: false
});
this._entry = new St.Entry({
name: 'SearchEntry',
style_class: 'search-entry',
track_hover: true,
reactive: true,
can_focus: true
});
this.actor.add(this._entry, { expand: true });
this._entry.set_primary_icon(new St.Icon({
style_class: 'search-entry-icon',
icon_name: 'edit-find-symbolic'
}));
this._entry.clutter_text.connect('text-changed', Lang.bind(this, this._onTextChanged));
this._clearIcon = new St.Icon({
style_class: 'search-entry-icon',
icon_name: 'edit-clear-symbolic'
});
this._iconClickedId = 0;
this._entry.connect('secondary-icon-clicked', Lang.bind(this, this.reset));
},
get text() {
return this._entry.get_text();
},
reset: function() {
this._entry.text = '';
let text = this._entry.clutter_text;
text.set_cursor_visible(true);
text.set_selection(0, 0);
},
_onTextChanged: function(se, prop) {
let dummy = (this.text.length === 0);
this._entry.set_secondary_icon((dummy) ? null : this._clearIcon);
this.emit('text-changed');
},
grab_key_focus: function() {
this._entry.grab_key_focus();
}
});