diff --git a/core/modules/startup/bulkops.js b/core/modules/startup/bulkops.js new file mode 100644 index 000000000..d70afadaa --- /dev/null +++ b/core/modules/startup/bulkops.js @@ -0,0 +1,28 @@ +/*\ +title: $:/core/modules/startup/bulkops.js +type: application/javascript +module-type: startup + +Support for bulk tiddler operations + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +// Export name and synchronous status +exports.name = "bulkops"; +exports.platforms = ["browser"]; +exports.after = ["startup"]; +exports.synchronous = true; + +exports.startup = function() { + $tw.rootWidget.addEventListener("tm-rename-tiddler",function(event) { + var paramObject = event.paramObject || {}; + $tw.wiki.renameTiddler(paramObject.from,paramObject.to); + }); +}; + +})(); diff --git a/core/modules/wiki-bulkops.js b/core/modules/wiki-bulkops.js new file mode 100644 index 000000000..ce72f1c99 --- /dev/null +++ b/core/modules/wiki-bulkops.js @@ -0,0 +1,53 @@ +/*\ +title: $:/core/modules/wiki-bulkops.js +type: application/javascript +module-type: wikimethod + +Bulk tiddler operations such as rename. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Rename a tiddler, and relink any tags or lists that reference it. +*/ +exports.renameTiddler = function(fromTitle,toTitle) { + var self = this; + fromTitle = (fromTitle || "").trim(); + toTitle = (toTitle || "").trim(); + if(fromTitle && toTitle && fromTitle !== toTitle) { + // Rename the tiddler itself + var tiddler = this.getTiddler(fromTitle); + this.addTiddler(new $tw.Tiddler(tiddler,{title: toTitle},this.getModificationFields())); + this.deleteTiddler(fromTitle); + // Rename any tags or lists that reference it + this.each(function(tiddler,title) { + var tags = (tiddler.fields.tags || []).slice(0), + list = (tiddler.fields.list || []).slice(0), + isModified = false; + // Rename tags + $tw.utils.each(tags,function (title,index) { + if(title === fromTitle) { + tags[index] = toTitle; + isModified = true; + } + }); + // Rename lists + $tw.utils.each(list,function (title,index) { + if(title === fromTitle) { + list[index] = toTitle; + isModified = true; + } + }); + if(isModified) { + self.addTiddler(new $tw.Tiddler(tiddler,{tags: tags, list: list},self.getModificationFields())); + } + }); + } +} + +})(); diff --git a/editions/text-slicer/tiddlers/HelloThere.tid b/editions/text-slicer/tiddlers/HelloThere.tid index 1a933f955..24d2d6438 100644 --- a/editions/text-slicer/tiddlers/HelloThere.tid +++ b/editions/text-slicer/tiddlers/HelloThere.tid @@ -14,10 +14,12 @@ The source document must first be marked up as an ordinary wikitext tiddler. Cur To try it out: -# Click the "text slicer" icon on the [[Sample Text]] tiddler below +# Click the ''text slicer'' icon on the [[Sample Text]] tiddler below # View the tiddler [[Sliced up Sample Text]] #* It should match the content of [[Sample Text]] #* The table of contents at the top allows the structure to be explored +# Click the ''Show toolbar'' checkbox to display a simple toolbar for each tiddler +# Use the text box and the ''rename'' button to rename tiddlers without breaking the tagging links ! Plugin Instructions diff --git a/plugins/tiddlywiki/text-slicer/tag-TextSlicerToolbar.tid b/plugins/tiddlywiki/text-slicer/tag-TextSlicerToolbar.tid new file mode 100644 index 000000000..ef2f27cd4 --- /dev/null +++ b/plugins/tiddlywiki/text-slicer/tag-TextSlicerToolbar.tid @@ -0,0 +1,3 @@ +title: $:/tags/TextSlicerToolbar +list: $:/plugins/tiddlywiki/text-slicer/toolbar/title $:/plugins/tiddlywiki/text-slicer/toolbar/rename + diff --git a/plugins/tiddlywiki/text-slicer/toolbar-rename.tid b/plugins/tiddlywiki/text-slicer/toolbar-rename.tid new file mode 100644 index 000000000..a11f10bbd --- /dev/null +++ b/plugins/tiddlywiki/text-slicer/toolbar-rename.tid @@ -0,0 +1,16 @@ +title: $:/plugins/tiddlywiki/text-slicer/toolbar/rename +tags: $:/tags/TextSlicerToolbar + +\define renameProxyTitle() +$:/config/plugins/tiddlywiki/text-slicer/rename-$(currentTiddler)$ +\end + +\define body() +<$edit-text tag="input" tiddler=<> placeholder="Rename" default=<>/> +<$button> +<$action-sendmessage $message="tm-rename-tiddler" from=<> to={{$(renameProxyTitle)$}}/> +rename + +\end + +<> \ No newline at end of file