forked from rubberduck-vba/Rubberduck
-
Notifications
You must be signed in to change notification settings - Fork 12
Adding a hotkey
Mathieu Guindon edited this page Apr 4, 2016
·
1 revision
Locate the Rubberduck.Settings.RubberduckHotkey enum:
namespace Rubberduck.Settings
{
public enum RubberduckHotkey
{
IndentProcedure,
IndentModule,
CodeExplorer,
InspectionResults,
TestExplorer,
RefactorRename,
RefactorExtractMethod,
}
}
Add an entry there.
Then, add an entry to the GetCommandMappings dictionary:
private IDictionary<RubberduckHotkey, ICommand> GetCommandMappings()
{
return new Dictionary<RubberduckHotkey, ICommand>
{
{ RubberduckHotkey.CodeExplorer, Command<CodeExplorerCommand>() },
{ RubberduckHotkey.IndentModule, Command<IndentCurrentModuleCommand>() },
{ RubberduckHotkey.IndentProcedure, Command<IndentCurrentProcedureCommand>() },
{ RubberduckHotkey.InspectionResults, Command<InspectionResultsCommand>() },
{ RubberduckHotkey.RefactorExtractMethod, Command<RefactorExtractMethodCommand>() },
{ RubberduckHotkey.RefactorRename, Command<CodePaneRefactorRenameCommand>() },
{ RubberduckHotkey.TestExplorer, Command<TestExplorerCommand>() }
};
}
Now edit the GetDefaultGeneralSettings method and add an entry to the inline array there:
return new GeneralSettings(new DisplayLanguageSetting("en-US"),
new[]
{
new HotkeySetting{Name=RubberduckHotkey.IndentProcedure.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="P", Command = commandMappings[RubberduckHotkey.IndentProcedure]},
new HotkeySetting{Name=RubberduckHotkey.IndentModule.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="M", Command = commandMappings[RubberduckHotkey.IndentModule]},
new HotkeySetting{Name=RubberduckHotkey.CodeExplorer.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="R", Command = commandMappings[RubberduckHotkey.CodeExplorer]},
new HotkeySetting{Name=RubberduckHotkey.InspectionResults.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="I", Command = commandMappings[RubberduckHotkey.InspectionResults]},
new HotkeySetting{Name=RubberduckHotkey.TestExplorer.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="T", Command = commandMappings[RubberduckHotkey.TestExplorer]},
new HotkeySetting{Name=RubberduckHotkey.RefactorRename.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="R", Command = commandMappings[RubberduckHotkey.RefactorRename]},
new HotkeySetting{Name=RubberduckHotkey.RefactorExtractMethod.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="M", Command = commandMappings[RubberduckHotkey.RefactorExtractMethod]}
},
false, 10);
If you run it now, you'll see what's missing - here I'm adding a new RubberduckHotkey.FindSymbol hotkey:

Each RubberduckHotkey enum value has a corresponding HotkeyDescription_[command] entry in RubberduckUI.resx:
-
HotkeyDescription_CodeExplorerforRubberduckHotkey.CodeExplorer -
HotkeyDescription_IndentModuleforRubberduckHotkey.IndentModule -
HotkeyDescription_InspectionResultsforRubberduckHotkey.InspectionResults
So:
-
HotkeyDescription_FooforRubberduckHotkey.Foo
That's it!


@rubberduckvba