1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 12:38:00 +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,9 +1037,12 @@ 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);
} }
try {
this.callback(this.file); this.callback(this.file);
} finally {
this.file.remove(false); this.file.remove(false);
} }
}
finally { finally {
this.destroy(); this.destroy();
} }

View File

@@ -348,21 +348,23 @@ 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 (textBox) if (force !== true && tmpfile.lastModifiedTime <= lastUpdate)
textBox.removeAttribute("readonly"); return;
lastUpdate = Date.now();
let val = tmpfile.read(); let val = tmpfile.read();
if (textBox) if (textBox)
textBox.value = val; textBox.value = val;
else { else {
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);
wholeDocRange.selectNodeContents(rootNode); wholeDocRange.selectNodeContents(rootNode);
@@ -370,6 +372,21 @@ const Editor = Module("editor", {
editor.selection.deleteFromDocument(); editor.selection.deleteFromDocument();
editor.insertText(val); 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)
textBox.removeAttribute("readonly");
}, this); }, this);
if (res == false) if (res == false)
throw Error("Couldn't create temporary file"); throw Error("Couldn't create temporary file");