Skip to content

Commit

Permalink
Expose the ViewWindow to ContextObject
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Dec 31, 2024
1 parent 3a1a74d commit 190ab5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion QuickLook.Common
23 changes: 14 additions & 9 deletions QuickLook/ViewerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using Wpf.Ui.Violeta.Controls;
using Brush = System.Windows.Media.Brush;
using FontFamily = System.Windows.Media.FontFamily;
using Size = System.Windows.Size;
Expand All @@ -41,7 +42,7 @@ public partial class ViewerWindow : Window
internal ViewerWindow()
{
// this object should be initialized before loading UI components, because many of which are binding to it.
ContextObject = new ContextObject();
ContextObject = new ContextObject() { Source = this };

ContextObject.PropertyChanged += ContextObject_PropertyChanged;

Expand All @@ -53,49 +54,53 @@ internal ViewerWindow()

SizeChanged += SaveWindowSizeOnSizeChanged;

StateChanged += (sender, e) => _ignoreNextWindowSizeChange = true;
StateChanged += (_, _) => _ignoreNextWindowSizeChange = true;

windowFrameContainer.PreviewMouseMove += ShowWindowCaptionContainer;

Topmost = SettingHelper.Get("Topmost", false);
buttonTop.Tag = Topmost ? "Top" : "Auto";

buttonTop.Click += (sender, e) =>
buttonTop.Click += (_, _) =>
{
Topmost = !Topmost;
SettingHelper.Set("Topmost", Topmost);
buttonTop.Tag = Topmost ? "Top" : "Auto";
};

buttonPin.Click += (sender, e) =>
buttonPin.Click += (_, _) =>
{
if (Pinned)
{
TranslationHelper.Get("Icon_Quit");
Toast.Information("Cancellation of Prevent Closing is not supported");
return;
}

ViewWindowManager.GetInstance().ForgetCurrentWindow();
};

buttonCloseWindow.Click += (sender, e) =>
buttonCloseWindow.Click += (_, _) =>
{
if (Pinned)
Close();
else
ViewWindowManager.GetInstance().ClosePreview();
};

buttonOpen.Click += (sender, e) =>
buttonOpen.Click += (_, _) =>
{
if (Pinned)
RunAndClose();
else
ViewWindowManager.GetInstance().RunAndClosePreview();
};

buttonWindowStatus.Click += (sender, e) =>
buttonWindowStatus.Click += (_, _) =>
WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;

buttonShare.Click += (sender, e) => ShareHelper.Share(_path, this);
buttonOpenWith.Click += (sender, e) => ShareHelper.Share(_path, this, true);
buttonShare.Click += (_, _) => ShareHelper.Share(_path, this);
buttonOpenWith.Click += (_, _) => ShareHelper.Share(_path, this, true);

// Set UI translations
buttonTop.ToolTip = TranslationHelper.Get("MW_StayTop");
Expand Down

0 comments on commit 190ab5f

Please sign in to comment.