Hook defined in startup module not working

93 views
Skip to first unread message

bimlas

unread,
Jan 31, 2020, 3:33:55 AM1/31/20
to TiddlyWikiDev
Dear all,

I would like to execute events when a tiddler is renamed, but even though I wrote my startup module from the snippets of "$:/plugins/tiddlywiki/savetrail/savetrail.js", for some reason only the default text "Relinking 'X' to 'Y'" appears in the developer console, "RENAMED" and "RELINKED" no (so it doesn't seem to execute the hook). On page load it prints "LOADED" to the console, so it loads the startup module. I also thought that I might just not be able to write to the console, so I also tried to create a tiddler, but that didn't happen either. What could be the problem?

/*\
title: $:/plugins/bimlas/my-plugin/startup/relink-or-rename.js
type: application/javascript
module-type: startup

Hook on rename

\*/

(function() {

 
/*jslint node: true, browser: false */
 
/*global $tw: true */
 
"use strict";

 
// Export name and synchronous status
 exports
.name = "my-rename-hook";
 exports
.platforms = ["browser"];
 exports
.after = ["startup"];
 exports
.synchronous = true;

 exports
.startup = function() {

   console
.log('LOADED');

   $tw
.hooks.addHook("th-renaming-tiddler",function handleEvent(newTiddler, tiddler) {
     console
.log('RENAME',newTiddler);
     $tw
.wiki.addTiddler(new $tw.Tiddler({title: "NAME CHANGED", text: "rename"}));
     
return newTiddler;
   
});

   $tw
.hooks.addHook("th-relinking-tiddler",function handleEvent(newTiddler, tiddler) {
     console
.log('RELINK', newTiddler);
     $tw
.wiki.addTiddler(new $tw.Tiddler({title: "NAME CHANGED", text: "relink"}));
     
return newTiddler;
   
});
 
};
})();



bimlas

unread,
Jan 31, 2020, 4:16:21 AM1/31/20
to TiddlyWikiDev
I've found the problem: the tiddler I wanted to rename was not listed in othe tiddler's fields (neither in the "tags" nor in the "list" field), so the hook didn't executed and therefore the messages didn't appear.

Can I create hooks that will be executed anyway when renaming, even if they have not been changed in the "list" or "tags" field?

Jeremy Ruston

unread,
Jan 31, 2020, 4:26:50 AM1/31/20
to TiddlyWikiDev
Hi Bimlas

The th-renaming-tiddler hook is intended to be invoked for every tiddler that is renamed, with the th-relinking-tiddler hook just being invoked for any relinking operations required as part of the rename. If the th-renaming-tiddler hook is not being invoked then I think there must be something else awry,

Best wishes

Jeremy

On 31 Jan 2020, at 09:16, bimlas <bimba....@gmail.com> wrote:

I've found the problem: the tiddler I wanted to rename was not listed in othe tiddler's fields (neither in the "tags" nor in the "list" field), so the hook didn't executed and therefore the messages didn't appear.

Can I create hooks that will be executed anyway when renaming, even if they have not been changed in the "list" or "tags" field?

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/08efea4e-0b4f-4913-b26b-f070d4b3dc33%40googlegroups.com.

bimlas

unread,
Jan 31, 2020, 4:50:58 AM1/31/20
to TiddlyWikiDev
Jeremy,

The "th-renaming-tiddler" hook is invoked by "$:/core/modules/wiki-bulkops.js" -> "renameTiddler()".
However, this event is only sent by the "text-slicer" and "xslx-utils" plugins, I have not found it anywhere else

So the "tm-renaming-tiddler" event will not be executed for example in empty edition, the "th-renaming-tiddler" hook will not execute.

bimlas

unread,
Jan 31, 2020, 7:41:44 AM1/31/20
to TiddlyWikiDev
I tried importing the above example into the Text-Slicer edition and after slicing the example text when I turned on the toolbar (which sends the "tm-rename-tiddler" message) in the left sidebar and renamed the tiddler there, in the console "RENAME" appeared, so the hook is executed here, but if for example i open the tiddler itself in edit mode and rewrite its name, the hook doesn't execute.

Jeremy Ruston

unread,
Jan 31, 2020, 7:48:30 AM1/31/20
to tiddly...@googlegroups.com
Hi Bimlas

Apologies, you’re correct, the tm-rename-tiddler event isn’t used by the core (it’s only required when renaming a tiddler directly, rather than via the edit template). But the navigator widget certainly should be invoking the renaming/relinking hooks, and I’d be happy to see it changed.

Best wishes

Jeremy.

On 31 Jan 2020, at 12:41, bimlas <bimba....@gmail.com> wrote:

I tried importing the above example into the Text-Slicer edition and after slicing the example text when I turned on the toolbar (which sends the "tm-rename-tiddler" message) in the left sidebar and renamed the tiddler there, in the console "RENAME" appeared, so the hook is executed here, but if for example i open the tiddler itself in edit mode and rewrite its name, the hook doesn't execute.

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.

bimlas

unread,
Jan 31, 2020, 9:19:47 AM1/31/20
to TiddlyWikiDev
For readers of this thread, I've opened the pull request: https://github.com/Jermolene/TiddlyWiki5/pull/4434

Mirko Richter

unread,
Jun 18, 2020, 6:15:47 AM6/18/20
to tiddly...@googlegroups.com

Hi! I came accross exactly the issue discussed here andin https://github.com/Jermolene/TiddlyWiki5/pull/4434.


My Use-Case is just as follows: Beside tags and list renaming (that is directly supported by TW5) i want to update my own list-fields (custom named) on ANY title-change (API or manual via editor) that occurs. As far as i understand the TW5-code, the best way to implement that is to listen on exactly the mentioned "th-renaming-tiddler"-event but that is not fired when renaming a tiddler by the standard edit-mode.

Or is there any other approach i should use that i don't see now (beside changing core-code)?


Thanks,
Mirko

Saq Imtiaz

unread,
Jun 18, 2020, 7:14:10 AM6/18/20
to TiddlyWikiDev
There is no way at present to hook into renaming that occurs via the standard edit template, which I think is a shortcoming that needs to be addressed. Looks like Jeremy is on the case for that.

TonyM

unread,
Jun 18, 2020, 11:58:59 PM6/18/20
to TiddlyWikiDev
Mirko,

when renaming a tiddler by the standard edit-mode
Does this mean in an interactive wiki?
 
you could use the new relink plugin, which means you need not bother with firing an event in that case.

Ignore me if I am off target.

TW Tones
Reply all
Reply to author
Forward
0 new messages