Action on open, reopen or close tiddler in a story

I would like to be able to set “Action on open, reopen or close tiddler in a story” to complement my work here https://all-button-actions.tiddlyhost.com/ which allows you to assign additional actions to almost any button.

On reflection I realised that “actions on open tiddler” is actually about when a tiddler enters a story (is opened) or is reopened (already in the story). This can be seen by reference to these two fields $:/StoryList!!list (in story) and $:/HistoryList!!current-tiddler(the recently opened or “focused tiddler”).

Can anyone suggest a way monitor these fields and generate an action according to the open and reopen “occurring” and close? We also need to identify the tiddler title in question.

  • From this we could meet the “action on open/reopen/close”, by trapping the “result of navigation events” rather than “capture all navigation events”.
    • We could also use this to work with substories and alternative stories.
  • Thus a user could use the default story or an alternative story in which open and reopen are detectable.
  • This seems to me a solution with less interference in the default behaviours and code.

Closing a tiddler;

  • By what ever means a user may close a tiddler they key fact is it is removed from $:/StoryList!!list so being able to detect this and trigger an action would also be helpful,
    • One could use additional actions on the close button such as in my all button actions solution however it would be easier and more comprehensive and efficient to detect when a title leaves the story.

Examples

  • Recording the time a given tiddler is open in the story.
    • Or We could start a timer when opened in the story $:/StoryList!!list.
      • and We could stop and accumulate a timer when removed from a story list $:/StoryList!!list.
  • An action triggered when a tiddler is first opened in a story could check if that tiddler has an “on-open-actions field” and trigger any actions named therein.

The first thing that comes to mind is the built-in hook mechanism:
https://tiddlywiki.com/dev/#HookMechanism
That requires building a JavaScript module, though.
In WikiText I think the best option would be to add a MessageCatcher in the PageTemplate that passes the message on, but also starts other actions. This is probably not doable without at least changing the tags on some core tiddlers (to replace them with your own), as you’ve probably already tried.

I, too, would be interested to hear other approaches.

Have a nice day
Yaisog

1 Like