private void LoadOptions() { var settings = Properties.Settings.Default; (App.Current as App).ChangeTheme(settings.Theme); this.Opacity = (double)settings.Opacity; if (settings.WindowPosition.X >= 0) { Left = settings.WindowPosition.X; } if (settings.WindowPosition.Y >= 0) { Top = Properties.Settings.Default.WindowPosition.Y; } if (hotKey != null) { hotKey.Pressed -= HotKey_Pressed; hotKey.Dispose(); } try { hotKey = new HotKey.HotKey(this, (ModifierKeys)settings.HotKeyModifiers, HotKeyConverter.ConvertFromString(settings.HotKeyCharacter)); hotKey.Pressed += HotKey_Pressed; } catch { MessageBox.Show("Hot-key is already in use. Please use another key.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } (NotifyIcon.ContextMenu.Items[0] as MenuItem).InputGestureText = new OptionsViewModel().HotKeyDescription; }
private void HotKey_Pressed(HotKey.HotKey obj) { if (IsVisible) { HideLauncher(); } else { ShowLauncher(); } }
private bool TryRegisterHotKey(string keyGestureString, out HotKey.HotKey hotKey) { try { hotKey = RegisterHotKey(keyGestureString); return(true); } catch { hotKey = null; return(false); } }
private HotKey.HotKey RegisterHotKey(string keyGestureString) { var keyGesture = (KeyGesture) new KeyGestureConverter().ConvertFromString(keyGestureString); hotKey = new HotKey.HotKey(this, keyGesture); hotKey.Pressed += (o) => { if (IsActive) { Hide(); } else { Show(); Activate(); } }; return(hotKey); }
private async Task RegisterHotKeyAsync(string keyGestureString) { try { hotKey = RegisterHotKey(keyGestureString); } catch (NotSupportedException) { var messageBox = new MessageBoxViewModel { Caption = Properties.Resources.HotKey_NotSupported, Button = MessageBoxButton.OK, Icon = MessageBoxImage.Error, }; await Messenger.Default.SendAsync(messageBox); } catch (ArgumentException) { var messageBox = new MessageBoxViewModel { Caption = Properties.Resources.HotKey_Invalid, Text = string.Format(Properties.Resources.HotKey_InvalidText, keyGestureString), Button = MessageBoxButton.OK, Icon = MessageBoxImage.Error, }; await Messenger.Default.SendAsync(messageBox); } catch { var messageBox = new MessageBoxViewModel { Caption = Properties.Resources.HoKey_InUse, Button = MessageBoxButton.OK, Icon = MessageBoxImage.Error, }; await Messenger.Default.SendAsync(messageBox); } }