diff --git a/QuickLook/ViewWindowManager.cs b/QuickLook/ViewWindowManager.cs index 8ff88ab..992ee4b 100644 --- a/QuickLook/ViewWindowManager.cs +++ b/QuickLook/ViewWindowManager.cs @@ -40,7 +40,6 @@ namespace QuickLook public void Dispose() { StopFocusMonitor(); - ClosePreview(); } public void RunAndClosePreview() @@ -96,7 +95,15 @@ namespace QuickLook { StopFocusMonitor(); - _viewerWindow = new ViewerWindow(); + var newWindow = new ViewerWindow + { + Top = _viewerWindow.Top, + Left = _viewerWindow.Left, + Width = _viewerWindow.Width, + Height = _viewerWindow.Height + }; + + _viewerWindow = newWindow; } public void SwitchPreview(string path) diff --git a/QuickLook/ViewerWindow.Actions.cs b/QuickLook/ViewerWindow.Actions.cs index d5579bf..7d27303 100644 --- a/QuickLook/ViewerWindow.Actions.cs +++ b/QuickLook/ViewerWindow.Actions.cs @@ -86,25 +86,10 @@ namespace QuickLook size.Width = Math.Max(size.Width, MinWidth); size.Height = Math.Max(size.Height, MinHeight); - if (!IsLoaded) - { - // if the window is not loaded yet, just leave the problem to WPF - Width = size.Width; - Height = size.Height; - WindowStartupLocation = WindowStartupLocation.CenterScreen; - Dispatcher.BeginInvoke(new Action(this.BringToFront), DispatcherPriority.Render); - - return; - } - - // is the window is now now maximized, do not move it + // if the window is now now maximized, do not move it if (WindowState == WindowState.Maximized) return; - // if this is a new window, place it to top - if (Visibility != Visibility.Visible) - this.BringToFront(); - var screen = WindowHelper.GetCurrentWindowRect(); // otherwise, resize it and place it to the old window center. @@ -120,7 +105,22 @@ namespace QuickLook newLeft = newLeft + size.Width > screen.Right ? screen.Right - size.Width : newLeft; // right newTop = newTop + size.Height > screen.Bottom ? screen.Bottom - size.Height : newTop; // bottom - this.MoveWindow(newLeft, newTop, size.Width, size.Height); + if (IsLoaded) + { + this.MoveWindow(newLeft, newTop, size.Width, size.Height); + } + else + { + // MoveWindow does not work for new windows + Width = size.Width; + Height = size.Height; + Left = newLeft; + Top = newTop; + if (double.IsNaN(Left) || double.IsNaN(Top)) // first time showing + WindowStartupLocation = WindowStartupLocation.CenterScreen; + + Dispatcher.BeginInvoke(new Action(this.BringToFront), DispatcherPriority.Render); + } } internal void UnloadPlugin() @@ -143,6 +143,7 @@ namespace QuickLook { Debug.WriteLine(e); } + Plugin = null; _path = string.Empty; @@ -217,12 +218,14 @@ namespace QuickLook AddToInlines("MW_BrowseFolder", Path.GetFileName(_path)); return; } + var isExe = FileHelper.IsExecutable(_path, out var appFriendlyName); if (isExe) { AddToInlines("MW_Run", appFriendlyName); return; } + // not an exe var found = FileHelper.GetAssocApplication(_path, out appFriendlyName); if (found) @@ -230,6 +233,7 @@ namespace QuickLook AddToInlines("MW_OpenWith", appFriendlyName); return; } + // assoc not found AddToInlines("MW_Open", Path.GetFileName(_path)); diff --git a/QuickLook/ViewerWindow.xaml b/QuickLook/ViewerWindow.xaml index 079c907..4eaefd5 100644 --- a/QuickLook/ViewerWindow.xaml +++ b/QuickLook/ViewerWindow.xaml @@ -11,7 +11,6 @@ UseLayoutRounding="True" d:DesignWidth="624" d:DesignHeight="700" MinWidth="400" MinHeight="200" - WindowStartupLocation="CenterScreen" Focusable="False" BorderBrush="{DynamicResource CaptionBackground}" Background="{DynamicResource MainWindowBackground}"