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

Poll temp files in <C-i> so I don't have to be edgy every time I quit the editor.

This commit is contained in:
Kris Maglione
2010-10-05 02:05:24 -04:00
parent 24313887da
commit 57fe3fe9eb
2 changed files with 35 additions and 15 deletions

View File

@@ -1037,8 +1037,11 @@ const Buffer = Module("buffer", {
this.file = io.createTempFile(); this.file = io.createTempFile();
this.file.write(this.docShell.document.body.textContent); this.file.write(this.docShell.document.body.textContent);
} }
this.callback(this.file); try {
this.file.remove(false); this.callback(this.file);
} finally {
this.file.remove(false);
}
} }
finally { finally {
this.destroy(); this.destroy();

View File

@@ -348,28 +348,45 @@ const Editor = Module("editor", {
tmpBg = "yellow"; tmpBg = "yellow";
textBox.style.backgroundColor = "#bbbbbb"; textBox.style.backgroundColor = "#bbbbbb";
} }
else
var editor = GetCurrentEditor();
if (!tmpfile.write(text)) if (!tmpfile.write(text))
throw Error("Input contains characters not valid in the current " + throw Error("Input contains characters not valid in the current " +
"file encoding"); "file encoding");
this.editFileExternally(tmpfile.path); let lastUpdate = Date.now();
function update(force) {
if (force !== true && tmpfile.lastModifiedTime <= lastUpdate)
return;
lastUpdate = Date.now();
let val = tmpfile.read();
if (textBox)
textBox.value = val;
else {
let wholeDocRange = editor.document.createRange();
let rootNode = editor.rootElement.QueryInterface(Ci.nsIDOMNode);
wholeDocRange.selectNodeContents(rootNode);
editor.selection.addRange(wholeDocRange);
editor.selection.deleteFromDocument();
editor.insertText(val);
}
}
let timer = services.create("timer");
timer.initWithCallback({ notify: update }, 100, timer.TYPE_REPEATING_SLACK);
try {
this.editFileExternally(tmpfile.path);
} finally {
timer.cancel();
}
update(true);
if (textBox) if (textBox)
textBox.removeAttribute("readonly"); textBox.removeAttribute("readonly");
let val = tmpfile.read();
if (textBox)
textBox.value = val;
else {
let editor = GetCurrentEditor();
let wholeDocRange = editor.document.createRange();
let rootNode = editor.rootElement.QueryInterface(Ci.nsIDOMNode);
wholeDocRange.selectNodeContents(rootNode);
editor.selection.addRange(wholeDocRange);
editor.selection.deleteFromDocument();
editor.insertText(val);
}
}, this); }, this);
if (res == false) if (res == false)
throw Error("Couldn't create temporary file"); throw Error("Couldn't create temporary file");