7
votes

In Delphi 2009, I tried to use GExperts to configure the shortcut Ctrl+R (easy to remember) for the rename refactoring. I have not changed any keybinding before so everything is in the IDE default state.

Ctrl+R actually shows up in the IDE menu as shortcut. But pressing this key combination has no effect in the editor.

I can see that Ctrl+R is now shown in the IDE menu Refactor | Rename .... And as expected the default key binding Ctrl+R is no longer shown for the menu item 'Search | Replace ...'.

However, the context menu item Refactoring | Rename ... still shows the default shortcut Shift+Ctrl+E.

Is there a way to set this shortcut?

2
What in the world is Strg?Andreas Rejbrand
@AndreasRejbrand oops, title was correct (Ctrl+C), question body is fixed nowmjn
@AndreasRejbrand It's the german caption for the Ctrl key (Strg is the abbreviation for Steuerung, which is the german translation of control)Frank Schmitt
Maybe, you can try with the shortcut F2, which is simple to remember too... avoiding the Search/Replace shortcut collision...Whiler
@Whiler F2 works. You can make it a answer and chances are that the bounty is yoursmjn

2 Answers

3
votes

I'll admit I'm a bit confused by the steps you've taken. GExperts lets you override default key bindings for its own editor enhancements easily enough but I've never seen a GExpert wizard that will let you redefine key bindings for stock IDE features or other third party extensions.

Nevermind. I've been using GExperts for years and I still find new things I didn't know existed. The "IDE Menu Shortcuts" feature for example. This pretty much makes my previous answer unnecessary. However, since you are already using this feature and the shortcut is still not working here are a few things you can try:

  • Try reordering the "Enhancement modules" in Tools>Options>Editor Options>Key Mappings.
  • Try disabling the "Refactoring Commands" module in this same dialog.

Failing these you can try tinkering around with my previous answer. If writing your own package and tinkering with the IDE internals still produces no results it may simply not be possible. The GExperts documentation says as much:

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.

Anyway hope this helps.

Previous answer:

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.

As for your question about the context menu. Each dockable form in the IDE has a separate context menu populated by an action list. This list is also separate for each dockable form. As far as I can tell there is no correlation between the IDE's main action list and the editor window's action list. My guess is GExperts' author(s) didn't want to attempt to match the context menu's action list with the main menu's action list.

1
votes

F2 - as suggested by @Whiler - can be used as an easy to remember shortcut for the Rename refactoring.