forked from linuxmint/cinnamon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_provider.js
More file actions
34 lines (30 loc) · 1.03 KB
/
Copy pathsearch_provider.js
File metadata and controls
34 lines (30 loc) · 1.03 KB
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
const Cinnamon = imports.gi.Cinnamon;
const St = imports.gi.St;
function perform_search(pattern){
/* Test for numbers and operators and make sure it does not end with
an operator, as that is not a valid operation */
if (/^[0-9.+*/()-]+[0-9\)]$/.test(pattern)) {
let solution = 0;
try {
solution = eval(pattern);
}catch(err){}
let awns = (Math.round(solution * 10000) / 10000).toString();
if (awns != pattern) {
let default_icon_app = Cinnamon.AppSystem.get_default().lookup_app("org.gnome.Calculator.desktop");
let result = {
id: awns,
label: _("Solution: %s").format(awns),
icon_app: default_icon_app
};
send_results([result]);
}
}
}
function on_result_selected (result) {
let awns = result.id;
copy_to_clipboard(awns);
}
function copy_to_clipboard (str) {
let clipboard = St.Clipboard.get_default()
clipboard.set_text(St.ClipboardType.CLIPBOARD, str);
}