Is there any reason we don’t have a widget, say called $action, that allows us to trigger any number of action-widgets, similar to pushing a button but without the button push itself?
Would be really useful, I would have thought.
Bobj
Is there any reason we don’t have a widget, say called $action, that allows us to trigger any number of action-widgets, similar to pushing a button but without the button push itself?
Would be really useful, I would have thought.
Bobj
“Hey, try this new cool theme I created. You can download it from http://imnotabadguy-reallyimnot.com/tw/beautiful-theme.json. Just download it, drag it onto your wiki and see these beautiful new stylings! Go on, do it now before you forget. It’s 100% safe, guaranteed. Really, don’t worry about it. And it’s entirely free!”
Ok, downloaded, dragging it to my wiki. This is going to be great!
Um, why is it making all these requests to http://malicioussite.com? Is that a password it just posted there?
And why is it changing the text of half my tiddlers, and deleting the other half?
Now what’s it doing? Saving to my desktop, overlaying my backup copy?
That’s why. We don’t want browser actions like download-and-overlay-file to be automatic. The browser doesn’t do that automatically, but only on a user request, with a second confirmation if there’s an overlay.
Similarly, you don’t want some random wikitext to delete your tiddler, or alter its fields, without your say-so. So any action that’s going to change your content (as opposed, say, to just rendering) needs an explicit trigger, one that demonstrates intent, like a button push, and not just a hover.
@Scott_I can see your argument but counter that those actions could happen anyway with a button there, all I have to do is to convince you to press it. And from what you hear today, getting a single push of a button is not too hard to achieve.
It’s a cost-benefit thing surely and the relying on the coder to ‘do the right thing’ which is the status quo.
Bobj
pmario made an experimental trigger widget. I have altered his widget to add features I needed for a game project I am working on. So it would normally be used like this:
<$trigger actions=<<your-actions>>/>
But I altered it to allow for a wait time in seconds as well as a random wait time with start and end, so it could be used like this:
<$trigger wait=10 actions=<<your-actions>>/>
Which will trigger the actions 10 seconds after the Tiddler is opened.
<$trigger start=20 end=60 actions=<<your actions>>/>
This would pick a random delay between 20 and 60 seconds before triggering the actions.
I have also created an altered version that runs as an action widget itself, called action-trigger, and it does the same thing, but is used as an action widget, so it does not run immediately, but is only triggered from another widget as an action. It it is used the same way:
<$action-trigger actions=<<my-actions>>/>
<$action-trigger wait=10 actions=<<my-actions>>/>
<$action-trigger start=20 end=60 actions=<<my-actions>>/>
I have also added a global option to both of these. If you set the global option, then only one trigger or action-trigger with the same matching global name will run. If you start another action with the same global name assigned, it will be skipped as there is already a “timer” waiting on the global name. It would be used like this:
<$trigger wait=30 global="mygroup" actions=<<my-actions>>/>
or
<$action-trigger wait=30 global="mygroup" actions=<<my-actions>>/>
Now, if you start another action widget, from either the trigger widget or the action-trigger widget with the same global name “mygroup” it will be skipped as long as the groups previous actions have not triggered yet.
Like Scott said, as well as a warning by pmario, you must use this carefully as it could screw things up if you don’t do it right.
Trigger Widget.json (6.4 KB)
Action Trigger Widget.json (7.1 KB)
I did create the trigger widget Wikilabs Home — A home for: Plugins, Editions and Themes!, which activates actions whenever it is rendered. The main problem is that if configured in the wrong way it can create endless loops which can brick your wiki. Eg: trigger is in tiddlerA which opens tiddlerB which triggers a redraw in tiddlerA →
I have visited this a number of times both in the early days of comming to terms with tiddlywiki then later as my skills develop. There are work arounds like mentioned above but also warnings. The Following may conceptualise why we do not have such actions - out of the box.
Appart from start actions, tiddlywiki loads and renders and presents its content. It needs to do this ASAP then stops doing anything and sits and waits for user interactions. Each interaction tiddlywiki will head off and do what it needs as quickly as possible, update all or part of what you see and sits and waits for your interaction again.
In some ways as a tiddlywiki designer you need to maintain a solution that supports this underlying structure. Although timers and other ways to trigger actions exist, it is best you clearly define what a trigger is, and what it does when triggered. The most common trigger is a button or link.
The Approach
Define your triggers with the above in mind. At the top of this topic you seem to be saying to action on display, ie the trigger is the render, rather than asking for a button click. But what if tiddlywiki re-renders for a change elsewhere?, you come back from another tab, reopening the tiddler, reloading the wiki, and how often do you want to trigger the “on display” action if the wiki is open for hours?
The solution
The most strait forward solution I have found is to piggyback on existing triggers such as on navigate, clicking a link or click an existing button. Of course this can also be conditional, use the trigger, but only action if certian conditions are true.
More details available if requested.
I would like to thank everyone for their comments. I take on board all your suggestions.
@TW_Tones, I have been looking at a specific case where I am using the Geospatial widget and have suddenly realised that it needs a ‘centre’ button, so the user can, after moving the map recentre themselves on the location it should be (that of a gun in some location). So your thoughts as to thinking about a button are the driver behind my solution.
Having said all that, I still think it would be useful in the situation where I want to set the field of a tiddler to some value. I know I can use a variable, global or otherwise, but as I am also thinking about persistence, the field of, say a system tiddler, would be very useful as this would survive the download to the user’s computer.
bobj
Absolutely. There’s no guaranteed protection.
But I feel much safer knowing that I can load things onto my wiki and click around without worrying about corrupting my wiki, unless I do things like hitting buttons. (Keystrokes, reload, also can trigger actions.)
How can keystrokes and reload trigger actions? Not heard of that before.
Bobj
Is background actions mentioned in this pull request by @jeremyruston something similar to what is being discussed in this thread
Keystrokes = Keyboard Shortcuts
Reload = Startup actions
I dont have the experience with the geospatial plugin (I used an earlier one) but for what you are doing it would be nice to click or ctrl-click to recentre or alt-click to centre a map (in the map window only) which I suspect may exist within tiddlyMap. The click is a trigger and can be used to trigger actions.