mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-15 04:39:07 +00:00
fix window resize when switching; fix invoke
This commit is contained in:
@@ -10,7 +10,7 @@ namespace QuickLook.Converters
|
|||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return Visibility.Visible;
|
return 0;
|
||||||
|
|
||||||
var v = (bool) value;
|
var v = (bool) value;
|
||||||
|
|
||||||
|
25
QuickLook/Converters/BooleanToResizeModeConverter.cs
Normal file
25
QuickLook/Converters/BooleanToResizeModeConverter.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace QuickLook.Converters
|
||||||
|
{
|
||||||
|
public sealed class BooleanToResizeModeConverter : DependencyObject, IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
return ResizeMode.CanResize;
|
||||||
|
|
||||||
|
var v = (bool) value;
|
||||||
|
|
||||||
|
return v ? ResizeMode.CanResize : ResizeMode.NoResize;
|
||||||
|
}
|
||||||
|
|
||||||
|
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -17,8 +17,13 @@
|
|||||||
ShowActivated="False" ShowInTaskbar="False"
|
ShowActivated="False" ShowInTaskbar="False"
|
||||||
FontFamily="Segoe UI,Microsoft Yahei UI">
|
FontFamily="Segoe UI,Microsoft Yahei UI">
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
|
<converters:BooleanToResizeModeConverter x:Key="BooleanToResizeModeConverter" />
|
||||||
<converters:BooleanToResizeBorderThicknessConverter x:Key="BooleanToResizeBorderThicknessConverter" />
|
<converters:BooleanToResizeBorderThicknessConverter x:Key="BooleanToResizeBorderThicknessConverter" />
|
||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
|
<Window.ResizeMode>
|
||||||
|
<Binding Converter="{StaticResource BooleanToResizeModeConverter}" ElementName="mainWindow"
|
||||||
|
Path="ContextObject.CanResize" />
|
||||||
|
</Window.ResizeMode>
|
||||||
<WindowChrome.WindowChrome>
|
<WindowChrome.WindowChrome>
|
||||||
<WindowChrome CaptionHeight="{Binding Height, ElementName=titlebar}"
|
<WindowChrome CaptionHeight="{Binding Height, ElementName=titlebar}"
|
||||||
ResizeBorderThickness="{Binding ContextObject.CanResize, Converter={StaticResource BooleanToResizeBorderThicknessConverter}, ElementName=mainWindow}"
|
ResizeBorderThickness="{Binding ContextObject.CanResize, Converter={StaticResource BooleanToResizeBorderThicknessConverter}, ElementName=mainWindow}"
|
||||||
|
@@ -55,24 +55,6 @@ namespace QuickLook
|
|||||||
BeginHide(true);
|
BeginHide(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private new void Show()
|
|
||||||
{
|
|
||||||
// revert UI changes
|
|
||||||
ContextObject.IsBusy = true;
|
|
||||||
|
|
||||||
var newHeight = ContextObject.PreferredSize.Height + titlebar.Height + windowBorder.BorderThickness.Top +
|
|
||||||
windowBorder.BorderThickness.Bottom;
|
|
||||||
var newWidth = ContextObject.PreferredSize.Width + windowBorder.BorderThickness.Left +
|
|
||||||
windowBorder.BorderThickness.Right;
|
|
||||||
|
|
||||||
ResizeAndCenter(new Size(newWidth, newHeight));
|
|
||||||
|
|
||||||
base.Show();
|
|
||||||
|
|
||||||
//if (!ContextObject.CanFocus)
|
|
||||||
// WindowHelper.SetNoactivate(new WindowInteropHelper(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ResizeAndCenter(Size size)
|
private void ResizeAndCenter(Size size)
|
||||||
{
|
{
|
||||||
if (!IsLoaded)
|
if (!IsLoaded)
|
||||||
@@ -103,21 +85,6 @@ namespace QuickLook
|
|||||||
ContextObject.ViewerPlugin?.Cleanup();
|
ContextObject.ViewerPlugin?.Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private new void Hide()
|
|
||||||
{
|
|
||||||
UnloadPlugin();
|
|
||||||
ContextObject.Reset();
|
|
||||||
|
|
||||||
GC.Collect();
|
|
||||||
|
|
||||||
// revert UI changes
|
|
||||||
ContextObject.IsBusy = true;
|
|
||||||
|
|
||||||
base.Hide();
|
|
||||||
//Left -= 10000;
|
|
||||||
//Dispatcher.Delay(100, _ => base.Hide());
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void BeginShow(IViewer matchedPlugin, string path)
|
internal void BeginShow(IViewer matchedPlugin, string path)
|
||||||
{
|
{
|
||||||
ContextObject.CurrentContentContainer = container;
|
ContextObject.CurrentContentContainer = container;
|
||||||
@@ -129,8 +96,20 @@ namespace QuickLook
|
|||||||
|
|
||||||
SetOpenWithButtonAndPath(path);
|
SetOpenWithButtonAndPath(path);
|
||||||
|
|
||||||
|
// revert UI changes
|
||||||
|
ContextObject.IsBusy = true;
|
||||||
|
|
||||||
|
var newHeight = ContextObject.PreferredSize.Height + titlebar.Height + windowBorder.BorderThickness.Top +
|
||||||
|
windowBorder.BorderThickness.Bottom;
|
||||||
|
var newWidth = ContextObject.PreferredSize.Width + windowBorder.BorderThickness.Left +
|
||||||
|
windowBorder.BorderThickness.Right;
|
||||||
|
|
||||||
|
ResizeAndCenter(new Size(newWidth, newHeight));
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
|
//WindowHelper.SetActivate(new WindowInteropHelper(this), ContextObject.CanFocus);
|
||||||
|
|
||||||
// load plugin, do not block UI
|
// load plugin, do not block UI
|
||||||
Exception thrown = null;
|
Exception thrown = null;
|
||||||
Dispatcher.BeginInvoke(new Action(() =>
|
Dispatcher.BeginInvoke(new Action(() =>
|
||||||
@@ -159,9 +138,9 @@ namespace QuickLook
|
|||||||
buttonOpenWith.Content = isExe == true ? $"Run {appFriendlyName}" : $"Open with {appFriendlyName}";
|
buttonOpenWith.Content = isExe == true ? $"Run {appFriendlyName}" : $"Open with {appFriendlyName}";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool BeginHide(bool quit = false)
|
internal bool BeginHide(bool quitIfViewer = false, bool disposePluginOnly = false)
|
||||||
{
|
{
|
||||||
if (quit && App.RunningAsViewer)
|
if (quitIfViewer && App.RunningAsViewer)
|
||||||
{
|
{
|
||||||
Application.Current.Shutdown();
|
Application.Current.Shutdown();
|
||||||
return true;
|
return true;
|
||||||
@@ -170,9 +149,20 @@ namespace QuickLook
|
|||||||
if (Visibility != Visibility.Visible)
|
if (Visibility != Visibility.Visible)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Hide();
|
UnloadPlugin();
|
||||||
|
ContextObject.Reset();
|
||||||
|
GC.Collect();
|
||||||
|
|
||||||
return true;
|
// revert UI changes
|
||||||
|
ContextObject.IsBusy = true;
|
||||||
|
|
||||||
|
if (!disposePluginOnly)
|
||||||
|
{
|
||||||
|
Hide();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -80,6 +80,7 @@
|
|||||||
<Compile Include="..\GitVersion.cs">
|
<Compile Include="..\GitVersion.cs">
|
||||||
<Link>Properties\GitVersion.cs</Link>
|
<Link>Properties\GitVersion.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Converters\BooleanToResizeModeConverter.cs" />
|
||||||
<Compile Include="Converters\BooleanToVisibilityCollapsedConverter.cs" />
|
<Compile Include="Converters\BooleanToVisibilityCollapsedConverter.cs" />
|
||||||
<Compile Include="Converters\BooleanToResizeBorderThicknessConverter.cs" />
|
<Compile Include="Converters\BooleanToResizeBorderThicknessConverter.cs" />
|
||||||
<Compile Include="Helpers\AutoStartupHelper.cs" />
|
<Compile Include="Helpers\AutoStartupHelper.cs" />
|
||||||
|
@@ -32,14 +32,15 @@ namespace QuickLook
|
|||||||
// do we need switch to another file?
|
// do we need switch to another file?
|
||||||
var replaceView = key == Keys.Up || key == Keys.Down || key == Keys.Left || key == Keys.Right;
|
var replaceView = key == Keys.Up || key == Keys.Down || key == Keys.Left || key == Keys.Right;
|
||||||
|
|
||||||
if (replaceView && _currentMainWindow.IsLoaded && _currentMainWindow.Visibility != Visibility.Visible)
|
if (replaceView && _currentMainWindow.Visibility != Visibility.Visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!WindowHelper.IsFocusedControlExplorerItem())
|
if (!WindowHelper.IsFocusedControlExplorerItem())
|
||||||
if (!WindowHelper.IsFocusedWindowSelf())
|
if (replaceView || !WindowHelper.IsFocusedWindowSelf())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!replaceView && _currentMainWindow.BeginHide())
|
// should the window be closed (replaceView == false), return without showing new one
|
||||||
|
if (_currentMainWindow.BeginHide(disposePluginOnly: replaceView))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var path = GetCurrentSelection();
|
var path = GetCurrentSelection();
|
||||||
|
Reference in New Issue
Block a user