-
Notifications
You must be signed in to change notification settings - Fork 7
/
gpaste_search_entry.js
113 lines (98 loc) · 3.07 KB
/
gpaste_search_entry.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const St = imports.gi.St;
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const Tooltips = Me.imports.tooltips;
const SEARCH_FLAGS = {
ONLY_TEXT: '-t',
ONLY_FILES: '-f',
ONLY_LINKS: '-l',
ONLY_CHECKED: '-c'
};
const GPasteSearchEntry = new Lang.Class({
Name: 'GPasteSearchEntry',
Extends: St.Entry,
_init: function() {
this.parent({
style_class: "gpaste-search-entry",
hint_text: "Type to search",
track_hover: true,
can_focus: true
});
this.clutter_text.connect(
'text-changed',
Lang.bind(this, this._on_text_changed)
);
this._inactive_icon = new St.Icon({
style_class: 'gpaste-search-entry-icon',
icon_name: 'edit-find-symbolic',
reactive: false
});
this._active_icon = new St.Icon({
style_class: 'gpaste-search-entry-icon',
icon_name: 'edit-clear-symbolic',
reactive: true
});
this.set_secondary_icon(this._inactive_icon);
this.connect(
'secondary-icon-clicked',
Lang.bind(this, this.clear)
);
Tooltips.get_manager().add_tooltip(this, {
text: (
'Append:\n' +
'"-f" to search only files\n' +
'"-t" - text\n' +
'"-l" - links'
)
});
this.term = '';
this.flag = '';
},
_on_text_changed: function() {
if(this.is_empty()) {
this.set_secondary_icon(this._inactive_icon);
return;
}
this._parse_text();
this.set_secondary_icon(this._active_icon);
},
_parse_text: function() {
if(this.is_empty()) {
this.term = '';
this.flag = '';
}
if(Utils.ends_with(this.text, SEARCH_FLAGS.ONLY_FILES)) {
this.term = this.text.slice(0, -SEARCH_FLAGS.ONLY_FILES.length);
this.flag = SEARCH_FLAGS.ONLY_FILES;
}
else if(Utils.ends_with(this.text, SEARCH_FLAGS.ONLY_TEXT)) {
this.term = this.text.slice(0, -SEARCH_FLAGS.ONLY_TEXT.length);
this.flag = SEARCH_FLAGS.ONLY_TEXT;
}
else if(Utils.ends_with(this.text, SEARCH_FLAGS.ONLY_LINKS)) {
this.term = this.text.slice(0, -SEARCH_FLAGS.ONLY_LINKS.length);
this.flag = SEARCH_FLAGS.ONLY_LINKS;
}
else if(Utils.ends_with(this.text, SEARCH_FLAGS.ONLY_CHECKED)) {
this.term = this.text.slice(0, -SEARCH_FLAGS.ONLY_CHECKED.length);
this.flag = SEARCH_FLAGS.ONLY_CHECKED;
}
else {
this.term = this.text;
this.flag = '';
}
},
is_empty: function() {
if(Utils.is_blank(this.text) || this.text === this.hint_text) {
return true
}
else {
return false;
}
},
clear: function() {
this.set_text('');
},
});