From 57fe3fe9eb22e81d3e5da86ccf74dba67c49d82e Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 5 Oct 2010 02:05:24 -0400 Subject: [PATCH] Poll temp files in so I don't have to be edgy every time I quit the editor. --- common/content/buffer.js | 7 +++++-- common/content/editor.js | 43 ++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/common/content/buffer.js b/common/content/buffer.js index 709c6eb8..38e1a468 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -1037,8 +1037,11 @@ const Buffer = Module("buffer", { this.file = io.createTempFile(); this.file.write(this.docShell.document.body.textContent); } - this.callback(this.file); - this.file.remove(false); + try { + this.callback(this.file); + } finally { + this.file.remove(false); + } } finally { this.destroy(); diff --git a/common/content/editor.js b/common/content/editor.js index f7bf6707..ecaa2a58 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -348,28 +348,45 @@ const Editor = Module("editor", { tmpBg = "yellow"; textBox.style.backgroundColor = "#bbbbbb"; } + else + var editor = GetCurrentEditor(); if (!tmpfile.write(text)) throw Error("Input contains characters not valid in the current " + "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) 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); if (res == false) throw Error("Couldn't create temporary file");