mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-10-31 23:26:18 +00:00
Add new hook "th-importing-files"
This commit is contained in:
parent
7bdaabce78
commit
518f57f4bb
@ -1177,6 +1177,22 @@ exports.readFile = function(file,options) {
|
|||||||
if($tw.log.IMPORT) {
|
if($tw.log.IMPORT) {
|
||||||
console.log("Importing file '" + file.name + "', type: '" + type + "', isBinary: " + isBinary);
|
console.log("Importing file '" + file.name + "', type: '" + type + "', isBinary: " + isBinary);
|
||||||
}
|
}
|
||||||
|
// Give the hook a chance to process the drag
|
||||||
|
if($tw.hooks.invokeHook("th-importing-file",{
|
||||||
|
file: file,
|
||||||
|
type: type,
|
||||||
|
isBinary: isBinary,
|
||||||
|
callback: callback
|
||||||
|
}) !== true) {
|
||||||
|
this.readFileContent(file,type,isBinary,options.deserializer,callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Lower level utility to read the content of a browser File object, invoking callback(tiddlerFieldsArray) with an array of tiddler fields objects
|
||||||
|
*/
|
||||||
|
exports.readFileContent = function(file,type,isBinary,deserializer,callback) {
|
||||||
|
var self = this;
|
||||||
// Create the FileReader
|
// Create the FileReader
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
// Onload
|
// Onload
|
||||||
@ -1198,7 +1214,7 @@ exports.readFile = function(file,options) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, just try to deserialise any tiddlers in the file
|
// Otherwise, just try to deserialise any tiddlers in the file
|
||||||
callback(self.deserializeTiddlers(type,text,tiddlerFields,{deserializer: options.deserializer}));
|
callback(self.deserializeTiddlers(type,text,tiddlerFields,{deserializer: deserializer}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Kick off the read
|
// Kick off the read
|
||||||
|
22
editions/dev/tiddlers/new/Hook__th-importing-file.tid
Normal file
22
editions/dev/tiddlers/new/Hook__th-importing-file.tid
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
created: 20171010115148355
|
||||||
|
modified: 20171010115148355
|
||||||
|
tags: HookMechanism
|
||||||
|
title: Hook: th-importing-file
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
This hook allows plugins to inspect or modify the details of files imported via drag and drop or the "import" button. It is invoked as each [[File object|https://developer.mozilla.org/en-US/docs/Web/API/File]] provided by the browser in response to an import or drag and drop is being read. The hook function can choose to ignore the file, in which case TiddlyWiki's default processing proceeds to read and import the content of the file. Alternatively, the hook function can process the file to extract the tiddlers itself, and then pass them back to TiddlyWiki to be handled by the rest of the import process.
|
||||||
|
|
||||||
|
Use this hook if you want to control how tiddlers are extracted from files during an import. See [[Hook: th-importing-tiddler]] if you want to process each imported tiddler after they have been extracted from the files.
|
||||||
|
|
||||||
|
Hook function parameters:
|
||||||
|
|
||||||
|
* ''info'': an object with properties containing information relating to the current file:
|
||||||
|
** ''file'': reference to the browser's [[File object|https://developer.mozilla.org/en-US/docs/Web/API/File]]
|
||||||
|
** ''type'': the MIME type of the file. If not provided by the browser then TiddlyWiki attempts to infer the type from the file extension
|
||||||
|
** ''isBinary'': flag for whether the file contains binary data (which requires that the file type be recognised by TiddlyWiki)
|
||||||
|
** ''callback'': callback function to be called with an array of tiddler field objects extracted from the file object
|
||||||
|
|
||||||
|
Return value:
|
||||||
|
|
||||||
|
* ''true'' indicates that the hook handled the file, and passed any extracted tiddlers to the callback
|
||||||
|
* ''false'' indicates that the hook didn't process the file
|
@ -1,10 +1,12 @@
|
|||||||
created: 20170209130829546
|
created: 20170209130829546
|
||||||
modified: 20170209145518777
|
modified: 20171010115148355
|
||||||
tags: HookMechanism
|
tags: HookMechanism
|
||||||
title: Hook: th-importing-tiddler
|
title: Hook: th-importing-tiddler
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
This hook allows plugins to inspect or modify tiddlers before they are imported via the import mechanism.
|
This hook allows plugins to inspect or modify tiddlers as they are imported via the import mechanism. It is invoked when the final "Import" button is clicked, and the selected tiddlers are being imported into the store.
|
||||||
|
|
||||||
|
Use this hook if you want to process each imported tiddler after they have been extracted from the files. See [[Hook: th-importing-file]] if you want to control how tiddlers are extracted from files during an import.
|
||||||
|
|
||||||
Hook function parameters:
|
Hook function parameters:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user