diff --git a/core/ui/EditTemplate/body-toolbar-button.tid b/core/ui/EditTemplate/body-toolbar-button.tid index 956bfd634..7390b3e20 100644 --- a/core/ui/EditTemplate/body-toolbar-button.tid +++ b/core/ui/EditTemplate/body-toolbar-button.tid @@ -35,22 +35,23 @@ title: $:/core/ui/EditTemplate/body/toolbar/button filter="[all[current]!has[dropdown]]" variable="no-dropdown" -><$button +><$set name=disabled filter={{!!condition-disabled}}><$button class="tc-btn-invisible $(buttonClasses)$" tooltip=<> actions={{!!actions}} + disabled=<> >match[yes]then[]else{!!shortcuts}] }}} /><><$transclude tiddler=<> field="text" -/><$list +/><$list filter="[all[current]has[dropdown]]" variable="dropdown" @@ -60,24 +61,25 @@ title: $:/core/ui/EditTemplate/body/toolbar/button name="dropdown-state" value=<> -><$button +><$set name=disabled filter={{!!condition-disabled}}><$button popup=<> class="tc-popup-keep tc-btn-invisible $(buttonClasses)$" selectedClass="tc-selected" tooltip=<> actions={{!!actions}} + disabled=<> >match[yes]then[]else{!!shortcuts}] }}} /><><$transclude tiddler=<> field="text" -/><$reveal +/><$reveal state=<> type="popup" diff --git a/editions/tw5.com/tiddlers/howtos/How to create dynamic editor toolbar buttons.tid b/editions/tw5.com/tiddlers/howtos/How to create dynamic editor toolbar buttons.tid new file mode 100644 index 000000000..27ed11d03 --- /dev/null +++ b/editions/tw5.com/tiddlers/howtos/How to create dynamic editor toolbar buttons.tid @@ -0,0 +1,126 @@ +created: 20201216182347597 +modified: 20201217193318816 +tags: +title: How to create dynamic editor toolbar buttons +type: text/vnd.tiddlywiki + +\define disabledFilterExample()`[[$(tempBoldDisabled)$]get[state-disabled]else[no]]` + +\define remove-shortcuts() +<$action-deletetiddler $tiddler=<>/> +<$action-deletetiddler $tiddler=<>/> +<$action-deletetiddler $tiddler=<>/> +<$action-deletetiddler $tiddler=<>/> +<$action-deletetiddler $tiddler=<>/> +\end + +\define create-shortcut-tiddlers() +<$action-createtiddler $basetitle=<> + $template="$:/config/ShortcutInfo/bold" + $overwrite="yes" +/> +<$action-navigate $to=<>/> + +<$action-createtiddler $basetitle=<> + $template="$:/config/shortcuts-mac/bold" + $overwrite="yes" + text="meta-shift-X" +/> +<$action-navigate $to=<>/> + +<$action-createtiddler $basetitle=<> + $template="$:/config/shortcuts-not-mac/bold" + $overwrite="yes" + text="ctrl-shift-X" +/> +<$action-navigate $to=<>/> + +\end + +\define clone-bold() +<$action-createtiddler $basetitle=<> + $template="$:/core/ui/EditorToolbar/bold" + $overwrite="yes" + icon="$:/core/images/spiral" + shortcuts="((temp-bold))" + condition-disabled="[[$(tempBoldDisabled)$]get[state-disabled]else[no]]" +/> +<$action-sendmessage $message="tm-edit-tiddler" $param=<>/> +\end + +\define clone-button-bold() +<$button actions=<> >Create a Temporary Bold Button +\end + +\define toggle-bold() +<$action-listops $tiddler=<> $field="state-disabled" $subfilter="+[toggle[yes],[no]]" /> +\end + + +<$vars tempBold="$:/temp/bold" tempBoldDisabled="$:/temp/bold/disabled" shortcutInfo="$:/config/ShortcutInfo/temp-bold" shortcutConfigMac="$:/config/shortcuts-mac/temp-bold" shortcutConfigNotMac="$:/config/shortcuts-not-mac/temp-bold"> + +!! Create a New Toolbar Button + +The easiest way to create new editor toolbar button is to clone and open one. + +><> + +This tiddler contains all the necessary elements that are important for toolbar buttons. + +<<< + +; text +: We don't discuss the text field details in this howto + +; caption +: The caption field is used to display the shortcut name in the $:/ControlPanel : Keyboard Shortcuts tab + +; condition +: A filter, that defines the button visibility state + +; condition-disabled <<.from-version "5.1.23">> +: A ''filter'', that allows us to define the "disabled" attribute for buttons. eg: <> +: This condition ''must'' return "no", if the "state tiddler" or "state field" doesn't exist! So there has to be a `else[no]` element in the filter. + +; description +: Is used as the button tooltip + +; icon +: Assigns the button icon. We use `$:/core/images/spiral` {{$:/core/images/spiral}} here. + +; shortcuts +: This is the [[Keyboard Shortcut Descriptor]] eg: `((temp-bold))` + +<<< + +!! Disabled State + +You can use any "state tiddler" to define the button disabled state. It's important, that the ''condition-disabled'' field is a ''filter''. For our example we use the `state-disabled` field from tiddler: <> + +The easiest way to test filters is with the $:/AdvancedSearch : Filter tab + +> The temporary "bold button" is disabled: ''"{{{ [get[state-disabled]else[no]] }}}"'' ... You can see the button in the editor toolbar if you edit any tiddler! + +> <$button actions=<>>Toggle Temporary Bold Button Visisbility + +!! Create Keyboard Shortcuts for New Button + +For our ~HowTo we use the ''Keyboard Shortcut Descriptor'': `((temp-bold))` + +To create a valid shortcut configuration we need 2 tiddlers: + +>[[$:/config/ShortcutInfo/|$:/config/ShortcutInfo/temp-bold]]''temp-bold'' .. and +>[[$:/config/shortcuts/|$:/config/shortcuts/temp-bold]]''temp-bold'' + +> <$button actions=<>>Create Shortcut Tiddlers + +!! + +!! Clean up the Configuration Tiddlers + +If you don't need the config tiddlers anymore you can + +><$button actions=<>>Remove the Shortcut Configuration + + + diff --git a/themes/tiddlywiki/vanilla/base.tid b/themes/tiddlywiki/vanilla/base.tid index b34917222..5fbde4325 100644 --- a/themes/tiddlywiki/vanilla/base.tid +++ b/themes/tiddlywiki/vanilla/base.tid @@ -87,6 +87,10 @@ html button { border-color: <>; } +button:disabled svg { + fill: <>; +} + /* ** Basic element styles */ @@ -1605,6 +1609,10 @@ html body.tc-body.tc-single-tiddler-window { fill: <>; } +.tc-drop-down button:disabled svg { + fill: <>; +} + .tc-drop-down button.tc-btn-invisible:hover svg { fill: <>; }