diff --git a/editions/tw5.com/tiddlers/howtos/How to create keyboard shortcuts.tid b/editions/tw5.com/tiddlers/howtos/How to create keyboard shortcuts.tid new file mode 100644 index 000000000..ea36b9e18 --- /dev/null +++ b/editions/tw5.com/tiddlers/howtos/How to create keyboard shortcuts.tid @@ -0,0 +1,90 @@ +tags: [[Customise TiddlyWiki]] Learning +title: How to create keyboard shortcuts +type: text/vnd.tiddlywiki + +<<.tip """We distinguish keyboard shortcuts that work within <$macrocall $name=".tag" _="input"/> fields or <$macrocall $name=".tag" _="textareas"/> which are handled by the <$macrocall $name=".wlink" to="KeyboardWidget"/> widget and keyboard shortcuts that work globally - which means that only the page needs to have focus in order for them to be accessible - handled by a mechanism that starts to work when a wiki is loaded""">> + +!!!!There's an underlying configuration mechanism that is the same for both shortcut-types: + +<$vars tv-show-missing-links="no"> + +* (`A`) - A tiddler with the <<.def prefix>> ''$:/config/ShortcutInfo/'' + a ''unique suffix'', like `my-shortcut` makes the new shortcut appear in the $:/ControlPanel within the [[Keyboard Shortcuts Tab|$:/core/ui/ControlPanel/KeyboardShortcuts]]. An optional description can be added within its text field +** In the [[Keyboard Shortcuts Tab|$:/core/ui/ControlPanel/KeyboardShortcuts]] it's possible to create the ''key combination'' that should trigger the shortcut +*** Look for the ''unique suffix'' (A) and click the <$button class="tc-btn-invisible">{{$:/core/images/edit-button}}<$action-sendmessage $message="tm-notify" $param="$:/core/images/edit-button"/> button to open a popup that detects ''key combinations'' and shows the detected combination in its input field +*** Press ''add shortcut'' if you're happy with the assigned key-combination +**** (`B`) Depending on the platform you choose the configuration mechanism creates a tiddler with a specific nomenclature: +***** $:/config/shortcuts/ + the ''unique suffix'' for shortcuts that will work on all platforms (operating systems) +***** $:/config/shortcuts-(mac/not-mac/windows/not-windows/linux/not-linux)/ + the ''unique suffix'' for shortcuts that will work on the chosen platform only or that will not work on the excluded platform +***** <$reveal state="$:/state/how-to/kb-shortcuts/platform-examples" type="nomatch" text="show"><$button class="tc-btn-invisible" set="$:/state/how-to/kb-shortcuts/platform-examples" setTo="show">Show examples<$reveal state="$:/state/how-to/kb-shortcuts/platform-examples" type="match" text="show"><$button class="tc-btn-invisible" set="$:/state/how-to/kb-shortcuts/platform-examples" setTo="hide">Hide examples
<$reveal state="$:/state/how-to/kb-shortcuts/platform-examples" type="match" text="show" animate="yes" retain="yes">''$:/config/shortcuts/''`my-shortcut`
''$:/config/shortcuts-mac/''`my-shortcut`
''$:/config/shortcuts-windows/''`my-shortcut`
''$:/config/shortcuts-linux/''`my-shortcut`
''$:/config/shortcuts-not-mac/''`my-shortcut`
''$:/config/shortcuts-not-windows/''`my-shortcut`
''$:/config/shortcuts-not-linux/''`my-shortcut`
+***** Note that you don't have to create those platform-specific tiddlers manually if you simply create the ''ShortcutInfo'' tiddler (`A`) and configure the shortcut in the ~ControlPanel + +!!!!At this point the shortcut is defined but it doesn't trigger any action + +<$reveal type="nomatch" text="show" state="$:/state/how-to/kb-shortcuts/keyboard-widget"> +<$button class="tc-btn-invisible" set="$:/state/how-to/kb-shortcuts/keyboard-widget" setTo="show">''Show'' "How to create the shortcut-actions for <<.tag input>> and <<.tag textarea>> fields" + +<$reveal type="match" text="show" state="$:/state/how-to/kb-shortcuts/keyboard-widget"> +<$button class="tc-btn-invisible" set="$:/state/how-to/kb-shortcuts/keyboard-widget" setTo="hide">''Hide'' "How to create the shortcut-actions for <<.tag input>> and <<.tag textarea>> fields" + +
+<$reveal type="match" text="show" animate="yes" retain="yes" state="$:/state/how-to/kb-shortcuts/keyboard-widget"> + +> A <<.wlink "KeyboardWidget">> widget detects the key combinations pressed in an <<.tag input>> or <<.tag textarea>> field within its scope. The <<.wlink "KeyboardWidget">> widget needs to ''surround'' the <<.tag input>> or <<.tag textarea>> field: + +``` +<$keyboard key="((my-shortcut))" actions="<$action-do-something/>"> + +<$edit-text tag="input" tiddler="my-tiddler"/> + + +``` +
+ +> The `((my-shortcut))` syntax with the `((` and `))` embracing the ''unique suffix'' defined in (`A`) makes the <<.wlink "KeyboardWidget">> widget look up for all existing configuration tiddlers (`B`) and assigns the correct key-combination for your platform/operating system to the actions defined with the <<.attr actions>> attribute + +> At this point, the <<.wlink KeyboardWidget>> widget will invoke the actions defined in its <<.attr actions>> attribute when it detects the key-combination defined for `my-shortcut` in any <<.tag input>> or <<.tag textarea>> field within its scope + + + +<$reveal type="nomatch" text="show" state="$:/state/how-to/kb-shortcuts/global-actions"> +<$button class="tc-btn-invisible" set="$:/state/how-to/kb-shortcuts/global-actions" setTo="show">''Show'' "How to create the shortcut-actions for `global` keyboard shortcuts" + +<$reveal type="match" text="show" state="$:/state/how-to/kb-shortcuts/global-actions"> +<$button class="tc-btn-invisible" set="$:/state/how-to/kb-shortcuts/global-actions" setTo="hide">''Hide'' "How to create the shortcut-actions for `global` keyboard shortcuts" + +
+<$reveal type="match" text="show" animate="yes" retain="yes" state="$:/state/how-to/kb-shortcuts/global-actions"> + +> The actions for ''global'' keyboard shortcuts are stored in the ''text'' field of tiddlers tagged with <> + + +> The ''key field'' connects this action-tiddler with the corresponding shortcut through the `((my-shortcut))` syntax, called [[Keyboard Shortcut Descriptor]] + +:

