private void ExecuteHideBarButtonCommand() { if (_mouseAndKeyboardHookService != null) { if (Settings.Default.ClosePasteBarWhenMouseIsAway) { _mouseAndKeyboardHookService.MouseAction -= MouseAndKeyboardHookService_MouseAction; } if (Settings.Default.ClosePasteBarWithHotKey) { _mouseAndKeyboardHookService.UnregisterHotKey(Consts.PasteShortcutName); _mouseAndKeyboardHookService.HotKeyDetected -= MouseAndKeyboardHookService_HotKeyDetected; } _mouseAndKeyboardHookService.Pause(); } Logger.Instance.Information($"The paste bar window has been hidden."); MessengerInstance.Send(new ComponentModel.Messages.Message(), MessageIdentifiers.HidePasteBarWindow); var delayer = new Delayer <object>(TimeSpan.FromMilliseconds(200)); delayer.Action += (sender, args) => { _mouseAndKeyboardHookService = null; _canCloseIfMouseMovesAway = false; if (!string.IsNullOrEmpty(SearchQueryString) || SearchType != SearchType.All) { SearchQueryString = string.Empty; SearchType = SearchType.All; Search(); } }; delayer.ResetAndTick(); }
/// <summary> /// Display on the screen the paste bare with an animation. /// </summary> internal void DisplayBar() { var delayer = new Delayer <object>(TimeSpan.FromMilliseconds(250)); delayer.Action += (sender, args) => { if (Settings.Default.ClosePasteBarWhenMouseIsAway && !CoreHelper.IsUnitTesting()) { _mouseAndKeyboardHookService = ServiceLocator.GetService <MouseAndKeyboardHookService>(); _mouseAndKeyboardHookService.MouseAction += MouseAndKeyboardHookService_MouseAction; _mouseAndKeyboardHookService.Resume(); } if (Settings.Default.ClosePasteBarWithHotKey && !CoreHelper.IsUnitTesting()) { if (_mouseAndKeyboardHookService == null) { _mouseAndKeyboardHookService = ServiceLocator.GetService <MouseAndKeyboardHookService>(); } _mouseAndKeyboardHookService.HotKeyDetected += MouseAndKeyboardHookService_HotKeyDetected; _mouseAndKeyboardHookService.RegisterHotKey(Consts.PasteShortcutName, Settings.Default.KeyboardShortcut.Cast <Key>().ToArray()); _mouseAndKeyboardHookService.Resume(); Logger.Instance.Information($"The keyboard is listened. The expecting shortcut is {JsonConvert.SerializeObject(Settings.Default.KeyboardShortcut.Cast<Key>().ToArray())}."); } }; delayer.ResetAndTick(); }
/// <summary> /// Initialize a new instance of the <see cref="SettingsGeneralUserControlViewModel"/> class. /// </summary> internal SettingsGeneralUserControlViewModel() { if (!IsInDesignMode) { _mouseAndKeyboardHookService = ServiceLocator.GetService <MouseAndKeyboardHookService>(); } _settingProvider = new ServiceSettingProvider(); _keyboardShortcut = new List <Key>(); InitializeCommands(); DisplayCurrentKeyboardShortcut(); }