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 and 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. On the left side you should find the class name of the class where you defined the method with the pragma. After you select the class, you will see the names of the actions you defined in the triples/quintuples. You can now right click on these items and select Add keyboard shortcut. After that a Dialog will open in which, after hovering over it, you can press a key combination that will appear. This is the shortcut that will be assigned after you press ok.

It is possible to assign multiple shortcuts to an action. To delete them, right click 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]

To reset all actions of a class to the default shortcut press the reset all button of the shortcut Browser. If an action has no assigned shortcut, the reset all button will delete all assigned shortcuts.

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