diff --git a/Plugins/Wox.Plugin.PluginManagement/Main.cs b/Plugins/Wox.Plugin.PluginManagement/Main.cs index 18af05f069..7af6db9257 100644 --- a/Plugins/Wox.Plugin.PluginManagement/Main.cs +++ b/Plugins/Wox.Plugin.PluginManagement/Main.cs @@ -152,7 +152,6 @@ namespace Wox.Plugin.PluginManagement if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); string filePath = Path.Combine(folder, Guid.NewGuid().ToString() + ".wox"); - context.API.StartLoadingBar(); string pluginUrl = APIBASE + "/media/" + r1.plugin_file; try @@ -168,7 +167,6 @@ namespace Wox.Plugin.PluginManagement return false; } context.API.InstallPlugin(filePath); - context.API.StopLoadingBar(); } return false; } diff --git a/Plugins/Wox.Plugin.Shell/Main.cs b/Plugins/Wox.Plugin.Shell/Main.cs index c605ed4bbe..321008c9ab 100644 --- a/Plugins/Wox.Plugin.Shell/Main.cs +++ b/Plugins/Wox.Plugin.Shell/Main.cs @@ -3,13 +3,14 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Windows.Forms; +using System.Windows; using WindowsInput; -using WindowsInput.Native; using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage; +using Application = System.Windows.Application; using Control = System.Windows.Controls.Control; +using Keys = System.Windows.Forms.Keys; namespace Wox.Plugin.CMD { @@ -191,7 +192,7 @@ namespace Wox.Plugin.CMD } else if (_settings.Shell == Shell.RunCommand) { - var parts = command.Split(new[] {' '}, 2); + var parts = command.Split(new[] { ' ' }, 2); if (parts.Length == 2) { var filename = parts[0]; @@ -283,17 +284,16 @@ namespace Wox.Plugin.CMD if (keyevent == (int)KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) { WinRStroked = false; - keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL); return false; } } - return true; + return false; } private void OnWinRPressed() { - context.API.ShowApp(); context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeperater}"); + Application.Current.MainWindow.Visibility = Visibility.Visible; } public Control CreateSettingPanel() @@ -311,8 +311,6 @@ namespace Wox.Plugin.CMD return context.API.GetTranslation("wox_plugin_cmd_plugin_description"); } - public bool IsInstantQuery(string query) => false; - public List LoadContextMenus(Result selectedResult) { return new List @@ -322,7 +320,6 @@ namespace Wox.Plugin.CMD Title = context.API.GetTranslation("wox_plugin_cmd_run_as_administrator"), Action = c => { - context.API.HideApp(); Execute(selectedResult.Title, true); return true; }, diff --git a/Plugins/Wox.Plugin.Sys/Main.cs b/Plugins/Wox.Plugin.Sys/Main.cs index 01b7a2d262..de17a1dfa6 100644 --- a/Plugins/Wox.Plugin.Sys/Main.cs +++ b/Plugins/Wox.Plugin.Sys/Main.cs @@ -161,7 +161,7 @@ namespace Wox.Plugin.Sys IcoPath = "Images\\app.png", Action = c => { - context.API.CloseApp(); + Application.Current.MainWindow.Close(); return true; } }, diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index e793dfd599..56870be676 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -3,6 +3,7 @@ using System.IO; using NLog; using NLog.Config; using NLog.Targets; +using Wox.Infrastructure.Exception; namespace Wox.Infrastructure.Logger { diff --git a/Wox.Plugin/IPublicAPI.cs b/Wox.Plugin/IPublicAPI.cs index 0608703e76..c726c962a6 100644 --- a/Wox.Plugin/IPublicAPI.cs +++ b/Wox.Plugin/IPublicAPI.cs @@ -31,11 +31,13 @@ namespace Wox.Plugin /// Just change the query text, this won't raise search /// /// + [Obsolete] void ChangeQueryText(string query, bool selectAll = false); /// /// Close Wox /// + [Obsolete] void CloseApp(); /// @@ -46,11 +48,13 @@ namespace Wox.Plugin /// /// Hide Wox /// + [Obsolete] void HideApp(); /// /// Show Wox /// + [Obsolete] void ShowApp(); /// @@ -69,11 +73,13 @@ namespace Wox.Plugin /// /// Show loading animation /// + [Obsolete("automatically start")] void StartLoadingBar(); /// /// Stop loading animation /// + [Obsolete("automatically stop")] void StopLoadingBar(); /// diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index d745466cd5..1afae043ef 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -8,7 +8,6 @@ using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure.Image; using Wox.Infrastructure.Logger; -using Wox.Infrastructure.Storage; using Wox.ViewModel; using Stopwatch = Wox.Infrastructure.Stopwatch; @@ -61,7 +60,10 @@ namespace Wox AutoStartup(); AutoUpdates(); - window.Show(); + if (!_settings.HideOnStartup) + { + mainVM.MainWindowVisibility = Visibility.Visible; + } }); } @@ -116,7 +118,7 @@ namespace Wox [Conditional("RELEASE")] private static void RegisterAppDomainExceptions() { - + AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle; AppDomain.CurrentDomain.FirstChanceException += (s, e) => { @@ -131,14 +133,14 @@ namespace Wox // but if sessionending is not called, exit won't be called when log off / shutdown if (!_disposed) { - Current.Dispatcher.Invoke(() => ((MainViewModel) Current.MainWindow?.DataContext)?.Save()); + Current.Dispatcher.Invoke(() => ((MainViewModel)Current.MainWindow?.DataContext)?.Save()); _disposed = true; } } public void OnSecondAppStarted() { - API.ShowApp(); + Current.MainWindow.Visibility = Visibility.Visible; } } } \ No newline at end of file diff --git a/Wox/CustomQueryHotkeySetting.xaml.cs b/Wox/CustomQueryHotkeySetting.xaml.cs index 48194359ff..83f47daa76 100644 --- a/Wox/CustomQueryHotkeySetting.xaml.cs +++ b/Wox/CustomQueryHotkeySetting.xaml.cs @@ -55,7 +55,7 @@ namespace Wox SetHotkey(ctlHotkey.CurrentHotkey, delegate { App.API.ChangeQuery(pluginHotkey.ActionKeyword); - App.API.ShowApp(); + Application.Current.MainWindow.Visibility = Visibility.Visible; }); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed")); } @@ -73,8 +73,8 @@ namespace Wox RemoveHotkey(oldHotkey); SetHotkey(new HotkeyModel(updateCustomHotkey.Hotkey), delegate { - App.API.ShowApp(); App.API.ChangeQuery(updateCustomHotkey.ActionKeyword); + Application.Current.MainWindow.Visibility = Visibility.Visible; }); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed")); } @@ -100,8 +100,8 @@ namespace Wox private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e) { - App.API.ShowApp(); App.API.ChangeQuery(tbAction.Text); + Application.Current.MainWindow.Visibility = Visibility.Visible; } private void RemoveHotkey(string hotkeyStr) diff --git a/Wox/Helper/SingletonWindowOpener.cs b/Wox/Helper/SingletonWindowOpener.cs index e9d9a594ea..440d223e70 100644 --- a/Wox/Helper/SingletonWindowOpener.cs +++ b/Wox/Helper/SingletonWindowOpener.cs @@ -10,7 +10,7 @@ namespace Wox.Helper { var window = Application.Current.Windows.OfType().FirstOrDefault(x => x.GetType() == typeof(T)) ?? (T)Activator.CreateInstance(typeof(T), args); - App.API.HideApp(); + Application.Current.MainWindow.Hide(); window.Show(); window.Focus(); diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml index f0cbd80803..ce23705669 100644 --- a/Wox/MainWindow.xaml +++ b/Wox/MainWindow.xaml @@ -7,10 +7,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="Wox" Topmost="True" - Loaded="OnLoaded" - Closing="OnClosing" - Drop="OnDrop" - Deactivated="OnDeactivated" SizeToContent="Height" ResizeMode="NoResize" WindowStyle="None" @@ -20,17 +16,22 @@ Style="{DynamicResource WindowStyle}" Icon="Images\app.png" AllowsTransparency="True" - Left="{Binding Left, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" - Top="{Binding Top, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" + Loaded="OnLoaded" + Closing="OnClosing" + Drop="OnDrop" + SizeChanged="OnSizeChanged" + IsVisibleChanged="OnMainWindowVisible" + Deactivated="OnDeactivated" + PreviewKeyDown="OnKeyDown" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" - d:DataContext="{d:DesignInstance vm:MainViewModel}"> + d:DataContext="{d:DesignInstance vm:MainViewModel}" + FocusManager.FocusedElement="{Binding ElementName=QueryTextBox}" + FocusManager.IsFocusScope="True"> - - @@ -50,12 +51,16 @@ - + diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index f8c5af7b08..c002fe8afc 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -1,7 +1,6 @@ using System; using System.ComponentModel; using System.Windows; -using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media.Animation; using System.Windows.Controls; @@ -10,11 +9,10 @@ using Wox.Core.Resource; using Wox.Core.UserSettings; using Wox.Helper; using Wox.ViewModel; +using Screen = System.Windows.Forms.Screen; using ContextMenu = System.Windows.Forms.ContextMenu; -using DataFormats = System.Windows.DataFormats; -using DragEventArgs = System.Windows.DragEventArgs; using MenuItem = System.Windows.Forms.MenuItem; -using MessageBox = System.Windows.MessageBox; +using NotifyIcon = System.Windows.Forms.NotifyIcon; namespace Wox { @@ -26,81 +24,42 @@ namespace Wox private readonly Storyboard _progressBarStoryboard = new Storyboard(); private Settings _settings; private NotifyIcon _notifyIcon; + private MainViewModel _viewModel; #endregion public MainWindow(Settings settings, MainViewModel mainVM) { - DataContext = mainVM; InitializeComponent(); + DataContext = mainVM; + _viewModel = mainVM; _settings = settings; } public MainWindow() { InitializeComponent(); } + private void OnClosing(object sender, CancelEventArgs e) { _notifyIcon.Visible = false; - _settings.WindowLeft = Left; - _settings.WindowTop = Top; - var vm = (MainViewModel)DataContext; - vm.Save(); + _viewModel.Save(); } - - private void OnLoaded(object sender, RoutedEventArgs _) { InitProgressbarAnimation(); WindowIntelopHelper.DisableControlBox(this); ThemeManager.Instance.ChangeTheme(_settings.Theme); InitializeNotifyIcon(); - - var vm = (MainViewModel)DataContext; - RegisterEvents(vm); - - // happlebao todo delete - vm.Left = GetWindowsLeft(); - vm.Top = GetWindowsTop(); - vm.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible; - } - - private void RegisterEvents(MainViewModel vm) - { - vm.TextBoxSelected += (o, e) => QueryTextBox.SelectAll(); - vm.CursorMovedToEnd += (o, e) => - { - QueryTextBox.Focus(); - QueryTextBox.CaretIndex = QueryTextBox.Text.Length; - }; - vm.PropertyChanged += (o, e) => - { - if (e.PropertyName == nameof(vm.MainWindowVisibility)) - { - if (vm.MainWindowVisibility.IsVisible()) - { - Activate(); - QueryTextBox.Focus(); - Left = GetWindowsLeft(); - Top = GetWindowsTop(); - _settings.ActivateTimes++; - } - else - { - _settings.WindowLeft = Left; - _settings.WindowTop = Top; - } - } - }; } private void InitializeNotifyIcon() { _notifyIcon = new NotifyIcon { Text = Infrastructure.Constant.Wox, Icon = Properties.Resources.app, Visible = true }; - _notifyIcon.Click += (o, e) => App.API.ShowApp(); + _notifyIcon.Click += (o, e) => Visibility = Visibility.Visible; var open = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayOpen")); - open.Click += (o, e) => App.API.ShowApp(); + open.Click += (o, e) => Visibility = Visibility.Visible; var setting = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTraySettings")); setting.Click += (o, e) => App.API.OpenSettingDialog(); var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit")); @@ -109,34 +68,6 @@ namespace Wox _notifyIcon.ContextMenu = new ContextMenu(childen); } - private double GetWindowsLeft() - { - if (_settings.RememberLastLaunchLocation) - { - return _settings.WindowLeft; - } - - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); - var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); - var left = (dip2.X - ActualWidth) / 2 + dip1.X; - return left; - } - - private double GetWindowsTop() - { - if (_settings.RememberLastLaunchLocation) - { - return _settings.WindowTop; - } - - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); - var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); - var top = (dip2.Y - ActualHeight) / 4 + dip1.Y; - return top; - } - private void InitProgressbarAnimation() { var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); @@ -146,8 +77,8 @@ namespace Wox _progressBarStoryboard.Children.Add(da); _progressBarStoryboard.Children.Add(da1); _progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever; - ProgressBar.Visibility = Visibility.Hidden; ProgressBar.BeginStoryboard(_progressBarStoryboard); + _viewModel.ProgressBarVisibility = Visibility.Hidden; } private void OnMouseDown(object sender, MouseButtonEventArgs e) @@ -155,14 +86,6 @@ namespace Wox if (e.ChangedButton == MouseButton.Left) DragMove(); } - private void OnDeactivated(object sender, EventArgs e) - { - if (_settings.HideWhenDeactive) - { - App.API.HideApp(); - } - } - private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e) { if (sender != null && e.OriginalSource != null) @@ -173,17 +96,13 @@ namespace Wox var result = (ResultViewModel)item?.DataContext; if (result != null) { - var vm = DataContext as MainViewModel; - if (vm != null) + if (e.ChangedButton == MouseButton.Left) { - if (e.ChangedButton == MouseButton.Left) - { - vm.OpenResultCommand.Execute(null); - } - else if (e.ChangedButton == MouseButton.Right) - { - vm.LoadContextMenuCommand.Execute(null); - } + _viewModel.OpenResultCommand.Execute(null); + } + else if (e.ChangedButton == MouseButton.Right) + { + _viewModel.LoadContextMenuCommand.Execute(null); } } } @@ -217,5 +136,110 @@ namespace Wox { App.API.OpenSettingDialog(); } + + + private void OnDeactivated(object sender, EventArgs e) + { + if (_settings.HideWhenDeactive) + { + Hide(); + } + } + + private void OnQueryVisible(object sender, DependencyPropertyChangedEventArgs e) + { + var visible = (bool)e.NewValue; + if (visible) + { + // the Focusable and the IsVisible both needs to be true when set focus + // logical is set in xaml + QueryTextBox.Focus(); + + if (_viewModel.QueryTextSelected) + { + QueryTextBox.SelectAll(); + _viewModel.QueryTextSelected = false; + } + } + } + + private void OnQueryChanged(object sender, TextChangedEventArgs e) + { + QueryTextBox.CaretIndex = QueryTextBox.Text.Length; + } + + private void OnMainWindowVisible(object sender, DependencyPropertyChangedEventArgs e) + { + var visible = (bool)e.NewValue; + if (visible) + { + SetWindowPosition(); + _settings.ActivateTimes++; + } + } + + private bool _startup = true; + private void SetWindowPosition() + { + if (!_settings.RememberLastLaunchLocation && !_startup) + { + Left = WindowLeft(); + Top = WindowTop(); + } + else + { + _startup = false; + } + } + + + + /// + // used to set correct position on windows first startup + // since the actual width and actual height will be avaiable after this event + /// + private void OnSizeChanged(object sender, SizeChangedEventArgs e) + { + Left = WindowLeft(); + Top = WindowTop(); + } + + private double WindowLeft() + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); + var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); + var left = (dip2.X - ActualWidth) / 2 + dip1.X; + return left; + } + + private double WindowTop() + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); + var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); + var top = (dip2.Y - QueryTextBox.ActualHeight) / 4 + dip1.Y; + return top; + } + + /// + /// Register up and down key + /// todo: any way to put this in xaml ? + /// + private void OnKeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Down) + { + _viewModel.SelectNextItemCommand.Execute(null); + e.Handled = true; + } + else if (e.Key == Key.Up) + { + _viewModel.SelectPrevItemCommand.Execute(null); + e.Handled = true; + } + } + + } } \ No newline at end of file diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index 36d995fbe4..e9801f686c 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -16,15 +16,15 @@ namespace Wox { public class PublicAPIInstance : IPublicAPI { - private readonly SettingWindowViewModel _settingsViewModel; + private readonly SettingWindowViewModel _settingsVM; + private readonly MainViewModel _mainVM; #region Constructor - public PublicAPIInstance(SettingWindowViewModel settingsViewModel, MainViewModel mainVM) + public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM) { - _settingsViewModel = settingsViewModel; - MainVM = mainVM; - //_settings = settings; + _settingsVM = settingsVM; + _mainVM = mainVM; GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback; WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); @@ -32,39 +32,27 @@ namespace Wox #endregion - #region Properties - - public MainViewModel MainVM - { - get; - set; - } - - #endregion - #region Public API public void ChangeQuery(string query, bool requery = false) { - MainVM.QueryText = query; - MainVM.OnCursorMovedToEnd(); + _mainVM.QueryText = query; } public void ChangeQueryText(string query, bool selectAll = false) { - MainVM.QueryText = query; - MainVM.OnTextBoxSelected(); + _mainVM.QueryText = query; } + [Obsolete] public void CloseApp() { - //notifyIcon.Visible = false; Application.Current.MainWindow.Close(); } public void RestarApp() { - HideWox(); + _mainVM.MainWindowVisibility = Visibility.Hidden; // we must manually save // UpdateManager.RestartApp() will call Environment.Exit(0) // which will cause ungraceful exit @@ -73,14 +61,16 @@ namespace Wox UpdateManager.RestartApp(); } + [Obsolete] public void HideApp() { - HideWox(); + _mainVM.MainWindowVisibility = Visibility.Hidden; } + [Obsolete] public void ShowApp() { - ShowWox(); + _mainVM.MainWindowVisibility = Visibility.Visible; } public void ShowMsg(string title, string subTitle = "", string iconPath = "") @@ -96,18 +86,18 @@ namespace Wox { Application.Current.Dispatcher.Invoke(() => { - SettingWindow sw = SingletonWindowOpener.Open(this, _settingsViewModel); + SettingWindow sw = SingletonWindowOpener.Open(this, _settingsVM); }); } public void StartLoadingBar() { - MainVM.ProgressBarVisibility = Visibility.Visible; + _mainVM.ProgressBarVisibility = Visibility.Visible; } public void StopLoadingBar() { - MainVM.ProgressBarVisibility = Visibility.Collapsed; + _mainVM.ProgressBarVisibility = Visibility.Collapsed; } public void InstallPlugin(string path) @@ -138,7 +128,7 @@ namespace Wox }); Task.Run(() => { - MainVM.UpdateResultView(results, plugin, query); + _mainVM.UpdateResultView(results, plugin, query); }); } @@ -154,17 +144,6 @@ namespace Wox } return true; } - - private void HideWox() - { - MainVM.MainWindowVisibility = Visibility.Collapsed; - } - - private void ShowWox(bool selectAll = true) - { - MainVM.MainWindowVisibility = Visibility.Visible; - MainVM.OnTextBoxSelected(); - } #endregion } } diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index c022d7286b..0fd0c8b9e5 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -128,15 +128,15 @@ namespace Wox { if (HotkeyControl.CurrentHotkeyAvailable) { - SetHotkey(HotkeyControl.CurrentHotkey, delegate + SetHotkey(HotkeyControl.CurrentHotkey, (o, args) => { if (!Application.Current.MainWindow.IsVisible) { - _api.ShowApp(); + Application.Current.MainWindow.Visibility = Visibility.Visible; } else { - _api.HideApp(); + Application.Current.MainWindow.Visibility = Visibility.Hidden; } }); RemoveHotkey(_settings.Hotkey); diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index 2b494d3781..d6bffb07ca 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -291,9 +291,7 @@ namespace Wox.ViewModel } } - public double Left { get; set; } - - public double Top { get; set; } + public bool QueryTextSelected { get; set; } public Visibility ContextMenuVisibility @@ -308,7 +306,6 @@ namespace Wox.ViewModel { QueryText = _queryTextBeforeLoadContextMenu; ResultListBoxVisibility = Visibility.Visible; - OnCursorMovedToEnd(); } else { @@ -572,12 +569,11 @@ namespace Wox.ViewModel if (_settings.CustomPluginHotkeys == null) return; foreach (CustomPluginHotkey hotkey in _settings.CustomPluginHotkeys) { - CustomPluginHotkey hotkey1 = hotkey; - SetHotkey(hotkey.Hotkey, delegate + SetHotkey(hotkey.Hotkey, (s, e) => { if (ShouldIgnoreHotkeys()) return; - App.API.ShowApp(); - App.API.ChangeQuery(hotkey1.ActionKeyword, true); + QueryText = hotkey.ActionKeyword; + MainWindowVisibility = Visibility.Visible; }); } } @@ -585,6 +581,7 @@ namespace Wox.ViewModel private void OnHotkey(object sender, HotkeyEventArgs e) { if (ShouldIgnoreHotkeys()) return; + QueryTextSelected = true; ToggleWox(); e.Handled = true; } @@ -594,7 +591,6 @@ namespace Wox.ViewModel if (!MainWindowVisibility.IsVisible()) { MainWindowVisibility = Visibility.Visible; - OnTextBoxSelected(); } else { @@ -653,19 +649,5 @@ namespace Wox.ViewModel } #endregion - - public event EventHandler CursorMovedToEnd; - - public void OnCursorMovedToEnd() - { - CursorMovedToEnd?.Invoke(this, new EventArgs()); - } - - public event EventHandler TextBoxSelected; - - public void OnTextBoxSelected() - { - TextBoxSelected?.Invoke(this, new EventArgs()); - } } } \ No newline at end of file diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index f7d26894d9..df4d0ceb2a 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -439,7 +439,7 @@ cd "$(TargetDir)" & del /s /q *.xml - taskkill /f /fi "IMAGENAME eq Wox.exe + taskkill /f /fi "IMAGENAME eq Wox.exe"