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
print-window-tiddler
Jermolene 2015-08-04 17:44:07 +01:00
rodzic be0ebfeeae
commit 72ed4b2673
5 zmienionych plików z 103 dodań i 1 usunięć

Wyświetl plik

@ -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);
});
};
})();

Wyświetl plik

@ -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()));
}
});
}
}
})();

Wyświetl plik

@ -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

Wyświetl plik

@ -0,0 +1,3 @@
title: $:/tags/TextSlicerToolbar
list: $:/plugins/tiddlywiki/text-slicer/toolbar/title $:/plugins/tiddlywiki/text-slicer/toolbar/rename

Wyświetl plik

@ -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>>