11using System ;
22using System . Collections . Generic ;
33using System . ComponentModel ;
4+ using System . Diagnostics ;
45using System . Linq ;
56using System . Runtime . InteropServices ;
67using System . Windows . Forms ;
@@ -28,7 +29,6 @@ public class RubberduckHooks : IRubberduckHooks
2829 private readonly IGeneralConfigService _config ;
2930 private readonly IEnumerable < CommandBase > _commands ;
3031 private readonly IList < IAttachable > _hooks = new List < IAttachable > ( ) ;
31- private readonly IDictionary < RubberduckHotkey , CommandBase > _mappings ;
3232 private static readonly Logger _logger = LogManager . GetCurrentClassLogger ( ) ;
3333
3434 public RubberduckHooks ( VBE vbe , IGeneralConfigService config , IEnumerable < CommandBase > commands )
@@ -42,29 +42,11 @@ public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<Comman
4242
4343 _commands = commands ;
4444 _config = config ;
45- _mappings = GetCommandMappings ( ) ;
4645 }
4746
48- private CommandBase Command < TCommand > ( ) where TCommand : CommandBase
47+ private CommandBase Command ( RubberduckHotkey hotkey )
4948 {
50- return _commands . OfType < TCommand > ( ) . SingleOrDefault ( ) ;
51- }
52-
53- private IDictionary < RubberduckHotkey , CommandBase > GetCommandMappings ( )
54- {
55- return new Dictionary < RubberduckHotkey , CommandBase >
56- {
57- { RubberduckHotkey . ParseAll , Command < ReparseCommand > ( ) } ,
58- { RubberduckHotkey . CodeExplorer , Command < CodeExplorerCommand > ( ) } ,
59- { RubberduckHotkey . IndentModule , Command < IndentCurrentModuleCommand > ( ) } ,
60- { RubberduckHotkey . IndentProcedure , Command < IndentCurrentProcedureCommand > ( ) } ,
61- { RubberduckHotkey . FindSymbol , Command < FindSymbolCommand > ( ) } ,
62- { RubberduckHotkey . RefactorMoveCloserToUsage , Command < RefactorMoveCloserToUsageCommand > ( ) } ,
63- { RubberduckHotkey . InspectionResults , Command < InspectionResultsCommand > ( ) } ,
64- { RubberduckHotkey . RefactorExtractMethod , Command < RefactorExtractMethodCommand > ( ) } ,
65- { RubberduckHotkey . RefactorRename , Command < CodePaneRefactorRenameCommand > ( ) } ,
66- { RubberduckHotkey . TestExplorer , Command < TestExplorerCommand > ( ) }
67- } ;
49+ return _commands . SingleOrDefault ( s => s . Hotkey == hotkey ) ;
6850 }
6951
7052 public void HookHotkeys ( )
@@ -92,7 +74,10 @@ public void HookHotkeys()
9274 RubberduckHotkey assigned ;
9375 if ( Enum . TryParse ( hotkey . Name , out assigned ) )
9476 {
95- AddHook ( new Hotkey ( _mainWindowHandle , hotkey . ToString ( ) , _mappings [ assigned ] ) ) ;
77+ var command = Command ( assigned ) ;
78+ Debug . Assert ( command != null ) ;
79+
80+ AddHook ( new Hotkey ( _mainWindowHandle , hotkey . ToString ( ) , command ) ) ;
9681 }
9782 }
9883 Attach ( ) ;
0 commit comments