简体   繁体   English

e4 KeyBinding和Handler取决于选择

[英]e4 KeyBinding and Handler depending on selection

I defined a KeyBinding in my e4 application model. 我在e4应用程序模型中定义了KeyBinding。 What I want to achieve is that a different handler is used when I press the defined keys - depending on the current selection. 我想要实现的是,当我按下定义的键时,将使用不同的处理程序-取决于当前选择。

One idea would be to define a common handler which checks the selection and then delegates to the appropriate handler. 一种想法是定义一个公共处理程序,该处理程序检查选择内容,然后委派给适当的处理程序。 But I feel this is not optimal and I hope e4 provides some other way of doing this. 但是我觉得这不是最佳选择,我希望e4提供其他实现此目的的方法。

One way is to define multiple Binding Contexts each with its own Binding Table. 一种方法是定义多个绑定上下文,每个绑定上下文都具有自己的绑定表。 You can then bind the key strokes to different commands in each context. 然后,您可以在每个上下文中将击键绑定到不同的命令。

Use the EContextService to activate a particular binding context: 使用EContextService激活特定的绑定上下文:

@Inject
EContextService contextService;


contextService.activateContext("context id");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM