[英]Reloading keyboard shortcut definitions in Pharo
I've been playing around with keyboard shortcuts in Pharo 7.0. 我一直在使用Pharo 7.0中的键盘快捷键。 I wanted to modify the binding for
#jumpToNextKeywordOfIt
in the Smalltalk editor and so I got the following change in the definition of buildShortcutsOn
method: 我想在Smalltalk编辑器中修改
#jumpToNextKeywordOfIt
的绑定,因此我对buildShortcutsOn
方法的定义进行了以下更改:
(aBuilder shortcut: #jumpToNextKeywordOfIt)
category: RubSmalltalkEditor name
default: $y meta shift
do: [ :target | target editor jumpToNextKeywordOfIt: true ]
description: 'Jump to next keyword'.
My first thought was that just saving this definition should immediately take effect, but it was not the case. 我的第一个想法是,仅保存此定义应立即生效,但事实并非如此。 Then I thought, perhaps since this is part of a method definition, then calling this method on the editor class would do the trick.
然后我想,也许因为这是方法定义的一部分,然后在编辑器类上调用此方法就可以了。 Now, the method takes an argument
aBuilder
and I don't really know what that is. 现在,该方法接受一个参数
aBuilder
,我真的不知道那是什么。 So two questions arise: 因此出现两个问题:
aBuilder
in this context and how does one get it? aBuilder
?如何获得它? Let me give you some hints on how to find the solution (as this might be more valuable than giving the solution at once) 让我给您一些有关如何找到解决方案的提示(因为这可能比一次提供解决方案更有价值)
The problem is what's aBuilder
right? 问题是什么是
aBuilder
? Well, from the expression 好吧,从表达
(aBuilder shortcut: #jumpToNextKeywordOfIt)
we deduce that aBuilder
is someone that responds to #shortcut:
. 我们推断
aBuilder
是响应#shortcut:
。 Cmd+m and you will get 9 implementors of #shortcut:
. Cmd + m,您将获得9个
#shortcut:
实现者。 One of them, KMBuilder
has an interesting name. 其中之一,
KMBuilder
有一个有趣的名字。 Moreover, its implementation of shortcut:
is 而且,它的
shortcut:
实现是shortcut:
shortcut: aKeymapName
^KMKeymapBuilder
for: aKeymapName
platform: platform
meaning that it will answer with an instance of KMKeymapBuilder
. 表示它将使用
KMKeymapBuilder
实例进行KMKeymapBuilder
。 Browse this class and verify that it understands the next message from your expression: 浏览此类,并验证其是否理解表达式中的下一条消息:
category: RubSmalltalkEditor name
default: $y meta shift
do: [ :target | target editor jumpToNextKeywordOfIt: true ]
description: 'Jump to next keyword'.
It does! 是的! So this must be it!
所以一定是这样! To check this, we still need an instance of
KMBuilder
. 要检查这一点,我们仍然需要
KMBuilder
的实例。 Browse the class, go to the class side and find the unary message #keymap
. 浏览班级,转到班级侧并找到一元消息
#keymap
。
This means that we can obtain aBuilder
by evaluating 这意味着我们可以通过评估获得
aBuilder
KMBuilder keymap
I love unary messages. 我喜欢一元信息。 Specially when they are on the class side!
特别是当他们在课堂上时!
Now go to the implementor of the method you already tweaked #buildShortcutsOn:
. 现在转到您已经调整过的
#buildShortcutsOn:
方法的实现者。 It is implemented in the class side and we can now evaluate: 它是在类端实现的,我们现在可以评估:
RubTextEditor buildShortcutsOn: KMBuilder keymap
To make sure that it works, go now to the desired handler #jumpToNextKeywordOfIt:
and insert a halt
in it. 为确保其正常工作,现在转到所需的处理程序
#jumpToNextKeywordOfIt:
并在其中插入halt
。 This is in the same class, instance side. 这是在同一类中,在实例方面。
Now lets press Cmd+Shift+y and see if we get the halt... Bingo! 现在让我们按Cmd + Shift + y,看看我们是否停止了……宾果游戏! I mean, Halt!
我的意思是,停下来!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.