mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-25 09:30:28 +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:
parent
be0ebfeeae
commit
72ed4b2673
28
core/modules/startup/bulkops.js
Normal file
28
core/modules/startup/bulkops.js
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
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()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
@ -14,10 +14,12 @@ The source document must first be marked up as an ordinary wikitext tiddler. Cur
|
|||||||
|
|
||||||
To try it out:
|
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]]
|
# View the tiddler [[Sliced up Sample Text]]
|
||||||
#* It should match the content of [[Sample Text]]
|
#* It should match the content of [[Sample Text]]
|
||||||
#* The table of contents at the top allows the structure to be explored
|
#* 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
|
! Plugin Instructions
|
||||||
|
|
||||||
|
3
plugins/tiddlywiki/text-slicer/tag-TextSlicerToolbar.tid
Normal file
3
plugins/tiddlywiki/text-slicer/tag-TextSlicerToolbar.tid
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
title: $:/tags/TextSlicerToolbar
|
||||||
|
list: $:/plugins/tiddlywiki/text-slicer/toolbar/title $:/plugins/tiddlywiki/text-slicer/toolbar/rename
|
||||||
|
|
16
plugins/tiddlywiki/text-slicer/toolbar-rename.tid
Normal file
16
plugins/tiddlywiki/text-slicer/toolbar-rename.tid
Normal file
@ -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=<<renameProxyTitle>> placeholder="Rename" default=<<currentTiddler>>/>
|
||||||
|
<$button>
|
||||||
|
<$action-sendmessage $message="tm-rename-tiddler" from=<<currentTiddler>> to={{$(renameProxyTitle)$}}/>
|
||||||
|
rename
|
||||||
|
</$button>
|
||||||
|
\end
|
||||||
|
|
||||||
|
<<body>>
|
Loading…
Reference in New Issue
Block a user