diff --git a/Wox.Core/UserSettings/UserSettingStorage.cs b/Wox.Core/UserSettings/UserSettingStorage.cs index ff2cc107ac..79f17f86f3 100644 --- a/Wox.Core/UserSettings/UserSettingStorage.cs +++ b/Wox.Core/UserSettings/UserSettingStorage.cs @@ -83,6 +83,9 @@ namespace Wox.Core.UserSettings [JsonProperty] public bool HideWhenDeactive { get; set; } + [JsonProperty] + public bool RememberLastLaunchLocation { get; set; } + [JsonProperty] public string ProxyServer { get; set; } @@ -131,6 +134,7 @@ namespace Wox.Core.UserSettings LeaveCmdOpen = false; HideWhenDeactive = false; CustomPluginHotkeys = new List(); + RememberLastLaunchLocation = false; return this; } diff --git a/Wox/Languages/en.xaml b/Wox/Languages/en.xaml index aaa5953d37..7d6b10bf31 100644 --- a/Wox/Languages/en.xaml +++ b/Wox/Languages/en.xaml @@ -9,7 +9,6 @@ Cancel topmost in this query Execute query:{0} Last execute time:{0} - Wox Settings @@ -17,8 +16,10 @@ Start Wox on system startup Hide Wox when loses focus Don't show upgrade msg if new version available + Remember last launch location Language + Plugin Browse more plugins diff --git a/Wox/Languages/zh-cn.xaml b/Wox/Languages/zh-cn.xaml index 7b2d632de9..48b5fe77a5 100644 --- a/Wox/Languages/zh-cn.xaml +++ b/Wox/Languages/zh-cn.xaml @@ -16,6 +16,7 @@ 开机启动 失去焦点时自动隐藏Wox 不显示新版本提示 + 记住上次启动位置 语言 diff --git a/Wox/Languages/zh-tw.xaml b/Wox/Languages/zh-tw.xaml index 1e3d40e829..6f97aa2b8c 100644 --- a/Wox/Languages/zh-tw.xaml +++ b/Wox/Languages/zh-tw.xaml @@ -16,6 +16,7 @@ 開機啟動 失去焦點時自動隱藏Wox 不顯示新版本提示 + 记住上次启动位置 語言 diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 9b785e7f9f..bea24ac6d2 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -262,19 +262,8 @@ namespace Wox private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { - if (UserSettingStorage.Instance.WindowLeft == 0 - && UserSettingStorage.Instance.WindowTop == 0) - { - Left = UserSettingStorage.Instance.WindowLeft - = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2; - Top = UserSettingStorage.Instance.WindowTop - = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 5; - } - else - { - Left = UserSettingStorage.Instance.WindowLeft; - Top = UserSettingStorage.Instance.WindowTop; - } + Left = GetWindowsLeft(); + Top = GetWindowsTop(); InitProgressbarAnimation(); WindowIntelopHelper.DisableControlBox(this); @@ -282,6 +271,39 @@ namespace Wox new ShellContextMenuManager().GetContextMenus(@"c:\Windows\write.exe"); } + private double GetWindowsLeft() + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + if (UserSettingStorage.Instance.RememberLastLaunchLocation) + { + var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight)); + var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth); + UserSettingStorage.Instance.WindowLeft = (screen.WorkingArea.Width - ActualWidth) * coordX + screen.WorkingArea.Left; + } + else + { + UserSettingStorage.Instance.WindowLeft = (screen.WorkingArea.Width - ActualWidth) / 2 + screen.WorkingArea.Left; + } + + return UserSettingStorage.Instance.WindowLeft; + } + + private double GetWindowsTop() + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + if (UserSettingStorage.Instance.RememberLastLaunchLocation) + { + var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight)); + var coordY = (Top - origScreen.WorkingArea.Top) / (origScreen.WorkingArea.Height - ActualHeight); + UserSettingStorage.Instance.WindowTop = (screen.WorkingArea.Height - ActualHeight) * coordY + screen.WorkingArea.Top; + } + else + { + UserSettingStorage.Instance.WindowTop = (screen.WorkingArea.Height - ActualHeight) / 4 + screen.WorkingArea.Top; + } + return UserSettingStorage.Instance.WindowTop; + } + private void CheckUpdate() { UpdaterManager.Instance.PrepareUpdateReady += OnPrepareUpdateReady; @@ -454,6 +476,7 @@ namespace Wox { QueryHistoryStorage.Instance.Reset(); } + private int GetSearchDelay(string query) { if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantQuery(query)) @@ -506,15 +529,8 @@ namespace Wox private void ShowWox(bool selectAll = true) { UserSettingStorage.Instance.IncreaseActivateTimes(); - if (!double.IsNaN(Left) && !double.IsNaN(Top)) - { - var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight)); - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth); - var coordY = (Top - origScreen.WorkingArea.Top) / (origScreen.WorkingArea.Height - ActualHeight); - Left = (screen.WorkingArea.Width - ActualWidth) * coordX + screen.WorkingArea.Left; - Top = (screen.WorkingArea.Height - ActualHeight) * coordY + screen.WorkingArea.Top; - } + Left = GetWindowsLeft(); + Top = GetWindowsTop(); Show(); Activate(); diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 29043715d4..66d0f1cdd6 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -31,6 +31,9 @@ + + + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 019f80593e..fd4de93bee 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -62,6 +62,18 @@ namespace Wox UserSettingStorage.Instance.Save(); }; + cbRememberLastLocation.Checked += (o, e) => + { + UserSettingStorage.Instance.RememberLastLaunchLocation = true; + UserSettingStorage.Instance.Save(); + }; + + cbRememberLastLocation.Unchecked += (o, e) => + { + UserSettingStorage.Instance.RememberLastLaunchLocation = false; + UserSettingStorage.Instance.Save(); + }; + cbDontPromptUpdateMsg.Checked += (o, e) => { UserSettingStorage.Instance.DontPromptUpdateMsg = true; @@ -77,6 +89,7 @@ namespace Wox cbStartWithWindows.IsChecked = CheckApplicationIsStartupWithWindow(); cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive; cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg; + cbRememberLastLocation.IsChecked = UserSettingStorage.Instance.RememberLastLaunchLocation; LoadLanguages();