/
openInEditor.js
46 lines (40 loc) · 1.57 KB
/
openInEditor.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
Components.utils.import('resource://greasemonkey/prefmanager.js');
Components.utils.import('resource://greasemonkey/util.js');
const EXPORTED_SYMBOLS = ['openInEditor'];
const COULD_NOT_LAUNCH = (function() {
var stringBundle = Components
.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService)
.createBundle("chrome://greasemonkey/locale/gm-browser.properties");
return stringBundle.GetStringFromName("editor.could_not_launch");
})();
function openInEditor(script) {
var editor = GM_util.getEditor();
if (!editor) {
// The user did not choose an editor.
return;
}
try {
var args=[script.file.path];
// For the mac, wrap with a call to "open".
var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULRuntime);
if ("Darwin"==xulRuntime.OS) {
args = ["-a", appFile.path, script.file.path];
editor = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
editor.followLinks = true;
editor.initWithPath("/usr/bin/open");
}
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(editor);
process.run(false, args, args.length);
} catch (e) {
// Something may be wrong with the editor the user selected. Remove so that
// next time they can pick a different one.
alert(COULD_NOT_LAUNCH + "\n" + e);
GM_prefRoot.remove("editor");
throw(e);
}
}