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 c5d45c6b44
commit 6274b617f4
2 changed files with 30 additions and 14 deletions

View File

@ -34,9 +34,11 @@ namespace Wox
private void OnClosing(object sender, CancelEventArgs e)
{
UserSettingStorage.Instance.WindowLeft = Left;
UserSettingStorage.Instance.WindowTop = Top;
UserSettingStorage.Instance.Save();
UserSettingStorage.Instance.WindowLeft = Left;
UserSettingStorage.Instance.WindowTop = Top;
UserSettingStorage.Instance.Save();
e.Cancel = true;
}
@ -63,6 +65,15 @@ namespace Wox
{
Activate();
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()
{
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 dipPoint = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
UserSettingStorage.Instance.WindowLeft = (dipPoint.X - ActualWidth) / 2;
return UserSettingStorage.Instance.WindowLeft;
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 (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 dipPoint = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
UserSettingStorage.Instance.WindowTop = (dipPoint.Y - QueryTextBox.ActualHeight) / 4;
return UserSettingStorage.Instance.WindowTop;
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 CheckUpdate()

View File

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