diff --git a/core/modules/widgets/action-createtiddler.js b/core/modules/widgets/action-createtiddler.js index 01010b940..879f0d68d 100644 --- a/core/modules/widgets/action-createtiddler.js +++ b/core/modules/widgets/action-createtiddler.js @@ -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 }; diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index e792341d9..33745b898 100755 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -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 diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 508ca07f3..f77d68fa2 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -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 diff --git a/editions/tw5.com/tiddlers/widgets/ActionCreateTiddlerWidget.tid b/editions/tw5.com/tiddlers/widgets/ActionCreateTiddlerWidget.tid index a7d223e4e..ed2ffbb90 100644 --- a/editions/tw5.com/tiddlers/widgets/ActionCreateTiddlerWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ActionCreateTiddlerWidget.tid @@ -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 |