Skip to content

How to use

Franka-T edited this page Aug 4, 2022 · 17 revisions

How to apply actions

On the class you want to use as the one that should receive the shortcuts (e.g. a morph or a model) define on class side a method and define the wantsActions pragma in it.

For example:

actions

	<wantsActions>

	^{   
		{'Remove' . #removeItem . 'Removes the currently selected item'}.
		{'Add line' . #addSeparator . 'Adds a seperator/line'}.
	}collect: [:each | AAction createActions: each]

If your recompile the method later on after changing something the changes will get applied automatically. So if you for example change the description or the symbol block you can observe the changes directly (e.g. by triggering the assigned shortcut). Only if you change the name of an Action, you need to reset the actions or change the shortcut to see the change.

How to define global actions

Global actions are define by a triple or a quintuple in the AGlobalActions class. The triple/quintuple is structured in the same way as for normal actions.

globalActions

	^{   
		{'Move up' . #moveUp . 'Moves the currently selected items above the items over it' . $p . #cmdPressed }.
		{'Move Down' . #moveDown . 'Moves the currently selected items under the items under it' }.
	}collect: [:each | AGlobalAction createActions: each]
	

Next we define a class side method in the class, where we want to use the global actions. In the method we define the wantsActions pragma an list all actions from the globalActions method of the AGlobalActions class which we want to use in the chosen class.

globalActions

	<wantsActions>

	^{   
		{'Move up' . #moveUp}.
	}collect: [:each | AGlobalAction from: each in: self]

How to define shortcuts

After defining the method you can open the Shortcut Browser by executing AShortcutBrowser open. There you should find the class name you defined the method with the pragma in it on the left side and after you select it you see the names you defined in the triples/quintuples. You can now right click on this items and select Add keyboard shortcut. After doing so there opens a Dialog where after hovering over you can press a key combination which will get displayed. This is the shortcut that will get assigned after you press ok.

It is possible to give one action multiple shortcuts. To delete them right click on the item again and you can now select Remove <your shortcut combination> to remove the shortcut.

How to define default shortcut

To define a default shortcut extend the triple of the actions method to a quintuple an add the key combination at the new free spaces.

actions

	<wantsActions>

	^{   
		{'Add line' . #addSeparator . 'Adds a seperator/line'. $a . #cmdPressed}.
		{'Remove' . #removeItem . 'Removes the currently selected item'. $r . #cmdPressed}.
	}collect: [:each | AAction createActions: each]

How to make shortcuts triggerable

To be able to trigger the shortcuts you have to write AActions shortcutFor: self event: evt in a method where keyboard events get processed. For example this could be keyStroke: or filterEvent:for:

For example:

keyPress: key tree: aTreeMorph event: evt

	AActions shortcutFor: self event: evt
Clone this wiki locally