gpt4 book ai didi

delphi - 如何将 Ctrl+R 设置为 Delphi 中 "Rename"重构的快捷方式?

转载 作者:行者123 更新时间:2023-12-03 14:54:13 27 4
gpt4 key购买 nike

在Delphi 2009中,我尝试使用GExperts来配置快捷键Ctrl+R(易于内存)进行重命名重构。我之前没有更改过任何键绑定(bind),因此一切都处于 IDE 默认状态。

Ctrl+R 实际上在 IDE 菜单中显示为快捷方式。但按此组合键在编辑器中没有任何效果。

我可以看到 Ctrl+R 现在显示在 IDE 菜单中 Refactor |重命名...。正如预期的那样,菜单项“搜索 | ”不再显示默认键绑定(bind) Ctrl+R。代替 ...'。

但是,上下文菜单项重构 |重命名...仍然显示默认快捷键Shift+Ctrl+E

有办法设置这个快捷键吗?

最佳答案

我承认我对你所采取的步骤有点困惑。 GExperts 可以让您轻松地覆盖其自身编辑器增强功能的默认键绑定(bind),但我从未见过 GExpert 向导可以让您重新定义常用 IDE 功能或其他第三方扩展的键绑定(bind)。

没关系。我已经使用 GExperts 多年了,但我仍然发现了一些我不知道的新东西。例如“IDE 菜单快捷方式”功能。这几乎使我之前的回答变得不必要。但是,由于您已经在使用此功能,并且快捷方式仍然不起作用,因此您可以尝试以下一些操作:

  • 尝试在“工具”>“选项”>“编辑器”中重新排序“增强模块”选项>按键映射。
  • 尝试在同一对话框中禁用“重构命令”模块。

如果这些都失败了,你可以尝试修改我之前的答案。如果编写自己的包并修改 IDE 内部结构仍然没有产生任何结果,那么这可能根本不可能。 GExperts 文档说了这么多:

If you find your chosen shortcut does not work, it is likely because the shortcut is reserved by the code editor or another menu item, and you'll need to select a different, unused shortcut.

无论如何希望这会有所帮助。

上一个答案:

Keyboard bindings are implemented using the Open Tools Api. Unfortunately it is the most poorly documented part of the IDE so you're kind of shooting in the dark.

There are two types of key bindings:

  • Complete - An exclusive mapping of keys to commands. Only one complete binding can be active at a time.
  • Partial - An extension to the currently active complete binding.

I can't say for sure in Delphi 2009 but in Delphi 2010 and above there is a list of these partial bindings (at least the ones that bothered to implement a Display Name) in Options > Editor Options > KeyMappings > Enhancement modules. Supposedly they can be enabled/disabled by clicking the checkbox next to each one but this didn't seem to have any effect on the ones I tried, even after reloading the IDE.

"Refactoring Commands" is one of the bindings listed. The refactoring package is implemented as a collection .NET assemblies (Borland.Together.Refactoring.*.dll) with only a small stub being the standard BPL. It may be helpful to inspect it's inner workings with one of the many "reflection" tools available.

In any case the IOTAKeyboardServices interface in ToolsAPI.pas is where you would need to look to change an existing binding. Four functions of interest:

  • AddKeyboardBinding
  • LookupKeyBinding
  • GetNextBindingRec
  • RemoveKeyboardBinding

Assuming they actually work in a predictable manor these functions should allow you to identify the TKeyBindingRec that's handling the CTRL+R.

Keep in mind that any IDE package can bind to a keyboard shortcut and users can load and unload packages on a whim. This means you can't assume there is only one command bound to a shortcut. You can't even assume that the binding will be the same between one press and the next.

While in theory a shortcut could trigger multiple unrelated commands it rarely works out that way. Most packages assume they are the sole listener for a shortcut and return a TKeyBindingResult of krHandled, which will halt further processing of that shortcut until it is pressed again.

至于你关于上下文菜单的问题。 IDE 中的每个可停靠表单都有一个由操作列表填充的单独上下文菜单。对于每个可停靠表单,此列表也是单独的。据我所知,IDE 的主操作列表和编辑器窗口的操作列表之间没有任何关联。我的猜测是 GExperts 的作者不想尝试将上下文菜单的操作列表与主菜单的操作列表相匹配。

关于delphi - 如何将 Ctrl+R 设置为 Delphi 中 "Rename"重构的快捷方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16506278/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com