private bool Close() { RecordingState state = this.recorder.State; bool result = false; switch (state) { case RecordingState.Idle: result = true; break; case RecordingState.Preparing: break; case RecordingState.Paused: case RecordingState.Recording: result = this.view.ShowStopMessage(); if (result) { this.recorder.Stop(); } break; } if (result) { this.view.AllowUpdate = false; if (this.hotKeyManager != null) { this.hotKeyManager.Dispose(); this.hotKeyManager = null; } try { this.configuration.Save(); } catch (ConfigurationException ce) { Trace.TraceError(ce.ToString()); } } return result; }
private void UpdateHotKeys(HotKeySettings oldConfig) { HotKeySettings hotKeysConfig = this.configuration.HotKeys; if (hotKeysConfig.Global) { List<HotKeyType> hotKeyTypesToRegister = new List<HotKeyType>(new HotKeyType[] { HotKeyType.Cancel, HotKeyType.Pause, HotKeyType.Record, HotKeyType.Stop, }); if (this.hotKeyManager == null) { this.hotKeyManager = new HotKeyManager(); this.hotKeyManager.HotKey += new KeyEventHandler(hotKeyManager_HotKey); } else if (oldConfig != null && oldConfig.Global) { // Unregister old hot keys Array hotKeyTypes = Enum.GetValues(typeof(HotKeyType)); foreach (object hotKeyType in hotKeyTypes) { Keys oldHotKey = GetHotKeyFromConfig(oldConfig, (HotKeyType)hotKeyType); Keys newHotKey = GetHotKeyFromConfig(hotKeysConfig, (HotKeyType)hotKeyType); if (oldHotKey == newHotKey) { hotKeyTypesToRegister.Remove((HotKeyType)hotKeyType); } else if (oldHotKey != Keys.None) { try { this.hotKeyManager.UnregisterHotKey(oldHotKey); } catch (InvalidOperationException e) { Trace.TraceWarning(e.ToString()); } } } } // Register new hot keys bool allSucceed = true; foreach (HotKeyType hotKeyType in hotKeyTypesToRegister) { Keys newHotKey = GetHotKeyFromConfig(hotKeysConfig, hotKeyType); try { this.hotKeyManager.RegisterHotKey(newHotKey); } catch (ArgumentException e) { Trace.TraceWarning(e.ToString()); allSucceed = false; } catch (InvalidOperationException e) { Trace.TraceWarning(e.ToString()); allSucceed = false; } } if (!allSucceed) { this.view.ShowHotKeyRegisterWarning(); } } else if (this.hotKeyManager != null) { this.hotKeyManager.HotKey -= hotKeyManager_HotKey; this.hotKeyManager.Dispose(); this.hotKeyManager = null; } }
public HotKeyWindow(HotKeyManager hotKeyManager) { if (hotKeyManager == null) { throw new ArgumentNullException("hotKeyManager"); } this.hotKeyManager = hotKeyManager; }