mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-16 23:37:19 +00:00
Add renaming to text-slicer tiddler toolbar
The plan is to expose the functionality in other places, too - for example, the edit template and the tag manager
This commit is contained in:
53
core/modules/wiki-bulkops.js
Normal file
53
core/modules/wiki-bulkops.js
Normal file
@@ -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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user