Ticket #610 (closed enhancement: fixed)

Opened 4 years ago

Last modified 19 months ago

enhance toolbar macro syntax to render tiddler/slice/section content inline

Reported by: EricShulman Owned by: MartinBudden
Priority: minor Milestone: 2.6.1
Component: core Version:
Severity: low Keywords:
Cc:

Description

Extend the <<toolbar>> macro to recognize references to tiddlernames, slices, or sections and render their content inline within the toolbar. This allows macros, options, or static text to be easily incorporated into a toolbar display.

See  http://www.TiddlyTools.com/#ToolbarCommands for examples

config.macros.toolbar.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
...
	if(c in config.commands)
		this.createCommand(place,c,tiddler,theClass);
	else { // WIKIFY TIDDLER/SLICE/SECTION
		if (c.substr(0,1)=="~") c=c.substr(1); // ignore leading ~
		var txt=store.getTiddlerText(c);
		if (txt) {
			// trim any leading/trailing newlines
			txt=txt.replace(/^\n*/,"").replace(/\n*$/,"");
			// trim PRE format wrapper if any
			txt=txt.replace(/^{{{\n/,"").replace(/\n}}}$/,""); 
			wikify(txt,createTiddlyElement(place,"span"));
		}
	} 
	break;
...

Change History

  Changed 4 years ago by MartinBudden

  • milestone set to 2.5

  Changed 3 years ago by MartinBudden

  • owner changed from JeremyRuston to EricShulman

follow-up: ↓ 5   Changed 3 years ago by FND

  • milestone changed from 2.5.1 to 2.5.2

While certainly very useful in some cases, I'm not sure whether this is suitable for inclusion in the core.

in reply to: ↑ 4   Changed 3 years ago by EricShulman

Replying to FND:

While certainly very useful in some cases, I'm not sure whether this is suitable for inclusion in the core.

I think that this *should* definitely go into the core for the following reasons: A) people are asking for this ability (in some form or another) B) it extends a no-op to do something useful C) it enables toolbar customization without any coding D) it doesn't change *existing* toolbar syntax in any way E) it replaces a somewhat bulky CoreTweak? with a small block of robust core code F) it eliminates a dependency on a plugin

Here's why:

The proposed functionality provides a highly-effective solution for supporting numerous uses-cases where custom toolbar commands are desired. I have been asked many times over the years if there is a way to embed either macro-based command links (such as <<newTiddler>>, <<closeAll>>, <<saveChanges>, etc.), or just plain TiddlyLinks? (e.g., Help, About, etc.) directly into the tiddler toolbar.

Unfortunately, there is currently **no way at all** for people to do this without requiring significant programming skills to write a custom toolbar command plugin that emulates the macro's handler() function (so it can perform the same underlying processing without using the macro's regular parameter syntax).

Of course, most people would have a great deal of trouble even understanding *how* to write such plugin code and get it to work properly, even if they thoroughly understand how to use the desired macro syntax in normal tiddler content.

Fortunately, the toolbar handling currently does *nothing* when it encounters an unrecognized toolbar command keyword (i.e., a keyword that doesn't have a matching config.commands.keyword.handler() function). As such, this provides an opportunity to add some handling to this "no-op' use case, so it can attempt to use the unrecognized command as a tiddler reference and then retrieve/render content from that tiddler (if it exists, of course).

With this simple extension to the toolbar syntax, it makes it possible to put a wide variety of non-toolbar commands (i.e., macros, TiddlyLinks?, inline 'onclick' scripts, pure HTML links, etc.) directly into the toolbar by making one or more separate tiddlers (or tiddler sections) containing the desired commands and then simply put the references to those tiddlers into the space-separate toolbar slice definitions in ToolbarCommands?.

For example:

[[ToolbarCommands]]:
|~ViewToolbar|ToolbarCommandsExtras closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|

[[ToolbarCommandsExtras]]:
[[help|HelpTiddler]] <<newJournal ...>> <<closeAll>> <<saveChanges>>

note: if you wanted to avoid having extra tiddlers around, you could also use a 'hidden section' directly in ToolbarCommands?, like this:

[[ToolbarCommands]]:
|~ViewToolbar|ToolbarCommands##extras closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|
/%
!extras
[[help|HelpTiddler]] <<newJournal ...>> <<closeAll>> <<saveChanges>>
!end
%/

Please note: when this proposal was discussed in the last Developer's Conference Call, it was left open for further consideration while also noting that, if it is ultimately decided to *not* add this change into the core code, then we really need to refactor config.macros.toolbar.handler() so that a plugin-based solution doesn't have to completely re-write and replace the entire function.

However, it is my position that a plugin-based solution is not the best choice because it still requires refactoring the core code in order to provide the 'hook' for the add-on code and also forces a dependency on add-on code that can make portability of enhanced toolbar definitions to other documents problematic.

  Changed 3 years ago by FND

  • milestone changed from 2.5.3 to 2.5.4

  Changed 2 years ago by MartinBudden

  • owner changed from EricShulman to MartinBudden

Interim solution - create overridable function in else clause above.

  Changed 2 years ago by FND

  • milestone changed from 2.6 to 2.6.1

  Changed 19 months ago by MartinBudden

  • status changed from new to closed
  • resolution set to fixed

Fixed in changeset:12296

Note: See TracTickets for help on using tickets.