diff --git a/QuickVSOpen/Commands/GoToMethodCommand.cs b/QuickVSOpen/Commands/GoToMethodCommand.cs index faadfe8..9047ac6 100644 --- a/QuickVSOpen/Commands/GoToMethodCommand.cs +++ b/QuickVSOpen/Commands/GoToMethodCommand.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using System.Linq; using Task = System.Threading.Tasks.Task; +using System.Windows; namespace QuickVSOpen { @@ -147,6 +148,18 @@ private void Execute(object sender, EventArgs e) if (found != null) { + if(m_openDialog != null) + { + var source = PresentationSource.FromVisual(m_openDialog.Owner); + var dpi = source?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0; + if(dpi != m_openDialog.ClosedDpi) + { + m_openDialog.AllowCloseClose = true; + m_openDialog.Close(); + m_openDialog = null; + } + } + if (m_openDialog == null) { m_openDialog = new OpenDialog(found, true, true, true); diff --git a/QuickVSOpen/Commands/OpenSolutionFileCommand.cs b/QuickVSOpen/Commands/OpenSolutionFileCommand.cs index 9468b21..61a0fb7 100644 --- a/QuickVSOpen/Commands/OpenSolutionFileCommand.cs +++ b/QuickVSOpen/Commands/OpenSolutionFileCommand.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using System.Linq; using Task = System.Threading.Tasks.Task; +using System.Windows; namespace QuickVSOpen { @@ -141,6 +142,18 @@ private void Execute(object sender, EventArgs e) } } + if (m_openDialog != null) + { + var source = PresentationSource.FromVisual(m_openDialog.Owner); + var dpi = source?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0; + if (dpi != m_openDialog.ClosedDpi) + { + m_openDialog.AllowCloseClose = true; + m_openDialog.Close(); + m_openDialog = null; + } + } + if (m_openDialog == null) { m_openDialog = new OpenDialog(m_files, true, false, true); diff --git a/QuickVSOpen/OpenDialog.xaml.cs b/QuickVSOpen/OpenDialog.xaml.cs index 587f132..1b5ea29 100644 --- a/QuickVSOpen/OpenDialog.xaml.cs +++ b/QuickVSOpen/OpenDialog.xaml.cs @@ -30,6 +30,9 @@ public partial class OpenDialog : Window public string SelectedSearchString { get; set; } bool m_handleTextChanged = true; + public double ClosedDpi { get; set; } + public bool AllowCloseClose { get; set; } = false; + public OpenDialog(ISearchable files, bool multiSelect, bool showSecondColumn, bool showFileTooltip) { InitializeComponent(); @@ -163,32 +166,23 @@ public void Init() m_resultsListView.SelectedIndex = 0; })); - Result = false; - this.ShowInTaskbar = false; + var source = PresentationSource.FromVisual(this.Owner); + var dpi = source?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0; - if (System.Windows.Application.Current.MainWindow.WindowState == System.Windows.WindowState.Maximized) - { - POINT lpPoint; - GetCursorPos(out lpPoint); + var p = this.Owner.PointToScreen(new Point(this.Owner.Width / 2, this.Owner.Height / 2)); - var screen = ScreenFromPoint1(lpPoint); + POINT lpPoint; + lpPoint.X = (int)p.X; + lpPoint.Y = (int)p.Y; - var left = screen.Bounds.Left + (screen.Bounds.Width / 2) - (this.Width / 2); - this.Left = left; + var screen = ScreenFromPoint1(lpPoint); - var top = screen.Bounds.Top + (screen.Bounds.Height / 2) - (this.Height / 2); - this.Top = top; - } - else - { - var left = (System.Windows.Application.Current.MainWindow.Left + (System.Windows.Application.Current.MainWindow.ActualWidth / 2)) - (this.Width / 2); - this.Left = left; + this.Left = screen.Bounds.Left + ((screen.Bounds.Width * dpi) / 2) - (this.Width / 2); + this.Top = screen.Bounds.Top + ((screen.Bounds.Height * dpi) / 2) - (this.Height / 2); - var top = (System.Windows.Application.Current.MainWindow.Top + (System.Windows.Application.Current.MainWindow.ActualHeight / 2)) - (this.Height / 2); - this.Top = top; - } + this.ShowInTaskbar = false; } private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) @@ -316,15 +310,22 @@ private void m_searchTextBox_KeyDown(object sender, KeyEventArgs e) private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { SelectedSearchString = m_searchTextBox.Text; - e.Cancel = true; - - Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)(arg => + + if (this.AllowCloseClose == false) { - this.Left = -1000; - this.Hide(); - - return null; - }), null); + e.Cancel = true; + + //keep track of this, not sure why but i was having problems (window would disapear) with closing the window and opening on a different dpi screen + //this lets us close the window on open if they are on different dpi and that works then + var s = PresentationSource.FromVisual(this); + this.ClosedDpi = s?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0; + + Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)(arg => + { + this.Hide(); + return null; + }), null); + } } } } diff --git a/QuickVSOpen/source.extension.vsixmanifest b/QuickVSOpen/source.extension.vsixmanifest index 4121b53..8ac0097 100644 --- a/QuickVSOpen/source.extension.vsixmanifest +++ b/QuickVSOpen/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + QuickVSOpen2022 Quickly open solution files or go to file members