mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-05-07 02:00:21 +08:00
"Pin" a viewer window
This commit is contained in:
+3
-3
@@ -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)
|
||||
@@ -18,13 +18,15 @@
|
||||
<Window.Resources>
|
||||
<converters:BooleanToResizeModeConverter x:Key="BooleanToResizeModeConverter" />
|
||||
<converters:BooleanToResizeBorderThicknessConverter x:Key="BooleanToResizeBorderThicknessConverter" />
|
||||
<converters:BooleanTrueToVisibilityCollapsedConverter x:Key="BooleanTrueToVisibilityCollapsedConverter" />
|
||||
</Window.Resources>
|
||||
<Window.ResizeMode>
|
||||
<Binding Converter="{StaticResource BooleanToResizeModeConverter}" ElementName="mainWindow"
|
||||
Path="ContextObject.CanResize" />
|
||||
</Window.ResizeMode>
|
||||
<WindowChrome.WindowChrome>
|
||||
<WindowChrome x:Name="chrome" ResizeBorderThickness="{Binding ContextObject.CanResize, Converter={StaticResource BooleanToResizeBorderThicknessConverter}, ElementName=mainWindow}"
|
||||
<WindowChrome x:Name="chrome"
|
||||
ResizeBorderThickness="{Binding ContextObject.CanResize, Converter={StaticResource BooleanToResizeBorderThicknessConverter}, ElementName=mainWindow}"
|
||||
UseAeroCaptionButtons="False" />
|
||||
</WindowChrome.WindowChrome>
|
||||
<Border x:Name="windowBorder" BorderThickness="1" BorderBrush="#FF7B7B7B">
|
||||
@@ -58,12 +60,13 @@
|
||||
<DockPanel x:Name="titlebar" Height="28" Dock="Top">
|
||||
<fa:ImageAwesome DockPanel.Dock="Right" x:Name="buttonCloseWindow" Icon="TimesCircle"
|
||||
WindowChrome.IsHitTestVisibleInChrome="True"
|
||||
Height="15" Margin="10,0" Foreground="Gray"
|
||||
Width="15" Height="15" Margin="10,0" Foreground="Gray"
|
||||
Cursor="Hand" />
|
||||
<Button x:Name="buttonOpenWith" DockPanel.Dock="Right" Content="Open with..." Height="20"
|
||||
Margin="10,0,0,0" Padding="5,0"
|
||||
Focusable="False" Cursor="Hand"
|
||||
Background="#E5EEEEEE" BorderBrush="#E59A9A9A"
|
||||
Visibility="{Binding Pinned,ElementName=mainWindow,Converter={StaticResource BooleanTrueToVisibilityCollapsedConverter}}"
|
||||
WindowChrome.IsHitTestVisibleInChrome="True" Foreground="#FF404040">
|
||||
<Button.ContentTemplate>
|
||||
<DataTemplate>
|
||||
@@ -71,6 +74,31 @@
|
||||
</DataTemplate>
|
||||
</Button.ContentTemplate>
|
||||
</Button>
|
||||
<fa:ImageAwesome DockPanel.Dock="Left" x:Name="buttonPin" Icon="ThumbTack"
|
||||
WindowChrome.IsHitTestVisibleInChrome="True"
|
||||
Width="14" Height="14" Margin="10,0"
|
||||
Cursor="Hand">
|
||||
<fa:ImageAwesome.Style>
|
||||
<Style TargetType="{x:Type fa:ImageAwesome}">
|
||||
<Setter Property="Foreground" Value="Gray" />
|
||||
<Setter Property="LayoutTransform">
|
||||
<Setter.Value>
|
||||
<RotateTransform Angle="-45" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Pinned, ElementName=mainWindow}" Value="True">
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
<Setter Property="LayoutTransform">
|
||||
<Setter.Value>
|
||||
<RotateTransform Angle="0" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</fa:ImageAwesome.Style>
|
||||
</fa:ImageAwesome>
|
||||
<!-- set grid.background colour makes it clickable -->
|
||||
<Grid x:Name="titleArea" Background="Transparent">
|
||||
<TextBlock Text="{Binding ContextObject.Title, ElementName=mainWindow}" FontSize="14"
|
||||
|
||||
@@ -16,13 +16,16 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindowTransparent.xaml
|
||||
/// </summary>
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@
|
||||
<Link>Properties\GitVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Converters\BooleanToResizeModeConverter.cs" />
|
||||
<Compile Include="Converters\BooleanToVisibilityCollapsedConverter.cs" />
|
||||
<Compile Include="Converters\BooleanTrueToVisibilityCollapsedConverter.cs" />
|
||||
<Compile Include="Converters\BooleanToResizeBorderThicknessConverter.cs" />
|
||||
<Compile Include="FocusMonitor.cs" />
|
||||
<Compile Include="Helpers\AutoStartupHelper.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();
|
||||
|
||||
Reference in New Issue
Block a user