private static void BindHotkeys()
{
_binder = new HotkeyBinder();
var hotkeySettings = new Dictionary<Type, SettingType>
{
[typeof(UserSelectionTemplate)] = SettingType.SelectAreaHotkey,
[typeof(SelectWindowTemplate)] = SettingType.SelectWindowHotkey,
[typeof(FullScreenTemplate)] = SettingType.FullscreenHotkey
};
var failedHotkeys = new List<SettingType>();
foreach (var hotkeySetting in hotkeySettings)
{
var hotkey = Settings.GetSetting<Hotkey>(hotkeySetting.Value);
if (_binder.IsHotkeyAlreadyBound(hotkey))
{
failedHotkeys.Add(hotkeySetting.Value);
_log.Warn($"Hotkey {hotkeySetting.Value} is already bound. Therefor the hotkey will not be set.");
continue;
}
_binder.Bind(hotkey, args => HandleHotkey(hotkeySetting.Key));
}
if (failedHotkeys.SequenceEqual(hotkeySettings.Select(s => s.Value)))
{
_log.Fatal("All hotkeys failed to bind. Exiting..");
NotificationProvider.Show("Lensert Closing", "All hotkeys failed to bind");
Environment.Exit(0);
}
else if (failedHotkeys.Any())
{
var message = $"Failed to bind: {string.Join(", ", failedHotkeys)}";
NotificationProvider.Show("Error", message, Util.OpenLog);
}
}