-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
66 lines (58 loc) · 1.7 KB
/
Plugin.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
using System;
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;
using QuickLook.Common.Plugin;
namespace QuickLook.Plugin.GraphvizDotViewer
{
public class Plugin : IViewer
{
public int Priority => 0;
public void Init()
{
}
public bool CanHandle(string path)
{
return !Directory.Exists(path) && path.ToLower().EndsWith(".dot");
}
public void Prepare(string path, ContextObject context)
{
context.PreferredSize = new Size { Width = 600, Height = 400 };
}
public void View(string path, ContextObject context)
{
byte[] imageBytes = null;
string errorMessage = null;
try
{
imageBytes = GraphvizWrapper.RenderImage(path, "dot", "png");
}
catch (Exception ex)
{
errorMessage = ex.Message;
}
BitmapImage image = null;
if (imageBytes != null)
{
image = new BitmapImage();
image.BeginInit();
using (var ms = new MemoryStream(imageBytes))
{
image.CacheOption = BitmapCacheOption.OnLoad;
image.StreamSource = ms;
image.EndInit();
}
}
context.Title = Path.GetFileName(path);
context.ViewerContent = new ImagePanel
{
ImageControl = { Source = image },
ErrorLabel = { Content = errorMessage }
};
context.IsBusy = false;
}
public void Cleanup()
{
}
}
}