mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 02:38:00 +01:00
Fix gF and so forth.
This commit is contained in:
@@ -1007,7 +1007,11 @@ const Buffer = Module("buffer", {
|
||||
XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), {
|
||||
init: function (doc, callback) {
|
||||
this.callback = callable(callback) ? callback :
|
||||
function (file) editor.editFileExternally(file.path, callback, null, true);
|
||||
function (file) {
|
||||
editor.editFileExternally({ file: file.path, line: callback },
|
||||
function () { file.remove(false) });
|
||||
return true;
|
||||
}
|
||||
|
||||
let url = isString(doc) ? doc : doc.location.href;
|
||||
let uri = util.newURI(url, charset);
|
||||
@@ -1018,8 +1022,8 @@ const Buffer = Module("buffer", {
|
||||
let encoder = services.HtmlEncoder();
|
||||
encoder.init(doc, "text/unicode", encoder.OutputRaw|encoder.OutputPreformatted);
|
||||
temp.write(encoder.encodeToString(), ">");
|
||||
this.callback(temp);
|
||||
}, this);
|
||||
return this.callback(temp);
|
||||
}, this, true);
|
||||
|
||||
let file = util.getFile(uri);
|
||||
if (file)
|
||||
@@ -1038,10 +1042,11 @@ const Buffer = Module("buffer", {
|
||||
onStateChange: function (progress, request, flag, status) {
|
||||
if ((flag & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) {
|
||||
try {
|
||||
this.callback(this.file);
|
||||
var ok = this.callback(this.file);
|
||||
}
|
||||
finally {
|
||||
this.file.remove(false);
|
||||
if (ok !== true)
|
||||
this.file.remove(false);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -241,12 +241,14 @@ const Editor = Module("editor", {
|
||||
return -1;
|
||||
},
|
||||
|
||||
editFileExternally: function (path, line, column, async) {
|
||||
let args = options.get("editor").format({ file: path, line: line, column: column });
|
||||
editFileExternally: function (args, blocking) {
|
||||
if (!isObject(args))
|
||||
args = { file: args };
|
||||
let args = options.get("editor").format(args);
|
||||
|
||||
dactyl.assert(args.length >= 1, "No editor specified");
|
||||
|
||||
io.run(io.expandPath(args.shift()), args, !async);
|
||||
io.run(io.expandPath(args.shift()), args, blocking);
|
||||
},
|
||||
|
||||
// TODO: clean up with 2 functions for textboxes and currentEditor?
|
||||
@@ -309,11 +311,10 @@ const Editor = Module("editor", {
|
||||
}
|
||||
}
|
||||
|
||||
let timer = services.Timer();
|
||||
timer.initWithCallback({ notify: update }, 100, timer.TYPE_REPEATING_SLACK);
|
||||
let timer = services.Timer(update, 100, services.Timer.TYPE_REPEATING_SLACK);
|
||||
|
||||
try {
|
||||
this.editFileExternally(tmpfile.path, line, column);
|
||||
this.editFileExternally({ file: tmpfile.path, line: line, column: column }, true);
|
||||
}
|
||||
finally {
|
||||
timer.cancel();
|
||||
|
||||
@@ -230,12 +230,9 @@ const IO = Module("io", {
|
||||
*
|
||||
* @param {string} program The program to run.
|
||||
* @param {string[]} args An array of arguments to pass to *program*.
|
||||
* @param {boolean} blocking Whether to wait until the process terminates.
|
||||
*/
|
||||
blockingProcesses: [],
|
||||
run: function (program, args, blocking) {
|
||||
args = args || [];
|
||||
blocking = !!blocking;
|
||||
|
||||
let file;
|
||||
|
||||
@@ -274,12 +271,19 @@ lookup:
|
||||
return -1;
|
||||
}
|
||||
|
||||
let process = services.Process();
|
||||
|
||||
process.init(file);
|
||||
let process = services.Process(file);
|
||||
process.run(false, args.map(String), args.length);
|
||||
try {
|
||||
if (blocking)
|
||||
if (callable(blocking))
|
||||
var timer = services.Timer(
|
||||
function () {
|
||||
if (!process.isRunning) {
|
||||
timer.cancel();
|
||||
callback();
|
||||
}
|
||||
},
|
||||
100, services.Timer.TYPE_REPEATING_SLACK);
|
||||
else if (blocking)
|
||||
while (process.isRunning)
|
||||
util.threadYield(false, true);
|
||||
}
|
||||
@@ -453,16 +457,18 @@ lookup:
|
||||
* @returns {boolean} false if temp files couldn't be created,
|
||||
* otherwise, the return value of *func*.
|
||||
*/
|
||||
withTempFiles: function (func, self) {
|
||||
withTempFiles: function (func, self, checked) {
|
||||
let args = util.map(util.range(0, func.length), this.createTempFile);
|
||||
try {
|
||||
if (!args.every(util.identity))
|
||||
return false;
|
||||
return func.apply(self || this, args);
|
||||
var res = func.apply(self || this, args);
|
||||
}
|
||||
finally {
|
||||
args.forEach(function (f) f && f.remove(false));
|
||||
if (!checked || res !== true)
|
||||
args.forEach(function (f) f && f.remove(false));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}, {
|
||||
/**
|
||||
|
||||
@@ -66,9 +66,9 @@ const Services = Module("Services", {
|
||||
this.addClass("Find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);
|
||||
this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", Ci.nsIFormatConverter);
|
||||
this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", Ci.nsIDocumentEncoder);
|
||||
this.addClass("Process", "@mozilla.org/process/util;1", Ci.nsIProcess);
|
||||
this.addClass("Process", "@mozilla.org/process/util;1", Ci.nsIProcess, "init");
|
||||
this.addClass("String", "@mozilla.org/supports-string;1", Ci.nsISupportsString);
|
||||
this.addClass("Timer", "@mozilla.org/timer;1", Ci.nsITimer);
|
||||
this.addClass("Timer", "@mozilla.org/timer;1", Ci.nsITimer, "initWithCallback");
|
||||
this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", Ci.nsIXMLHttpRequest);
|
||||
this.addClass("ZipReader", "@mozilla.org/libjar/zip-reader;1", Ci.nsIZipReader, "open");
|
||||
this.addClass("ZipWriter", "@mozilla.org/zipwriter;1", Ci.nsIZipWriter);
|
||||
@@ -80,7 +80,7 @@ const Services = Module("Services", {
|
||||
if (!ifaces)
|
||||
return res.wrappedJSObject;
|
||||
Array.concat(ifaces).forEach(function (iface) res.QueryInterface(iface));
|
||||
if (init)
|
||||
if (init && args.length)
|
||||
res[init].apply(res, args);
|
||||
return res;
|
||||
}
|
||||
@@ -120,7 +120,9 @@ const Services = Module("Services", {
|
||||
*/
|
||||
addClass: function (name, class_, ifaces, init) {
|
||||
const self = this;
|
||||
return this[name] = function () self._create(class_, ifaces, "createInstance", init, arguments);
|
||||
this[name] = function () self._create(class_, ifaces, "createInstance", init, arguments);
|
||||
update.apply(null, [this[name]].concat(ifaces));
|
||||
return this[name];
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user