Files
QuickLook/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs
2017-05-22 18:51:27 +03:00

60 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
using System.Windows;
namespace QuickLook.Plugin.ImageViewer
{
public class Plugin : IViewer
{
private Size _imageSize;
private ImagePanel _ip;
public int Priority => int.MaxValue;
public bool AllowsTransparency => true;
public bool CanHandle(string path)
{
// TODO: determine file type by content
if (Directory.Exists(path))
return false;
switch (Path.GetExtension(path).ToLower())
{
case ".bmp":
case ".gif":
case ".ico":
case ".jpg":
case ".jpeg":
case ".png":
case ".wdp":
case ".tiff":
return true;
default:
return false;
}
}
public void Prepare(string path, ContextObject context)
{
_imageSize = ImageFileHelper.GetImageSize(path);
context.SetPreferredSizeFit(_imageSize, 0.8);
}
public void View(string path, ContextObject context)
{
_ip = new ImagePanel(path);
context.ViewerContent = _ip;
context.Title = $"{Path.GetFileName(path)} ({_imageSize.Width}×{_imageSize.Height})";
context.IsBusy = false;
}
public void Cleanup()
{
_ip = null;
}
}
}