1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 14:53:15 +00:00

Extend tm-import-tiddlers message (#4741)

* Allow tm-import-tiddlers event to override tv-auto-open-on-import

* Add autoOpenOnImport attribute to dropzone

* Updated DropZone docs

* Updated dropzone to support importTitle attribute

* Updated navigator to support importTitle attribute on tm-import-tiddlers

* Update dropzone docs for importTitle attribute

* Updated docs for tm-import-tiddlers

* Fixed formatting
This commit is contained in:
saqimtiaz 2020-06-27 13:32:11 +02:00 committed by GitHub
parent 64034f4977
commit d46872c061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 11 deletions

View File

@ -113,7 +113,7 @@ DropZoneWidget.prototype.handleDragEndEvent = function(event) {
DropZoneWidget.prototype.handleDropEvent = function(event) { DropZoneWidget.prototype.handleDropEvent = function(event) {
var self = this, var self = this,
readFileCallback = function(tiddlerFieldsArray) { readFileCallback = function(tiddlerFieldsArray) {
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)}); self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray), autoOpenOnImport: self.autoOpenOnImport, importTitle: self.importTitle});
}; };
this.leaveDrag(event); this.leaveDrag(event);
// Check for being over a TEXTAREA or INPUT // Check for being over a TEXTAREA or INPUT
@ -149,7 +149,7 @@ DropZoneWidget.prototype.handleDropEvent = function(event) {
DropZoneWidget.prototype.handlePasteEvent = function(event) { DropZoneWidget.prototype.handlePasteEvent = function(event) {
var self = this, var self = this,
readFileCallback = function(tiddlerFieldsArray) { readFileCallback = function(tiddlerFieldsArray) {
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)}); self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray), autoOpenOnImport: self.autoOpenOnImport, importTitle: self.importTitle});
}; };
// Let the browser handle it if we're in a textarea or input box // Let the browser handle it if we're in a textarea or input box
if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) == -1 && !event.target.isContentEditable) { if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) == -1 && !event.target.isContentEditable) {
@ -176,7 +176,7 @@ DropZoneWidget.prototype.handlePasteEvent = function(event) {
if($tw.log.IMPORT) { if($tw.log.IMPORT) {
console.log("Importing string '" + str + "', type: '" + type + "'"); console.log("Importing string '" + str + "', type: '" + type + "'");
} }
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify([tiddlerFields])}); self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify([tiddlerFields]), autoOpenOnImport: self.autoOpenOnImport, importTitle: self.importTitle});
}); });
} }
} }
@ -193,6 +193,8 @@ DropZoneWidget.prototype.execute = function() {
this.dropzoneClass = this.getAttribute("class"); this.dropzoneClass = this.getAttribute("class");
this.dropzoneDeserializer = this.getAttribute("deserializer"); this.dropzoneDeserializer = this.getAttribute("deserializer");
this.dropzoneEnable = (this.getAttribute("enable") || "yes") === "yes"; this.dropzoneEnable = (this.getAttribute("enable") || "yes") === "yes";
this.autoOpenOnImport = this.getAttribute("autoOpenOnImport");
this.importTitle = this.getAttribute("importTitle");
// Make child widgets // Make child widgets
this.makeChildWidgets(); this.makeChildWidgets();
}; };
@ -202,7 +204,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/ */
DropZoneWidget.prototype.refresh = function(changedTiddlers) { DropZoneWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes(); var changedAttributes = this.computeAttributes();
if(changedAttributes.enable) { if(changedAttributes.enable || changedAttributes.autoOpenOnImport || changedAttributes.importTitle || changedAttributes.deserializer || changedAttributes.class) {
this.refreshSelf(); this.refreshSelf();
return true; return true;
} }

View File

@ -494,10 +494,11 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) {
} catch(e) { } catch(e) {
} }
// Get the current $:/Import tiddler // Get the current $:/Import tiddler
var importTiddler = this.wiki.getTiddler(IMPORT_TITLE), var importTitle = event.importTitle ? event.importTitle : IMPORT_TITLE,
importData = this.wiki.getTiddlerData(IMPORT_TITLE,{}), importTiddler = this.wiki.getTiddler(importTitle),
importData = this.wiki.getTiddlerData(importTitle,{}),
newFields = new Object({ newFields = new Object({
title: IMPORT_TITLE, title: importTitle,
type: "application/json", type: "application/json",
"plugin-type": "import", "plugin-type": "import",
"status": "pending" "status": "pending"
@ -528,15 +529,16 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) {
newFields.text = JSON.stringify(importData,null,$tw.config.preferences.jsonSpaces); newFields.text = JSON.stringify(importData,null,$tw.config.preferences.jsonSpaces);
this.wiki.addTiddler(new $tw.Tiddler(importTiddler,newFields)); this.wiki.addTiddler(new $tw.Tiddler(importTiddler,newFields));
// Update the story and history details // Update the story and history details
if(this.getVariable("tv-auto-open-on-import") !== "no") { var autoOpenOnImport = event.autoOpenOnImport ? event.autoOpenOnImport : this.getVariable("tv-auto-open-on-import");
if(autoOpenOnImport !== "no") {
var storyList = this.getStoryList(), var storyList = this.getStoryList(),
history = []; history = [];
// Add it to the story // Add it to the story
if(storyList && storyList.indexOf(IMPORT_TITLE) === -1) { if(storyList && storyList.indexOf(importTitle) === -1) {
storyList.unshift(IMPORT_TITLE); storyList.unshift(importTitle);
} }
// And to history // And to history
history.push(IMPORT_TITLE); history.push(importTitle);
// Save the updated story and history // Save the updated story and history
this.saveStoryList(storyList); this.saveStoryList(storyList);
this.addToHistory(history); this.addToHistory(history);

View File

@ -9,6 +9,8 @@ The `tm-import-tiddlers` message inserts a list of tiddlers into the pending imp
|!Name |!Description | |!Name |!Description |
|param |JSON text of the array of tiddlers to be imported | |param |JSON text of the array of tiddlers to be imported |
|autoOpenOnImport |<<.from-version "5.1.23">> Optional value "no" or "yes" that can override tv-auto-open-on-import |
|importTitle|<<.from-version "5.1.23">> optional tiddler title to use for import process instead of ~$:/Import |
The import tiddlers message is usually generated with the DropzoneWidget or the BrowseWidget, and is handled by the NavigatorWidget. The import tiddlers message is usually generated with the DropzoneWidget or the BrowseWidget, and is handled by the NavigatorWidget.

View File

@ -17,6 +17,8 @@ It sends a [[WidgetMessage: tm-import-tiddlers]] carrying a JSON representation
|deserializer |<<.from-version "5.1.15">> Optional name of deserializer to be used (by default the deserializer is derived from the file extension) | |deserializer |<<.from-version "5.1.15">> Optional name of deserializer to be used (by default the deserializer is derived from the file extension) |
|enable |<<.from-version "5.1.22">> Optional value "no" to disable the dropzone functionality (defaults to "yes") | |enable |<<.from-version "5.1.22">> Optional value "no" to disable the dropzone functionality (defaults to "yes") |
|class |<<.from-version "5.1.22">> Optional CSS class to be assigned to the dropzone (defaults to "tc-drag-over") | |class |<<.from-version "5.1.22">> Optional CSS class to be assigned to the dropzone (defaults to "tc-drag-over") |
|autoOpenOnImport |<<.from-version "5.1.23">> Optional value "no" or "yes" that can override tv-auto-open-on-import |
|importTitle|<<.from-version "5.1.23">> optional tiddler title to use for import process instead of ~$:/Import |
The list of available deserializers can be inspected by executing `Object.keys($tw.Wiki.tiddlerDeserializerModules).sort().join("\n")` in the browser JavaScript console. The list of available deserializers can be inspected by executing `Object.keys($tw.Wiki.tiddlerDeserializerModules).sort().join("\n")` in the browser JavaScript console.