diff --git a/common/content/buffer.js b/common/content/buffer.js index ef1c2a82..3089256f 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -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; diff --git a/common/content/editor.js b/common/content/editor.js index 386a3194..af210936 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -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(); diff --git a/common/content/io.js b/common/content/io.js index e6d09e07..46464800 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -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; } }, { /** diff --git a/common/modules/services.jsm b/common/modules/services.jsm index 1460cf83..7be520f6 100644 --- a/common/modules/services.jsm +++ b/common/modules/services.jsm @@ -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]; }, /**