Fix position

1. Fix "Remember launch location", this was introduced since e7aa6022.
Fix #511
2. Fix opening position ( #510 ), bug introduced from PR #494 (commit e7aa602)
This commit is contained in:
bao-qian
2016-03-25 02:38:10 +00:00
parent d6f9fddc94
commit fbc6f78cb5
2 changed files with 30 additions and 14 deletions

View File

@@ -34,9 +34,11 @@ namespace Wox
private void OnClosing(object sender, CancelEventArgs e) private void OnClosing(object sender, CancelEventArgs e)
{ {
UserSettingStorage.Instance.WindowLeft = Left;
UserSettingStorage.Instance.WindowTop = Top; UserSettingStorage.Instance.WindowLeft = Left;
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.WindowTop = Top;
UserSettingStorage.Instance.Save();
e.Cancel = true; e.Cancel = true;
} }
@@ -63,6 +65,15 @@ namespace Wox
{ {
Activate(); Activate();
QueryTextBox.Focus(); QueryTextBox.Focus();
Left = GetWindowsLeft();
Top = GetWindowsTop();
UserSettingStorage.Instance.IncreaseActivateTimes();
}
else
{
UserSettingStorage.Instance.WindowLeft = Left;
UserSettingStorage.Instance.WindowTop = Top;
UserSettingStorage.Instance.Save();
} }
}; };
@@ -73,22 +84,30 @@ namespace Wox
private double GetWindowsLeft() private double GetWindowsLeft()
{ {
if (UserSettingStorage.Instance.RememberLastLaunchLocation) return UserSettingStorage.Instance.WindowLeft; if (UserSettingStorage.Instance.RememberLastLaunchLocation)
{
return UserSettingStorage.Instance.WindowLeft;
}
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
var dipPoint = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
UserSettingStorage.Instance.WindowLeft = (dipPoint.X - ActualWidth) / 2; var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
return UserSettingStorage.Instance.WindowLeft; var left = (dip2.X - ActualWidth) / 2 + dip1.X;
return left;
} }
private double GetWindowsTop() private double GetWindowsTop()
{ {
if (UserSettingStorage.Instance.RememberLastLaunchLocation) return UserSettingStorage.Instance.WindowTop; if (UserSettingStorage.Instance.RememberLastLaunchLocation)
{
return UserSettingStorage.Instance.WindowTop;
}
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
var dipPoint = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
UserSettingStorage.Instance.WindowTop = (dipPoint.Y - QueryTextBox.ActualHeight) / 4; var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
return UserSettingStorage.Instance.WindowTop; var top = (dip2.Y - ActualHeight) / 4 + dip1.Y;
return top;
} }
private void CheckUpdate() private void CheckUpdate()

View File

@@ -187,14 +187,11 @@ namespace Wox
private void HideWox() private void HideWox()
{ {
UserSettingStorage.Instance.WindowLeft = MainVM.Left;
UserSettingStorage.Instance.WindowTop = MainVM.Top;
MainVM.MainWindowVisibility = Visibility.Collapsed; MainVM.MainWindowVisibility = Visibility.Collapsed;
} }
private void ShowWox(bool selectAll = true) private void ShowWox(bool selectAll = true)
{ {
UserSettingStorage.Instance.IncreaseActivateTimes();
MainVM.MainWindowVisibility = Visibility.Visible; MainVM.MainWindowVisibility = Visibility.Visible;
MainVM.OnTextBoxSelected(); MainVM.OnTextBoxSelected();
} }