var tabs = require("sdk/tabs");
var iofile = require("sdk/io/file");
var widgets = require("sdk/widget");
var selection = require("sdk/selection");
function console_log(text) {
console.log(selection.text);
}
function print(text) {
console.log(text);
}
function dir_object(object_to_parse) {
var name = '';
for (name in object_to_parse) {
print(name);
}
}
function write_text(filename, text) {
var fh = iofile.open(filename, 'w');
var content = fh.read();
dir_object(fh);
selected_text = text + "\n";
fh.write(selected_text);
fh.flush();
fh.close()
}
function select_text_handler() {
write_text('/tmp/foo', selection.text);
}
var widget = widgets.Widget({
id: "scribus-link",
label: "Scribus website",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function() {
}
});
selection.on('select', function () { select_text_handler(); });
“打开”“w”中的文件,这会截断我现有的文件!如何以“附加”模式打开然后“查找”?https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/io/file.htm https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/io/file.htm
The file
SDK的模块非常有限。当打开文件进行写入时,它总是会被截断(code https://github.com/mozilla/addon-sdk/blob/613de5ee8f5db7e81fd2d65416d8760c61a0bbd1/lib/sdk/io/file.js#L142-L144)。此外,它在主线程上使用完全同步的 I/O,这并不是一件好事,因为它会在 I/O 期间阻塞整个 UI。
您可能应该通过以下方式使用另一种机制chrome https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/tutorials/chrome.html模块。看OS.File https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread和/或MDN 文件 I/O 片段 https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O#Writing_to_a_file.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)