在我当前的代码中,我具有按预期工作的代码
MenuItem runFileItem = new MenuItem(
(MenuItem mi) => pm.runFile(),
"_Run file",
"activate", true, accelGroup, 'r',
ModifierType.CONTROL_MASK | ModifierType.SHIFT_MASK,
AccelFlags.VISIBLE);
- 我可以通过按CTRL+SHIFT+R执行处理程序PM.runfile()。我这样做的原因是因为我无法弄清楚如何实现我想用于此目的的首选Shift+F6。如果我可以放置GDK_F6 GDK Keysym(来自 gdk.keysyms
模块),那将是一件好事,但找不到使用它的方法。我还在GTKD论坛上提出了同样的问题( https:///forum.gtkd .org/groups/gtkd/thread/2976/)没有运气。
因此,问题是如何按原定的计划修改上述代码以正确处理Shift+F6组合?
更新:
根据亚当的答案,以下代码有效:
MenuItem runFileItem = new MenuItem("_Run file", (MenuItem mi) => pm.runFile(), "activate");
runFileItem.addAccelerator("activate", accelGroup, GdkKeysyms.GDK_F6, ModifierType.SHIFT_MASK, AccelFlags.VISIBLE);
In my current code I have the code
MenuItem runFileItem = new MenuItem(
(MenuItem mi) => pm.runFile(),
"_Run file",
"activate", true, accelGroup, 'r',
ModifierType.CONTROL_MASK | ModifierType.SHIFT_MASK,
AccelFlags.VISIBLE);
which works as expected - I can execute the handler pm.runFile() by pressing CTRL+SHIFT+r. Reason why I did it this way is because I could not figure out how to implement the preferred SHIFT+F6 that I wanted to use for this purpose. It would be good if I could put GDK_F6 GDK Keysym (from the gdk.Keysyms
module), but could not find a way to use it. I've also asked the same question on GtkD forum (https://forum.gtkd.org/groups/GtkD/thread/2976/) without luck.
So the question is how to modify the above code to make SHIFT+F6 combination be handled properly as originally planned?
UPDATE:
Based on Adam's answer, the following code works:
MenuItem runFileItem = new MenuItem("_Run file", (MenuItem mi) => pm.runFile(), "activate");
runFileItem.addAccelerator("activate", accelGroup, GdkKeysyms.GDK_F6, ModifierType.SHIFT_MASK, AccelFlags.VISIBLE);
发布评论
评论(1)
您正在调用的此构造函数:
转发一些论点要在基类上进行此函数:
https://api.gtkd.org/ gtk.widget.widget.addaccelerator.html
注意CTOR采用
char
,但其他功能采用uint
,因此它应该能够获得更多的值。所以我建议尝试:
看看它是否有效。
This constructor you're calling: https://api.gtkd.org/gtk.MenuItem.MenuItem.this.3.html
Forwards some of its arguments to this function on the base class:
https://api.gtkd.org/gtk.Widget.Widget.addAccelerator.html
Notice the ctor takes
char
but that other function takesuint
so it should be able to take more values.So I'd suggest trying:
and see if it works.