diff --git a/QuickLook/Converters/BooleanToVisibilityCollapsedConverter.cs b/QuickLook/Converters/BooleanTrueToVisibilityCollapsedConverter.cs similarity index 85% rename from QuickLook/Converters/BooleanToVisibilityCollapsedConverter.cs rename to QuickLook/Converters/BooleanTrueToVisibilityCollapsedConverter.cs index 3bdf71f..bd3bb62 100644 --- a/QuickLook/Converters/BooleanToVisibilityCollapsedConverter.cs +++ b/QuickLook/Converters/BooleanTrueToVisibilityCollapsedConverter.cs @@ -22,16 +22,16 @@ using System.Windows.Data; namespace QuickLook.Converters { - public sealed class BooleanToVisibilityCollapsedConverter : DependencyObject, IValueConverter + public sealed class BooleanTrueToVisibilityCollapsedConverter : DependencyObject, IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) - return Visibility.Visible; + return Visibility.Collapsed; var v = (bool) value; - return v ? Visibility.Visible : Visibility.Collapsed; + return v ? Visibility.Collapsed : Visibility.Visible; } object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/QuickLook/MainWindowTransparent.xaml b/QuickLook/MainWindowTransparent.xaml index 6e37662..3d84e17 100644 --- a/QuickLook/MainWindowTransparent.xaml +++ b/QuickLook/MainWindowTransparent.xaml @@ -18,13 +18,15 @@ + - @@ -58,12 +60,13 @@ + + + + + . using System; +using System.ComponentModel; using System.Diagnostics; using System.IO; +using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; +using QuickLook.Annotations; using QuickLook.Helpers; using QuickLook.Helpers.BlurLibrary; using QuickLook.Plugin; @@ -32,8 +35,10 @@ namespace QuickLook /// /// Interaction logic for MainWindowTransparent.xaml /// - public partial class MainWindowTransparent : Window + public partial class MainWindowTransparent : Window, INotifyPropertyChanged { + private bool _pinned; + internal MainWindowTransparent() { // this object should be initialized before loading UI components, because many of which are binding to it. @@ -41,8 +46,7 @@ namespace QuickLook InitializeComponent(); - FontFamily = - new FontFamily(TranslationHelper.GetString("UI_FontFamily", failsafe: "Segoe UI")); + FontFamily = new FontFamily(TranslationHelper.GetString("UI_FontFamily", failsafe: "Segoe UI")); SourceInitialized += (sender, e) => { @@ -50,18 +54,43 @@ namespace QuickLook BlurWindow.EnableWindowBlur(this); }; + buttonPin.MouseLeftButtonUp += (sender, e) => + { + if (Pinned) return; + Pinned = true; + buttonOpenWith.Visibility = Visibility.Collapsed; + ViewWindowManager.GetInstance().ForgetCurrentWindow(); + }; + buttonCloseWindow.MouseLeftButtonUp += (sender, e) => - ViewWindowManager.GetInstance().ClosePreview(); + { + if (Pinned) + BeginClose(); + else + ViewWindowManager.GetInstance().ClosePreview(); + }; buttonOpenWith.Click += (sender, e) => ViewWindowManager.GetInstance().RunAndClosePreview(); } + public bool Pinned + { + get => _pinned; + private set + { + _pinned = value; + OnPropertyChanged(); + } + } + public string PreviewPath { get; private set; } public IViewer Plugin { get; private set; } public ContextObject ContextObject { get; private set; } + public event PropertyChangedEventHandler PropertyChanged; + internal void RunAndHide() { if (string.IsNullOrEmpty(PreviewPath)) @@ -181,10 +210,8 @@ namespace QuickLook buttonOpenWith.Content = isExe == null ? Directory.Exists(PreviewPath) - ? string.Format(TranslationHelper.GetString("MW_BrowseFolder"), - Path.GetFileName(PreviewPath)) - : string.Format(TranslationHelper.GetString("MW_Open"), - Path.GetFileName(PreviewPath)) + ? string.Format(TranslationHelper.GetString("MW_BrowseFolder"), Path.GetFileName(PreviewPath)) + : string.Format(TranslationHelper.GetString("MW_Open"), Path.GetFileName(PreviewPath)) : isExe == true ? string.Format(TranslationHelper.GetString("MW_Run"), appFriendlyName) : string.Format(TranslationHelper.GetString("MW_OpenWith"), appFriendlyName); @@ -202,5 +229,20 @@ namespace QuickLook ProcessHelper.PerformAggressiveGC(); } + + internal void BeginClose() + { + UnloadPlugin(); + + Close(); + + ProcessHelper.PerformAggressiveGC(); + } + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } } \ No newline at end of file diff --git a/QuickLook/QuickLook.csproj b/QuickLook/QuickLook.csproj index 9b7f2b3..9d3542a 100644 --- a/QuickLook/QuickLook.csproj +++ b/QuickLook/QuickLook.csproj @@ -107,7 +107,7 @@ Properties\GitVersion.cs - + diff --git a/QuickLook/ViewWindowManager.cs b/QuickLook/ViewWindowManager.cs index 05e6ae6..acc3ccf 100644 --- a/QuickLook/ViewWindowManager.cs +++ b/QuickLook/ViewWindowManager.cs @@ -31,18 +31,18 @@ namespace QuickLook { private static ViewWindowManager _instance; - private readonly MainWindowNoTransparent _viewWindowNoTransparent; - private readonly MainWindowTransparent _viewWindowTransparentTransparent; + private MainWindowNoTransparent _viewWindowNoTransparent; + private MainWindowTransparent _viewWindowTransparent; private MainWindowTransparent _currentMainWindow; private string _path = string.Empty; internal ViewWindowManager() { - _viewWindowTransparentTransparent = new MainWindowTransparent(); + _viewWindowTransparent = new MainWindowTransparent(); _viewWindowNoTransparent = new MainWindowNoTransparent(); - _currentMainWindow = _viewWindowTransparentTransparent; + _currentMainWindow = _viewWindowTransparent; } public void Dispose() @@ -172,6 +172,18 @@ namespace QuickLook FocusMonitor.GetInstance().Heartbeat -= SwitchPreviewRemoteInvoke; } } + + internal void ForgetCurrentWindow() + { + StopFocusMonitor(); + + if (ReferenceEquals(_currentMainWindow, _viewWindowTransparent)) + _viewWindowTransparent=new MainWindowTransparent(); + else + _viewWindowNoTransparent = new MainWindowNoTransparent(); + + _currentMainWindow = _viewWindowTransparent; + } internal bool InvokeViewer(string path = null, bool closeIfSame = false) { @@ -206,7 +218,7 @@ namespace QuickLook // switch window var oldWindow = _currentMainWindow; _currentMainWindow = matchedPlugin.AllowsTransparency - ? _viewWindowTransparentTransparent + ? _viewWindowTransparent : _viewWindowNoTransparent; if (!ReferenceEquals(oldWindow, _currentMainWindow)) oldWindow.BeginHide();