private void RefreshHotkeys() { // Unregister all hotkeys. foreach (var hotkey in _hotkeys) { hotkey.Dispose(); } _hotkeys.Clear(); // Remove any hotkeys for profiles that no longer exist (but keep hotkeys for system commands). if (SettingsFiles.ApplicationSettings.Hotkeys.RemoveAll(x => !SystemCommands.IsSystemCommand(x.Id) && !_profiles.ContainsKey(x.Id)) != 0) { SettingsFiles.SaveApplicationSettings(); } // Register hotkeys. foreach (var hotkeySetting in SettingsFiles.ApplicationSettings.Hotkeys) { var id = hotkeySetting.Id; try { _hotkeys.Add(new WinFormsHotkey(hotkeySetting.Hotkey, true, () => ExecuteSystemCommandOrLoadProfile(hotkeySetting.Id))); } catch (Exception ex) { BalloonTip("Could not bind hotkey " + WinFormsHotkey.HotkeyString(hotkeySetting.Hotkey) + " to " + SystemCommands.GetTitle(id), ex.Message, ToolTipIcon.Warning); } } }
private void ExecuteSystemCommandOrLoadProfile(string id) { if (SystemCommands.IsSystemCommand(id)) { ExecuteSystemCommand(id); } else { LoadProfile(id); } }