Skip to content

Commit 11a63c8

Browse files
committed
added command mappings
1 parent fdf1ab9 commit 11a63c8

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

RetailCoder.VBE/Settings/ConfigurationLoader.cs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public override Configuration LoadConfiguration()
5151
{
5252
config.UserSettings.GeneralSettings = GetDefaultGeneralSettings();
5353
}
54+
else
55+
{
56+
AssociateHotkeyCommands(config);
57+
}
5458

5559
if (config.UserSettings.ToDoListSettings == null)
5660
{
@@ -80,6 +84,33 @@ public override Configuration LoadConfiguration()
8084
return config;
8185
}
8286

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+
83114
protected override Configuration HandleIOException(IOException ex)
84115
{
85116
return GetDefaultConfiguration();
@@ -139,16 +170,17 @@ public Configuration GetDefaultConfiguration()
139170

140171
private GeneralSettings GetDefaultGeneralSettings()
141172
{
173+
var commandMappings = GetCommandMappings();
142174
return new GeneralSettings(new DisplayLanguageSetting("en-US"),
143175
new[]
144176
{
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]}
152184
},
153185
false, 10);
154186
}

0 commit comments

Comments
 (0)