1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 11:18:00 +01:00

Use io.withTempFiles in editFieldExternally

This commit is contained in:
Kris Maglione
2008-12-17 21:22:52 -05:00
parent cf1b1ccf2d
commit e86ae1d6da

View File

@@ -825,53 +825,30 @@ function Editor() //{{{
else else
return false; return false;
let oldbg, tmpBg;
try try
{ {
var tmpfile = io.createTempFile(); let res = io.withTempFiles(function (tmpfile) {
} io.writeFile(tmpfile, text);
catch (e)
{
liberator.echoerr("Could not create temporary file: " + e.message);
return false;
}
try
{
io.writeFile(tmpfile, text);
}
catch (e)
{
liberator.echoerr("Could not write to temporary file " + tmpfile.path + ": " + e.message);
return false;
}
if (textBox) if (textBox)
{ {
textBox.setAttribute("readonly", "true"); textBox.setAttribute("readonly", "true");
var oldBg = textBox.style.backgroundColor; oldBg = textBox.style.backgroundColor;
var tmpBg = "yellow"; tmpBg = "yellow";
textBox.style.backgroundColor = "#bbbbbb"; textBox.style.backgroundColor = "#bbbbbb";
} }
this.editFileExternally(tmpfile.path); this.editFileExternally(tmpfile.path);
if (textBox) if (textBox)
textBox.removeAttribute("readonly"); textBox.removeAttribute("readonly");
// if (v:shell_error != 0)
// {
// tmpBg = "red";
// liberator.echoerr("External editor returned with exit code " + retcode);
// }
// else
// {
try
{
let val = io.readFile(tmpfile); let val = io.readFile(tmpfile);
if (textBox) if (textBox)
textBox.value = val; textBox.value = val;
else else
{ {
//document.getElementById("content-frame").contentDocument.designMode = "on";
let editor = GetCurrentEditor(); let editor = GetCurrentEditor();
let wholeDocRange = editor.document.createRange(); let wholeDocRange = editor.document.createRange();
let rootNode = editor.rootElement.QueryInterface(Ci.nsIDOMNode); let rootNode = editor.rootElement.QueryInterface(Ci.nsIDOMNode);
@@ -879,31 +856,31 @@ function Editor() //{{{
editor.selection.addRange(wholeDocRange); editor.selection.addRange(wholeDocRange);
editor.selection.deleteFromDocument(); editor.selection.deleteFromDocument();
editor.insertText(val); editor.insertText(val);
//setTimeout(function () {
// document.getElementById("content-frame").contentDocument.designMode = "off";
//}, 100);
} }
} }, this)
catch (e) if (res == false)
{ throw "Couldn't create temporary file";
tmpBg = "red"; }
liberator.echoerr("Could not read from temporary file " + tmpfile.path + ": " + e.message); catch (e)
} {
// } // Errors are unlikely, and our error messages won't
// likely be any more helpful than that given in the
// exception.
liberator.echoerr(e);
tmpBg = "red";
}
// blink the textbox after returning // blink the textbox after returning
if (textBox) if (textBox)
{ {
let timeout = 100;
let colors = [tmpBg, oldBg, tmpBg, oldBg]; let colors = [tmpBg, oldBg, tmpBg, oldBg];
(function () { (function () {
textBox.style.backgroundColor = colors.shift(); textBox.style.backgroundColor = colors.shift();
if (colors.length > 0) if (colors.length > 0)
setTimeout(arguments.callee, timeout); setTimeout(arguments.callee, 100);
})(); })();
} }
tmpfile.remove(false);
return true; return true;
}, },