mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-12 12:59:57 +00:00
Improve action-createtiddler to return a draft title too
This commit is contained in:
parent
72c64013c7
commit
28c732d2be
@ -37,6 +37,7 @@ Compute the internal state of the widget
|
||||
CreateTiddlerWidget.prototype.execute = function() {
|
||||
this.actionBaseTitle = this.getAttribute("$basetitle");
|
||||
this.actionSaveTitle = this.getAttribute("$savetitle");
|
||||
this.actionSaveDraftTitle = this.getAttribute("$savedrafttitle");
|
||||
this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes";
|
||||
};
|
||||
|
||||
@ -73,6 +74,9 @@ CreateTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
if(this.actionSaveTitle) {
|
||||
this.wiki.setTextReference(this.actionSaveTitle,title,this.getVariable("currentTiddler"));
|
||||
}
|
||||
if(this.actionSaveDraftTitle) {
|
||||
this.wiki.setTextReference(this.actionSaveDraftTitle,this.wiki.generateDraftTitle(title),this.getVariable("currentTiddler"));
|
||||
}
|
||||
return true; // Action was invoked
|
||||
};
|
||||
|
||||
|
@ -279,15 +279,7 @@ NavigatorWidget.prototype.makeDraftTiddler = function(targetTitle) {
|
||||
Generate a title for the draft of a given tiddler
|
||||
*/
|
||||
NavigatorWidget.prototype.generateDraftTitle = function(title) {
|
||||
var c = 0,
|
||||
draftTitle,
|
||||
username = this.wiki.getTiddlerText("$:/status/UserName"),
|
||||
attribution = username ? " by " + username : "";
|
||||
do {
|
||||
draftTitle = "Draft " + (c ? (c + 1) + " " : "") + "of '" + title + "'" + attribution;
|
||||
c++;
|
||||
} while(this.wiki.tiddlerExists(draftTitle));
|
||||
return draftTitle;
|
||||
return this.wiki.generateDraftTitle(title);
|
||||
};
|
||||
|
||||
// Take a tiddler out of edit mode, saving the changes
|
||||
|
@ -1402,6 +1402,21 @@ exports.addToStory = function(title,fromTitle,storyTitle,options) {
|
||||
story.addToStory(title,fromTitle,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Generate a title for the draft of a given tiddler
|
||||
*/
|
||||
exports.generateDraftTitle = function(title) {
|
||||
var c = 0,
|
||||
draftTitle,
|
||||
username = this.getTiddlerText("$:/status/UserName"),
|
||||
attribution = username ? " by " + username : "";
|
||||
do {
|
||||
draftTitle = "Draft " + (c ? (c + 1) + " " : "") + "of '" + title + "'" + attribution;
|
||||
c++;
|
||||
} while(this.tiddlerExists(draftTitle));
|
||||
return draftTitle;
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the available upgrader modules
|
||||
titles: array of tiddler titles to be processed
|
||||
|
@ -1,6 +1,6 @@
|
||||
caption: action-createtiddler
|
||||
created: 20161020152745942
|
||||
modified: 20161020155119177
|
||||
modified: 20190604113017742
|
||||
tags: Widgets ActionWidgets
|
||||
title: ActionCreateTiddlerWidget
|
||||
type: text/vnd.tiddlywiki
|
||||
@ -21,6 +21,7 @@ The ''action-createtiddler'' widget is invisible. Any content within it is ignor
|
||||
|!Attribute |!Description |
|
||||
|$basetitle |The initial title that will be attempted. If a tiddler with that title already exists, then a numerical counter is added to the title and incremented until it is unique|
|
||||
|$savetitle |A text reference identifying a field or index into which the title of the newly created tiddler will be stored after it is created |
|
||||
|$savedrafttitle |<<.from-version "5.1.20">> A text reference identifying a field or index into which the draft title associated with the newly created tiddler will be stored after it is created. This is useful when using a sequence of action widgets to create a new tiddler, put it into edit mode, and position it within the list of its parent tag |
|
||||
|$timestamp |Specifies whether the timestamp(s) of the target tiddler will be updated (''modified'' and ''modifier'', plus ''created'' and ''creator'' for newly created tiddlers). Can be "yes" (the default) or "no" |
|
||||
|//{any attributes not starting with $}// |Each attribute name specifies a field to be created in the new tiddler |
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user