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 |
2015-10-28 19:59 GMT+01:00 Johan Fabry <[hidden email]>: Hi all, 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@0 corner: 1@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. |
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@0 corner: 1@1) asLayoutFrame. window title: 'Example'. window openInWorld.
---> Save our in-boxes! http://emailcharter.org <---
Johan Fabry - http://pleiad.cl/~jfabry PLEIAD and RyCh labs - Computer Science Department (DCC) - University of Chile |
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" <[hidden email]> wrote:
|
2015-10-28 23:56 GMT+01:00 Aliaksei Syrel <[hidden email]>:
This does not really help if you don't know which morph actually gets the shortcut definitions. In my example I did the same mistake, even if you instantiate a RubScrolledTextMORPH the object that processes the keyevents is actually a RubEditingArea, accessible through (RubScollredTextMorph) self textArea. ( if you are working with a spec TextModel this you need to call it two times t:= TextModel new. "the textarea is: " t textArea textArea " : - ("
@Johan, as above, the "correct" morph for processing the keyevents is the textArea of the RubScrolledTextMorph, this should work | window text | text := RubScrolledTextMorph new. "define a custom shortcut - notice the call to textArea" text textArea removeKeyCombination: $s command. text textArea on:$s command do:[ text setText: text text asString reverse]. window := StandardWindow new. window addMorph: text fullFrame: (0@0 corner: 1@1) asLayoutFrame. window title: 'Example'. window openInWorld.
|
In reply to this post by Nicolai Hess-3-2
Wow!!!
Powerful example! Alexandre
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
|
In reply to this post by Nicolai Hess-3-2
(Also, alex, thanks for pointing out the tab in the inspector, but I think I would have not found it since the morph is embedded in a Spec window so it would have been even deeper in the hierarchy.)
---> Save our in-boxes! http://emailcharter.org <---
Johan Fabry - http://pleiad.cl/~jfabry PLEIAD and RyCh labs - Computer Science Department (DCC) - University of Chile |
Free forum by Nabble | Edit this page |