[Pharo-users] How to add a keyboard shortcut to Rubric?

Aliaksei Syrel alex.syrel at gmail.com
Wed Oct 28 18:56:40 EDT 2015


You can use the power of Inspector! Inspect rubric morph and you will see
there is shortcuts tab which lists all assigned shortcuts and if you click
on one them a new tab will be opened to the right showing exact place in
source code when shortcut is defined and its action.
On Oct 28, 2015 11:05 PM, "Johan Fabry" <jfabry at dcc.uchile.cl> wrote:

> Hi Nicolai,
>
> thanks for your answer! However, apparently the problem is a bit
> different: the shortcut I wanted to add, cmd-s, already existed but I did
> not realize it! I want to add cmd-s to save the text to a file, but the
> editor has auto accept set to true and cmd-s calls accept by default. So
> adding another cmd-s did not do anything and neither could I see that the
> existing cmd-s binding was executing some other behavior :-/
>
> After seeing this, I expected that I would be able to remove the cmd-s
> keybinding, using removeKeyCombination: but apparently I cannot (see
> example below).
>
> In general, it’s not nice to discover from the code that there are
> keyboard shortcuts that are not listed in the context menu. The enduser
> should be able to discover all active keybindings from what is visible in
> the UI and this is not the case here. Maybe I’ll make a subclass of
> RubTextEditor that only reimplements buildShortcutsOn: so that it is
> without all these hidden keybindings.
>
> But for now I’ll add cmd-d to do save … although that’s ugly. :-(
>
>     |  window text |
>     text := RubScrolledTextMorph new.
>
>     "define a custom shortcut"
>     text removeKeyCombination: $s command.
>     text on:$s command do:[
>         text setText: text text asString reverse].
>
>     window := StandardWindow new.
>     window addMorph: text fullFrame: (0 at 0 corner: 1 at 1) asLayoutFrame.
>     window title: 'Example'.
>     window openInWorld.
>
>
> On Oct 28, 2015, at 17:58, Nicolai Hess <nicolaihess at gmail.com> wrote:
>
>
>
> 2015-10-28 19:59 GMT+01:00 Johan Fabry <jfabry at dcc.uchile.cl>:
>
>> Hi all,
>>
>> I am trying to add a keyboard shortcut to a RubTextEditor. I have tried
>> different ways but nothing seems to work. I have even tried modifying
>> buildShortcutsOn: at class side to include the extra shortcut but it does
>> not have any effect at all.
>>
>> Ideally I’d take an existing instance and add the keyboard shortcut
>> there, but if that is impossible I’m willing to make a subclass just to get
>> this extra shortcut. Can anybody give me pointers?
>>
>> ---> Save our in-boxes! http://emailcharter.org <---
>>
>> Johan Fabry   -   http://pleiad.cl/~jfabry
>> PLEIAD and RyCh labs  -  Computer Science Department (DCC)  -  University
>> of Chile
>>
>>
>>
> Hi Johan,
> adding a custom shortcut for a Rubric-TextMorph is easy:
>
>
>     |  window text |
>     text := RubWorkspaceExample new newScrolledText.
>
>     "define a custom shortcut"
>     text on:$t command do:[
>         text setText: text text asString reverse].
>
>     window := StandardWindow new.
>     window addMorph: text fullFrame: (0 at 0 corner: 1 at 1) asLayoutFrame.
>     window title: 'Example'.
>     window openInWorld.
>
>
> This simple example will build a Rubric Scrolled Textmorph and add a
> alt+t shortcut to reverse the current text
>
> What ways did you already tried?
>
> Modifying the existing #buildShortcuts method should work, for existing
> RubTextEditor (or subclasses).
> But if you define your own RubTextEditor you may need to define another
> shortcut category and register your editor with that
> category on the Morph you use.
>
> For example, RubAbstractTextArea (a Morph) calls
>
> super initializeShortcuts: aKMDispatcher.
> self editor initializeShortcuts: aKMDispatcher
>
> and teh editors #initializeShortcuts
> will attach the editors category, defined in the editors class side
> buildShortCutsOn method.
>
>
>
>
>
>
>
>
> ---> Save our in-boxes! http://emailcharter.org <---
>
> Johan Fabry   -   http://pleiad.cl/~jfabry
> PLEIAD and RyCh labs  -  Computer Science Department (DCC)  -  University
> of Chile
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20151028/451ba82c/attachment.html>


More information about the Pharo-users mailing list