-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPlugin.cs
More file actions
58 lines (47 loc) · 1.78 KB
/
Plugin.cs
File metadata and controls
58 lines (47 loc) · 1.78 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
// Copyright © 2022 Frank Becker
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Threading;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
namespace QuickLook.Plugin.WebViewPlus
{
public class Plugin : IViewer
{
private WebpagePanel _panel;
public int Priority => 1;
private static double _width = SettingHelper.Get("WindowWidth", 1000, "QuickLook.Plugin.WebViewPlus");
private static double _height = SettingHelper.Get("WindowHeight", 1200, "QuickLook.Plugin.WebViewPlus");
public void Init()
{
}
public bool CanHandle(string path)
{
var extension = Path.GetExtension(path).ToLower().Substring(1);
return !Directory.Exists(path) && WebpagePanel.Extensions.Any(extension.Equals);
}
public void Prepare(string path, ContextObject context)
{
var desiredSize = new Size(_width, _height);
context.SetPreferredSizeFit(desiredSize, 0.9);
}
public void View(string path, ContextObject context)
{
_panel = new WebpagePanel();
context.ViewerContent = _panel;
context.Title = Path.IsPathRooted(path) ? Path.GetFileName(path) : path;
_panel.NavigateToFile(path);
_panel.Dispatcher.Invoke(() => { context.IsBusy = false; }, DispatcherPriority.Loaded);
}
public void Cleanup()
{
_width = _panel.ActualWidth;
_height = _panel.ActualHeight;
SettingHelper.Set("WindowWidth", _width, "QuickLook.Plugin.WebViewPlus");
SettingHelper.Set("WindowHeight", _height, "QuickLook.Plugin.WebViewPlus");
_panel?.Dispose();
_panel = null;
}
}
}