Folks,
Please find attached a macro (or version of) I would like to have included in the next release.
Why?
- This will allow the ability to add actions (Action Widgets) to existing buttons such that macros, plugins and solutions can make use of the existing button use, this is in a hackable way to avoid core tiddler changes (after this facility is added to the core buttons.
- There are many actions a user/designers may want to do within tiddlywiki which requires a trigger, this typically forces the bespoke button to achieve this, and demands the user click another button. By leveraging the existing buttons new actions can be added at appropriate times including but not limited to examples such as;
- On edit button
- On close or Done
- On save-wiki
button-actions-macro.json (515 Bytes)
\define button-actions(buttonname)
<$list filter="[tag[$:/tags/button-actions/$buttonname$]]" variable=button-action-tiddler>
<$transclude tiddler=<<button-action-tiddler>>/>
</$list>
\end
;Button action tags in use
<$list filter="[tags[]prefix[$:/tags/button-actions/]]" variable=button-action-tag>
<$macrocall $name=tag tag=<<button-action-tag>>/>
</$list>
Note: after the \end
is ignored when generating the macros, what follows helps users track the tags in use.
It can be installed on tiddlywiki.com with no apparent changes beyond the macros existence.
This enables a macro as follows;
<<button-actions "buttonname">>
where button name is an arbitrary button name, although a later step would be to update the majority of core buttons to use this (described later).
This macro however will transclude all tiddlers into the actions parameter tagged
$:/tags/button-actions/buttonname
Thus a button can be created as follows;
<$button actions=<<button-actions "MyButton">> >
MyButton
</$button>
and then clicking “MyButton” will trigger the actions in all tiddlers tagged $:/tags/button-actions/MyButton
Thus without returning to a buttons invocation and editing it in future additional actions can be added to every button that contains actions=<<button-actions "MyButton">>
simply by placing additional actions in a tiddler and tagging it $:/tags/button-actions/MyButton, with the added feature that they may be actioned in the order of the tagged items.
As this solution is now;
- This will encourage users to follow a de facto standard when developing buttons in their solutions, allowing other solutions or plugins to add actions where necessary or convivence and integration without the need to edit each others buttons.
- We may suggest by example that such “action tiddlers” be named with the button-actions or similar in its name.
- Most existing buttons respond only to click, using this method actions responding to the modifier keys “on click” can be added by user/designers without core changes.
What is next?
-
Update the majority of core buttons. With the above macro in place I propose changing most core buttons
[all[shadows]prefix[$:/core/ui/Buttons/]]
not already using the “actions=” parameter withactions=<<button-actions "buttonname">>
where button name is the name following “$:/core/ui/Buttons/” eg; $:/core/ui/Buttons/save-wiki getsactions=<<button-actions "save-wiki">>
- This includes buttons for the view and edit toolbars and the page controls (toolbar)
- If the above macro or a version of it is accepted I would hopefully proceed with updating most core button widgets before the next release.
The exceptions to above can be found with [all[shadows]prefix[$:/core/ui/Buttons/]search[actions=]]
and each of these handled separately, ideally to bring them inline with the same approach.
- $:/core/ui/Buttons/cancel
- $:/core/ui/Buttons/delete
- $:/core/ui/Buttons/new-image
- $:/core/ui/Buttons/new-journal
- $:/core/ui/Buttons/new-tiddler
- $:/core/ui/Buttons/new-here
An outstanding question?
- Please Consider; Lets say you wished to have an action occur when a user clicks any button. You would create a single action tiddler and tag it with all the various
$:/tags/button-actions/*buttonname*
or alternatively add the action to multiple tiddlers with the appropriate tags. - This could be used to log the button usage of your wiki for analytics or designer/user feedback.
The Question;
- Would it be acceptable to include in the solution an additional “virtual tag” such as
$:/tags/button-actions/all
where tiddlers so tagged will contain actions to be executed for all buttons? This is mainly due to the possible performance impact, but would it be less if used with a single tag anyway if someone chose to go with it anyway?
Extending this concept later;
- A similar treatment of these on Editor Toolbar buttons, would be useful but requires additional research.
- Providing a matching solution for other actions not on existing core buttons, and in other widgets such as the selectwidget ETC… in this case we may add tags of the form $:/tags/actions/actionname
- A method to do the same on open or navigate to a tiddler would also be highly desirable, for example; opening select tiddlers, could start a timer, but also requires additional research.