@@ -51,6 +51,10 @@ public override Configuration LoadConfiguration()
51
51
{
52
52
config . UserSettings . GeneralSettings = GetDefaultGeneralSettings ( ) ;
53
53
}
54
+ else
55
+ {
56
+ AssociateHotkeyCommands ( config ) ;
57
+ }
54
58
55
59
if ( config . UserSettings . ToDoListSettings == null )
56
60
{
@@ -80,6 +84,33 @@ public override Configuration LoadConfiguration()
80
84
return config ;
81
85
}
82
86
87
+ private IDictionary < RubberduckHotkey , ICommand > GetCommandMappings ( )
88
+ {
89
+ return new Dictionary < RubberduckHotkey , ICommand >
90
+ {
91
+ { RubberduckHotkey . CodeExplorer , _commands . SingleOrDefault ( cmd => cmd is CodeExplorerCommand ) } ,
92
+ { RubberduckHotkey . IndentModule , _commands . SingleOrDefault ( cmd => cmd is IndentCurrentModuleCommand ) } ,
93
+ { RubberduckHotkey . IndentProcedure , _commands . SingleOrDefault ( cmd => cmd is IndentCurrentProcedureCommand ) } ,
94
+ { RubberduckHotkey . InspectionResults , _commands . SingleOrDefault ( cmd => cmd is InspectionResultsCommand ) } ,
95
+ { RubberduckHotkey . RefactorExtractMethod , _commands . SingleOrDefault ( cmd => cmd is RefactorExtractMethodCommand ) } ,
96
+ { RubberduckHotkey . RefactorRename , _commands . SingleOrDefault ( cmd => cmd is CodePaneRefactorRenameCommand ) } ,
97
+ { RubberduckHotkey . TestExplorer , _commands . SingleOrDefault ( cmd => cmd is TestExplorerCommand ) }
98
+ } ;
99
+ }
100
+
101
+ private void AssociateHotkeyCommands ( Configuration config )
102
+ {
103
+ var mappings = GetCommandMappings ( ) ;
104
+ foreach ( var setting in config . UserSettings . GeneralSettings . HotkeySettings )
105
+ {
106
+ RubberduckHotkey hotkey ;
107
+ if ( Enum . TryParse ( setting . Name , out hotkey ) )
108
+ {
109
+ setting . Command = mappings [ hotkey ] ;
110
+ }
111
+ }
112
+ }
113
+
83
114
protected override Configuration HandleIOException ( IOException ex )
84
115
{
85
116
return GetDefaultConfiguration ( ) ;
@@ -139,16 +170,17 @@ public Configuration GetDefaultConfiguration()
139
170
140
171
private GeneralSettings GetDefaultGeneralSettings ( )
141
172
{
173
+ var commandMappings = GetCommandMappings ( ) ;
142
174
return new GeneralSettings ( new DisplayLanguageSetting ( "en-US" ) ,
143
175
new [ ]
144
176
{
145
- new HotkeySetting { Name = RubberduckHotkey . IndentProcedure . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , Key1 = "P" , Command = _commands . SingleOrDefault ( cmd => cmd is IndentCurrentProcedureCommand ) } ,
146
- new HotkeySetting { Name = RubberduckHotkey . IndentModule . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , Key1 = "M" , Command = _commands . SingleOrDefault ( cmd => cmd is IndentCurrentModuleCommand ) } ,
147
- new HotkeySetting { Name = RubberduckHotkey . CodeExplorer . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , Key1 = "R" , Command = _commands . SingleOrDefault ( cmd => cmd is CodeExplorerCommand ) } ,
148
- new HotkeySetting { Name = RubberduckHotkey . InspectionResults . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , HasShiftModifier = true , Key1 = "I" , Command = _commands . SingleOrDefault ( cmd => cmd is InspectionResultsCommand ) } ,
149
- new HotkeySetting { Name = RubberduckHotkey . TestExplorer . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , HasShiftModifier = true , Key1 = "T" , Command = _commands . SingleOrDefault ( cmd => cmd is TestExplorerCommand ) } ,
150
- new HotkeySetting { Name = RubberduckHotkey . RefactorRename . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , HasShiftModifier = true , Key1 = "R" , Command = _commands . SingleOrDefault ( cmd => cmd is CodePaneRefactorRenameCommand ) } ,
151
- new HotkeySetting { Name = RubberduckHotkey . RefactorExtractMethod . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , HasShiftModifier = true , Key1 = "M" , Command = _commands . SingleOrDefault ( cmd => cmd is RefactorExtractMethodCommand ) }
177
+ new HotkeySetting { Name = RubberduckHotkey . IndentProcedure . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , Key1 = "P" , Command = commandMappings [ RubberduckHotkey . IndentProcedure ] } ,
178
+ new HotkeySetting { Name = RubberduckHotkey . IndentModule . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , Key1 = "M" , Command = commandMappings [ RubberduckHotkey . IndentModule ] } ,
179
+ new HotkeySetting { Name = RubberduckHotkey . CodeExplorer . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , Key1 = "R" , Command = commandMappings [ RubberduckHotkey . CodeExplorer ] } ,
180
+ new HotkeySetting { Name = RubberduckHotkey . InspectionResults . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , HasShiftModifier = true , Key1 = "I" , Command = commandMappings [ RubberduckHotkey . InspectionResults ] } ,
181
+ new HotkeySetting { Name = RubberduckHotkey . TestExplorer . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , HasShiftModifier = true , Key1 = "T" , Command = commandMappings [ RubberduckHotkey . TestExplorer ] } ,
182
+ new HotkeySetting { Name = RubberduckHotkey . RefactorRename . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , HasShiftModifier = true , Key1 = "R" , Command = commandMappings [ RubberduckHotkey . RefactorRename ] } ,
183
+ new HotkeySetting { Name = RubberduckHotkey . RefactorExtractMethod . ToString ( ) , IsEnabled = true , HasCtrlModifier = true , HasShiftModifier = true , Key1 = "M" , Command = commandMappings [ RubberduckHotkey . RefactorExtractMethod ] }
152
184
} ,
153
185
false , 10 ) ;
154
186
}
0 commit comments