1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

Add several new hooks for UI actions

This commit is contained in:
Jermolene 2017-02-09 15:42:55 +00:00
parent 6b2ab90721
commit 2397f0aa6f
9 changed files with 117 additions and 10 deletions

View File

@ -245,6 +245,7 @@ NavigatorWidget.prototype.handleDeleteTiddlerEvent = function(event) {
tiddler = this.wiki.getTiddler(title),
storyList = this.getStoryList(),
originalTitle = tiddler ? tiddler.fields["draft.of"] : "",
originalTiddler = originalTitle ? this.wiki.getTiddler(originalTitle) : undefined,
confirmationTitle;
if(!tiddler) {
return false;
@ -268,10 +269,14 @@ NavigatorWidget.prototype.handleDeleteTiddlerEvent = function(event) {
}
// Delete the original tiddler
if(originalTitle) {
if(originalTiddler) {
$tw.hooks.invokeHook("th-deleting-tiddler",originalTiddler);
}
this.wiki.deleteTiddler(originalTitle);
this.removeTitleFromStory(storyList,originalTitle);
}
// Delete this tiddler
// Invoke the hook function and delete this tiddler
$tw.hooks.invokeHook("th-deleting-tiddler",tiddler);
this.wiki.deleteTiddler(title);
// Remove the closed tiddler from the story
this.removeTitleFromStory(storyList,title);
@ -568,7 +573,9 @@ NavigatorWidget.prototype.handlePerformImportEvent = function(event) {
$tw.utils.each(importData.tiddlers,function(tiddlerFields) {
var title = tiddlerFields.title;
if(title && importTiddler && importTiddler.fields["selection-" + title] !== "unchecked") {
self.wiki.addTiddler(new $tw.Tiddler(tiddlerFields));
var tiddler = new $tw.Tiddler(tiddlerFields);
tiddler = $tw.hooks.invokeHook("th-importing-tiddler",tiddler);
self.wiki.addTiddler(tiddler);
importReport.push("# [[" + tiddlerFields.title + "]]");
}
});

View File

@ -21,8 +21,10 @@ function renameTiddler(fromTitle,toTitle,options) {
options = options || {};
if(fromTitle && toTitle && fromTitle !== toTitle) {
// Rename the tiddler itself
var tiddler = this.getTiddler(fromTitle);
this.addTiddler(new $tw.Tiddler(tiddler,{title: toTitle},this.getModificationFields()));
var oldTiddler = this.getTiddler(fromTitle),
newTiddler = new $tw.Tiddler(oldTiddler,{title: toTitle},this.getModificationFields());
newTiddler = $tw.hooks.invokeHook("th-renaming-tiddler",newTiddler,oldTiddler);
this.addTiddler(newTiddler);
this.deleteTiddler(fromTitle);
// Rename any tags or lists that reference it
this.relinkTiddler(fromTitle,toTitle,options)
@ -66,7 +68,9 @@ console.log("Renaming list item '" + list[index] + "' to '" + toTitle + "' of ti
});
}
if(isModified) {
self.addTiddler(new $tw.Tiddler(tiddler,{tags: tags, list: list},self.getModificationFields()));
var newTiddler = new $tw.Tiddler(tiddler,{tags: tags, list: list},self.getModificationFields())
newTiddler = $tw.hooks.invokeHook("th-relinking-tiddler",newTiddler,tiddler);
self.addTiddler(newTiddler);
}
}
});

View File

@ -1,5 +1,5 @@
created: 20141122200310516
modified: 20141122200310516
modified: 20170209130807520
title: HookMechanism
type: text/vnd.tiddlywiki

View File

@ -0,0 +1,17 @@
created: 20170209115611070
modified: 20170209145906743
tags: HookMechanism
title: Hook: th-deleting-tiddler
type: text/vnd.tiddlywiki
This hook allows plugins to inspect tiddlers before they are deleted via the ''delete'' toolbar button. When the delete button is used from the edit toolbar there are actually two invocations of the `th-deleting-tiddler` hook function: one for the original tiddler and one for the draft.
Note that this hook is not invoked for tiddlers deleted by other means such as the ActionDeleteTiddlerWidget.
Hook function parameters:
* ''tiddler'': tiddler object about to be deleted
Return value:
* unmodified tiddler to be deleted

