-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathContextObject.cs
251 lines (223 loc) · 6.52 KB
/
ContextObject.cs
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// 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 QuickLook.Common.Annotations;
using QuickLook.Common.Helpers;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
namespace QuickLook.Common.Plugin;
/// <summary>
/// A runtime object which allows interaction between this plugin and QuickLook.
/// </summary>
public class ContextObject : INotifyPropertyChanged
{
private bool _canResize = true;
private bool _fullWindowDragging;
private bool _isBusy;
private string _title = string.Empty;
private bool _titlebarAutoHide;
private bool _titlebarBlurVisibility;
private bool _titlebarColourVisibility = true;
private bool _titlebarOverlap;
private Themes _theme = Themes.None;
private object _viewerContent;
private string _colorProfileName = null;
/// <summary>
/// Get the instance of Viewer window.
/// </summary>
public object Source { get; set; }
/// <summary>
/// Get or set the title of Viewer window.
/// </summary>
public string Title
{
get => _title;
set
{
_title = value;
OnPropertyChanged();
}
}
/// <summary>
/// Get or set the viewer content control.
/// </summary>
public object ViewerContent
{
get => _viewerContent;
set
{
_viewerContent = value;
OnPropertyChanged();
}
}
/// <summary>
/// Show or hide the busy indicator icon.
/// </summary>
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged();
}
}
/// <summary>
/// Set the exact size you want.
/// </summary>
public Size PreferredSize { get; set; } = new Size { Width = 800, Height = 600 };
/// <summary>
/// Set whether user are allowed to resize the viewer window.
/// </summary>
public bool CanResize
{
get => _canResize;
set
{
_canResize = value;
OnPropertyChanged();
}
}
/// <summary>
/// Set whether the full viewer window can be used for mouse dragging.
/// </summary>
public bool FullWindowDragging
{
get => _fullWindowDragging;
set
{
_fullWindowDragging = value;
OnPropertyChanged();
}
}
/// <summary>
/// Set whether the viewer content is overlapped by the title bar
/// </summary>
public bool TitlebarOverlap
{
get => _titlebarOverlap;
set
{
_titlebarOverlap = value;
OnPropertyChanged();
}
}
/// <summary>
/// Set whether the title bar shows a blurred background
/// </summary>
public bool TitlebarBlurVisibility
{
get => _titlebarBlurVisibility;
set
{
if (value == _titlebarBlurVisibility) return;
_titlebarBlurVisibility = value;
OnPropertyChanged();
}
}
/// <summary>
/// Set whether the title bar shows a colour overlay
/// </summary>
public bool TitlebarColourVisibility
{
get => _titlebarColourVisibility;
set
{
if (value == _titlebarColourVisibility) return;
_titlebarColourVisibility = value;
OnPropertyChanged();
}
}
/// <summary>
/// Should the titlebar hides itself after a short period of inactivity?
/// </summary>
public bool TitlebarAutoHide
{
get => _titlebarAutoHide;
set
{
if (value == _titlebarAutoHide) return;
_titlebarAutoHide = value;
OnPropertyChanged();
}
}
/// <summary>
/// Switch to dark theme?
/// </summary>
public Themes Theme
{
get => _theme;
set
{
_theme = value;
OnPropertyChanged();
}
}
/// <summary>
/// The color profile of the monitor that will host the preview window
/// </summary>
public string ColorProfileName
{
get => _colorProfileName;
set
{
_colorProfileName = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Set the size of viewer window, scale or shrink to fit (to screen resolution).
/// The window can take maximum (maxRatio*resolution) space.
/// </summary>
/// <param name="size">The desired size.</param>
/// <param name="maxRatio">The maximum percent (over screen resolution) it can take.</param>
public double SetPreferredSizeFit(Size size, double maxRatio)
{
if (maxRatio > 1)
maxRatio = 1;
var max = WindowHelper.GetCurrentDesktopSize();
var widthRatio = max.Width * maxRatio / size.Width;
var heightRatio = max.Height * maxRatio / size.Height;
var ratio = Math.Min(widthRatio, heightRatio);
if (ratio > 1) ratio = 1;
PreferredSize = new Size { Width = size.Width * ratio, Height = size.Height * ratio };
return ratio;
}
public void Reset()
{
Title = string.Empty;
// set to False to prevent showing loading icon
IsBusy = false;
PreferredSize = new Size();
CanResize = true;
FullWindowDragging = false;
Theme = Themes.None;
TitlebarOverlap = false;
TitlebarAutoHide = false;
TitlebarBlurVisibility = false;
TitlebarColourVisibility = true;
ViewerContent = null;
ColorProfileName = null;
}
[NotifyPropertyChangedInvocator]
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}