Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion content/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The JavaScript in this file is injected into each TiddlyWiki page that loads
var message = document.createElement("div");
message.setAttribute("data-tiddlyfox-path",path);
message.setAttribute("data-tiddlyfox-content",content);
message.setAttribute("data-tiddlyfox-tw2","true");
messageBox.appendChild(message);
// Create and dispatch the custom event to the extension
var event = document.createEvent("Events");
Expand Down Expand Up @@ -52,4 +53,4 @@ The JavaScript in this file is injected into each TiddlyWiki page that loads
window.convertUriToUTF8 = injectedConvertUriToUTF8;
window.convertUnicodeToFileFormat = injectedConvertUnicodeToFileFormat;

})();
})();
30 changes: 26 additions & 4 deletions content/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,20 @@ var TiddlyFox = {
// Attach the event handler to the message box
messageBox.addEventListener("tiddlyfox-save-file",TiddlyFox.onSaveFile,false);
},

moveFile: function(sourcefile,destdir,destfile) {
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(sourcefile);

var dir = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
dir.initWithPath(destdir);

file.moveTo(dir,destfile);
},

saveFile: function(filePath,content) {
saveFile: function(filePath,content,destdir,destfile) {
// Attempt to convert the filepath to a proper UTF-8 string
try {
var converter = Components.classes["@mozilla.org/intl/utf8converterservice;1"].getService(Components.interfaces.nsIUTF8ConverterService);
Expand All @@ -90,6 +102,9 @@ var TiddlyFox = {
}
// Save the file
try {
if (destdir) {
TiddlyFox.moveFile(filePath,destdir,destfile);
}
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
Expand All @@ -112,10 +127,17 @@ var TiddlyFox = {
// Get the details from the message
var message = event.target,
path = message.getAttribute("data-tiddlyfox-path"),
content = message.getAttribute("data-tiddlyfox-content");
content = message.getAttribute("data-tiddlyfox-content"),
backupdir = message.getAttribute("data-tiddlyfox-backupdir"),
backupfile = message.getAttribute("data-tiddlyfox-backupfile"),
tw2 = message.getAttribute("data-tiddlyfox-tw2");
// Save the file
TiddlyFox.saveFile(path,content);
// Remove the message element from the message box
if (tw2) {
TiddlyFox.saveFile(path,content);
}
else {
TiddlyFox.saveFile(path,content,backupdir,backupfile);
}
message.parentNode.removeChild(message);
// Send a confirmation message
var event = document.createEvent("Events");
Expand Down
Binary file modified tiddlyfox.xpi
Binary file not shown.