View File

@ -0,0 +1,23 @@
created: 20170209130829546
modified: 20170209145518777
tags: HookMechanism
title: Hook: th-importing-tiddler
type: text/vnd.tiddlywiki
This hook allows plugins to inspect or modify tiddlers before they are imported via the import mechanism.
Hook function parameters:
* ''tiddler'': tiddler object about to be imported
Return value:
* tiddler object to be imported
The original tiddler object can be returned unmodified by the hook. If the hook needs to modify the tiddler then it should return a new tiddler object, for example:
```
return new $tw.Tiddler(tiddler,{"my-field": value});
```
Hooks must not change the ''title'' field but can freely modify any other field of the tiddler.

View File

@ -0,0 +1,24 @@
created: 20170209145637233
modified: 20170209150007550
tags: HookMechanism
title: Hook: th-relinking-tiddler
type: text/vnd.tiddlywiki
This hook allows plugins to inspect tiddlers before they are relinked ("relinking" is the optional operation of relinking references to a tiddler when it is renamed).
Hook function parameters:
* ''newTiddler'': tiddler object incorporating the relinking
* ''oldTiddler'': optional existing tiddler object that will be overwritten
Return value:
* ''newTiddler'': tiddler object to be used for the relinking operation.
The original tiddler object can be returned unmodified by the hook. If the hook needs to modify the tiddler then it should return a new tiddler object, for example:
```
return new $tw.Tiddler(tiddler,{"my-field": value});
```
Hooks must not change the ''title'' field but can freely modify any other field of the tiddler.

View File

@ -0,0 +1,24 @@
created: 20170209145207186
modified: 20170209145633522
tags: HookMechanism
title: Hook: th-renaming-tiddler
type: text/vnd.tiddlywiki
This hook allows plugins to inspect tiddlers before they are modified by the `tm-rename-tiddler` message.
Hook function parameters:
* ''newTiddler'': tiddler object incorporating the rename
* ''oldTiddler'': optional existing tiddler object that will be overwritten
Return value:
* newTiddler: tiddler object to be used for the renaming operation.
The original tiddler object can be returned unmodified by the hook. If the hook needs to modify the tiddler then it should return a new tiddler object, for example:
```
return new $tw.Tiddler(tiddler,{"my-field": value});
```
Hooks must not change the ''title'' field but can freely modify any other field of the tiddler.

View File

@ -1,10 +1,17 @@
created: 20141122200310516
modified: 20141122200310516
modified: 20170209115548070
tags: HookMechanism
title: Hook: th-opening-default-tiddlers-list
type: text/vnd.tiddlywiki
This hook allows plugins to add to or remove from the list of tiddlers that are opened when the wiki is first loaded or the home button is clicked.
The function takes a list of tiddlers as its only argument and returns a modified list of tiddler titles to display.
Hook function parameters:
* ''list'': array of tiddler titles to be opened
Return value:
* modified array of tiddler titles to be opened
Note that this hook is invoked with the tiddler titles that are generated from the filter in [[$:/DefaultTiddlers]]. Any added entries must be tiddler titles, not filter expressions.

View File

@ -1,9 +1,10 @@
created: 20150908150314994
modified: 20150908150314994
modified: 20170209145506427
tags: HookMechanism
title: Hook: th-saving-tiddler
type: text/vnd.tiddlywiki
This hook allows plugins to modify tiddlers before they are saved via the ''confirm'' toolbar button; the hook is not invoked for tiddlers that are saved through other means, such as state tiddlers created by the ActionSetFieldWidget.
This hook allows plugins to inspect or modify tiddlers before they are saved via the ''confirm'' toolbar button; the hook is not invoked for tiddlers that are saved through other means, such as state tiddlers created by the ActionSetFieldWidget.
Hook function parameters: