Skip to content

How to use

Tom Braun edited this page Sep 30, 2020 · 17 revisions

How to expose 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 that takes one parameter and define the wantsActions pragma in it. The parameter exposes the methods:

  • save: for saving a single Action
  • saveActionsFrom: for converting a collection of collections with 3 elements to Actions and save them. The 3 elements are: {<aSymbol that represents the name of the action>, <a Symbol that gets performed on the object | a BlockClosure with zero parameters | a BlockClosure with one parameter. The parameter is the Object.>, <a string that is a short description of the action>}.
  • saveActionsWithDefaultShortcutsFrom: like saveActionsFrom: but can not only contain collections but also Associations with a AShortcut as the key and a collection with 3 elements as value. AShortcut can be created with onlyKey: (only press the key to trigger it), modifier: (press, depending on your platform, command or control + a key), modifierShift: (press, depending on your platform, command or control + shift + a key)

For example:

actions: aActions

	<wantsActions> 
	AActions saveActionsWithDefaultShortcutsFrom:  {  
		(AShortcut modifier: $c) -> {#changeColor . #changeColor . 'Triggers a change in color' }.
		{#changeExtent . [:me | me extent: (200 atRandom max: 20)@(200 atRandom max: 20)] . 'A stub action'}.
		{#openBrowser . [Browser open] . 'Opens a browser because why not'}
	}

The From method requires a triple: a name, an action to be executed using a shortcut, and a description of what the action does. The action can either be a symbol, a block without any parameter or a block with one parameter. In the first case the symbol will get performed on the receiving object (e.g. the morph) and in the last case the parameter for executing the block will be the object too.

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. 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 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:

keyStroke: evt

	AActions shortcutFor: self event: evt
Clone this wiki locally