TiddlyFox update to work with Unicode paths

print-window-tiddler
Jeremy Ruston 2012-09-01 16:31:21 +01:00
rodzic 460dffa08f
commit 0d4ea62ef8
3 zmienionych plików z 18 dodań i 5 usunięć

Wyświetl plik

@ -13,8 +13,8 @@ The JavaScript in this file is injected into each TiddlyWiki page that loads
if(messageBox) { if(messageBox) {
// Create the message element and put it in the message box // Create the message element and put it in the message box
var message = document.createElement("div"); var message = document.createElement("div");
message.setAttribute("tiddlyfox-path",path); message.setAttribute("data-tiddlyfox-path",path);
message.setAttribute("tiddlyfox-content",content); message.setAttribute("data-tiddlyfox-content",content);
messageBox.appendChild(message); messageBox.appendChild(message);
// Create and dispatch the custom event to the extension // Create and dispatch the custom event to the extension
var event = document.createEvent("Events"); var event = document.createEvent("Events");
@ -31,7 +31,7 @@ The JavaScript in this file is injected into each TiddlyWiki page that loads
try { try {
// Just the read the file synchronously // Just the read the file synchronously
var xhReq = new XMLHttpRequest(); var xhReq = new XMLHttpRequest();
xhReq.open("GET", "file://" + path, false); xhReq.open("GET", "file://" + escape(path), false);
xhReq.send(null); xhReq.send(null);
return xhReq.responseText; return xhReq.responseText;
} catch(ex) { } catch(ex) {
@ -39,7 +39,12 @@ The JavaScript in this file is injected into each TiddlyWiki page that loads
} }
}; };
var injectedConvertUriToUTF8 = function(path) {
return path;
}
window.mozillaSaveFile = injectedSaveFile; window.mozillaSaveFile = injectedSaveFile;
window.mozillaLoadFile = injectedLoadFile; window.mozillaLoadFile = injectedLoadFile;
window.convertUriToUTF8 = injectedConvertUriToUTF8;
})(); })();

Wyświetl plik

@ -62,6 +62,14 @@ var TiddlyFox = {
}, },
saveFile: function(filePath,content) { saveFile: function(filePath,content) {
// Attempt to convert the filepath to a proper UTF-8 string
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var converter = Components.classes["@mozilla.org/intl/utf8converterservice;1"].getService(Components.interfaces.nsIUTF8ConverterService);
filePath = converter.convertURISpecToUTF8(filePath,"UTF-8");
} catch(ex) {
}
// Save the file
try { try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
@ -82,8 +90,8 @@ var TiddlyFox = {
onSaveFile: function(event) { onSaveFile: function(event) {
// Get the details from the message // Get the details from the message
var message = event.target, var message = event.target,
path = message.getAttribute("tiddlyfox-path"), path = message.getAttribute("data-tiddlyfox-path"),
content = message.getAttribute("tiddlyfox-content"); content = message.getAttribute("data-tiddlyfox-content");
// Save the file // Save the file
TiddlyFox.saveFile(path,content); TiddlyFox.saveFile(path,content);
// Remove the message element from the message box // Remove the message element from the message box

Plik binarny nie jest wyświetlany.