Shift-F6作为菜单快捷方式

发布于 2025-02-13 09:46:06 字数 923 浏览 0 评论 0 原文

在我当前的代码中,我具有按预期工作的代码

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥枳 2025-02-20 09:46:06

您正在调用的此构造函数:

转发一些论点要在基类上进行此函数:

https://api.gtkd.org/ gtk.widget.widget.addaccelerator.html

注意CTOR采用 char ,但其他功能采用 uint ,因此它应该能够获得更多的值。

所以我建议尝试:

auto mi = new MenuItem(label, action);
mi.addAccelerator(
  "activate", accelGroup, GDK_F6,
  ModifierType.SHIFT_MASK, 
  AccelFlags.VISIBLE
);

看看它是否有效。

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 takes uint so it should be able to take more values.

So I'd suggest trying:

auto mi = new MenuItem(label, action);
mi.addAccelerator(
  "activate", accelGroup, GDK_F6,
  ModifierType.SHIFT_MASK, 
  AccelFlags.VISIBLE
);

and see if it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文