Syntax: `((` + ''unique suffix'' (`A`) + `))`

+ +> If the tiddler has the tag <>, the field ''key'' with the [[Keyboard Shortcut Descriptor]] as its value and some actions in its text field, the actions will be triggered when the mechanism detects the configured key-combination + +<$macrocall $name=".tip" _="""''Macros'' defined ''outside'' our keyboard-shortcut tiddlers (through a tiddler tagged <>) don't work out-of-the-box when triggered with a global keyboard shortcut, but there's a simple workaround using the [[import pragma|Pragma]], adding the following line ''on top'' of your keyboard-shortcut tiddler containing the macro: + +
+\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
+
+ +or even simpler, if the tiddler containing the macro is known and - for example - titled `my-macro-tiddler`: + +
+\import [[my-macro-tiddler]]
+
+ +"""/> + +<$macrocall $name=".tip" _="""Some actions require that we add a <<.wlink NavigatorWidget>> widget at the top of our action tiddler. That is necessary for following list of widgets and messages in order ''to work with global keyboard shortcuts'':"""/> + +* __Widgets__ +** <<.wlink ActionNavigateWidget>> (ActionNavigateWidget) +* __Messages__
    <$list filter="[tag[navigator-message]]"> +
  • <$link to={{!!title}}><$view field="title"/>
+ + + + diff --git a/editions/tw5.com/tiddlers/howtos/KeyboardShortcuts.tid b/editions/tw5.com/tiddlers/howtos/KeyboardShortcuts.tid index ea07c63d9..432e38226 100644 --- a/editions/tw5.com/tiddlers/howtos/KeyboardShortcuts.tid +++ b/editions/tw5.com/tiddlers/howtos/KeyboardShortcuts.tid @@ -10,20 +10,23 @@ Keyboard shortcuts can either be used with the <<.wlink KeyboardWidget>> Widget A shortcut defined through a [[Keyboard Shortcut Tiddler]] makes the shortcut accessible globally""">> +!!!See [[How to create keyboard shortcuts]] with a detailed explanation for creating your own shortcuts + Keyboard shortcuts are available for common editing operations within the Text Editor: * Confirming changes to the draft tiddler containing the keyboard focus (defaults to ctrl-Enter) * Abandoning changes to the draft tiddler containing the keyboard focus (defaults to escape) * Formatting operations from the tiddler editing toolbar (see the tooltips) -<<.from-version 5.1.18>>: New ''global'' Keyboard shortcuts: +<<.from-version 5.1.18>> : New ''global'' Keyboard shortcuts: -* Creating a new tiddler (defaults to alt-N) -* Creating a new journal (defaults to alt-J) +* Creating a new tiddler (defaults to alt-N ) +* Creating a new journal (defaults to alt-J ) +* Creating a new image (defaults to alt-I ) The current shortcuts can be inspected and customised in the "Keyboard Shortcuts" tab of the [[Control Panel|$:/ControlPanel]] {{$:/core/images/options-button}}. !! Special Keys ; adding tags in the editor -: <<.from-version 5.1.14>>: if you hit Enter in the new tag input, the tag will be added +: <<.from-version 5.1.14>> : if you hit Enter in the new tag input, the tag will be added