forked from QL-Win/QuickLook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewerWindow.xaml.cs
More file actions
183 lines (152 loc) · 6.21 KB
/
ViewerWindow.xaml.cs
File metadata and controls
183 lines (152 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright © 2017 Paddy Xu
//
// This file is part of QuickLook program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using QuickLook.Helpers;
using Brush = System.Windows.Media.Brush;
using FontFamily = System.Windows.Media.FontFamily;
using Size = System.Windows.Size;
namespace QuickLook
{
/// <summary>
/// Interaction logic for ViewerWindow.xaml
/// </summary>
public partial class ViewerWindow : Window
{
private Size _customWindowSize = Size.Empty;
private bool _ignoreNextWindowSizeChange;
private string _path = string.Empty;
internal ViewerWindow()
{
// this object should be initialized before loading UI components, because many of which are binding to it.
ContextObject = new ContextObject();
ContextObject.PropertyChanged += ContextObject_PropertyChanged;
InitializeComponent();
Icon = (App.IsWin10 ? Properties.Resources.app_white_png : Properties.Resources.app_png).ToBitmapSource();
FontFamily = new FontFamily(TranslationHelper.Get("UI_FontFamily", failsafe: "Segoe UI"));
SizeChanged += SaveWindowSizeOnSizeChanged;
StateChanged += (sender, e) => _ignoreNextWindowSizeChange = true;
windowFrameContainer.PreviewMouseMove += ShowWindowCaptionContainer;
Topmost = SettingHelper.Get("Topmost", false);
buttonTop.Tag = Topmost ? "Top" : "Auto";
buttonTop.Click += (sender, e) =>
{
Topmost = !Topmost;
SettingHelper.Set("Topmost", Topmost);
buttonTop.Tag = Topmost ? "Top" : "Auto";
};
buttonPin.Click += (sender, e) =>
{
if (Pinned)
return;
ViewWindowManager.GetInstance().ForgetCurrentWindow();
};
buttonCloseWindow.Click += (sender, e) =>
{
if (Pinned)
Close();
else
ViewWindowManager.GetInstance().ClosePreview();
};
buttonOpen.Click += (sender, e) =>
{
if (Pinned)
RunAndClose();
else
ViewWindowManager.GetInstance().RunAndClosePreview();
};
buttonWindowStatus.Click += (sender, e) =>
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);
// Set UI translations
buttonTop.ToolTip = TranslationHelper.Get("MW_StayTop");
buttonPin.ToolTip = TranslationHelper.Get("MW_PreventClosing");
buttonOpenWith.ToolTip = TranslationHelper.Get("MW_OpenWithMenu");
buttonShare.ToolTip = TranslationHelper.Get("MW_Share");
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
WindowHelper.RemoveWindowControls(this);
if (SettingHelper.Get("UseTransparency", true)
&& SystemParameters.IsGlassEnabled
&& !App.IsGPUInBlacklist)
{
if (App.IsWin11)
{
if (Environment.OSVersion.Version >= new Version(10, 0, 22523))
{
WindowHelper.EnableBackdropMicaBlur(this, CurrentTheme == Themes.Dark);
}
else
{
WindowHelper.EnableMicaBlur(this, CurrentTheme == Themes.Dark);
}
}
else if (App.IsWin10)
{
WindowHelper.EnableBlur(this);
}
else
{
Background = (Brush)FindResource("MainWindowBackgroundNoTransparent");
}
}
else
{
Background = (Brush)FindResource("MainWindowBackgroundNoTransparent");
}
}
private void SaveWindowSizeOnSizeChanged(object sender, SizeChangedEventArgs e)
{
// first shown?
if (e.PreviousSize == new Size(0, 0))
return;
// resize when switching preview?
if (_ignoreNextWindowSizeChange)
{
_ignoreNextWindowSizeChange = false;
return;
}
// by user?
_customWindowSize = new Size(Width, Height);
}
private void ShowWindowCaptionContainer(object sender, MouseEventArgs e)
{
var show = (Storyboard) windowCaptionContainer.FindResource("ShowCaptionContainerStoryboard");
if (windowCaptionContainer.Opacity == 0 || windowCaptionContainer.Opacity == 1)
show.Begin();
}
private void AutoHideCaptionContainer(object sender, EventArgs e)
{
if (!ContextObject.TitlebarAutoHide)
return;
if (!ContextObject.TitlebarOverlap)
return;
if (windowCaptionContainer.IsMouseOver)
return;
var hide = (Storyboard) windowCaptionContainer.FindResource("HideCaptionContainerStoryboard");
hide.Begin();
}
}
}