From 58886d3302aa185673e8e7eeaacc789357123f10 Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Sat, 6 May 2017 22:56:20 +0300 Subject: [PATCH] Add "Focusable" property to plugins --- .../QuickLook.Plugin.ArchiveViewer/Plugin.cs | 2 +- .../QuickLook.Plugin.ImageViewer/Plugin.cs | 2 +- .../PluginInterface.cs | 2 +- .../QuickLook.Plugin.PDFViewer/Plugin.cs | 2 +- .../QuickLook.Plugin.TextViewer/Plugin.cs | 3 ++- QuickLook/Plugin/ContextObject.cs | 5 +++++ QuickLook/Plugin/IViewer.cs | 4 ++-- QuickLook/Plugin/InfoPanel/PluginInterface.cs | 2 +- QuickLook/PluginManager.cs | 14 +++++++++++++- 9 files changed, 27 insertions(+), 9 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs index c1b9a7a..c31ab65 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs @@ -30,7 +30,7 @@ namespace QuickLook.Plugin.ArchiveViewer return true; } - public void BoundViewSize(string path, ContextObject context) + public void Prepare(string path, ContextObject context) { context.PreferredSize = new Size {Width = 800, Height = 600}; } diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs index 0986155..1fec187 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs @@ -33,7 +33,7 @@ namespace QuickLook.Plugin.ImageViewer } } - public void BoundViewSize(string path, ContextObject context) + public void Prepare(string path, ContextObject context) { _imageSize = ImageFileHelper.GetImageSize(path); diff --git a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PluginInterface.cs b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PluginInterface.cs index 148fb39..9e848a3 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PluginInterface.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.OfficeViewer/PluginInterface.cs @@ -31,7 +31,7 @@ namespace QuickLook.Plugin.OfficeViewer return false; } - public void BoundViewSize(string path, ContextObject context) + public void Prepare(string path, ContextObject context) { context.SetPreferredSizeFit(new Size {Width = 800, Height = 600}, 0.8); } diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs index b6fe2c6..0533c28 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs @@ -24,7 +24,7 @@ namespace QuickLook.Plugin.PDFViewer } } - public void BoundViewSize(string path, ContextObject context) + public void Prepare(string path, ContextObject context) { _pdfControl = new PdfViewerControl(); diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs index 2b8dcec..1040a3e 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs @@ -40,9 +40,10 @@ namespace QuickLook.Plugin.TextViewer } } - public void BoundViewSize(string path, ContextObject context) + public void Prepare(string path, ContextObject context) { context.PreferredSize = new Size {Width = 800, Height = 600}; + context.Focusable = true; } public void View(string path, ContextObject context) diff --git a/QuickLook/Plugin/ContextObject.cs b/QuickLook/Plugin/ContextObject.cs index 5f75d54..e83d0a6 100644 --- a/QuickLook/Plugin/ContextObject.cs +++ b/QuickLook/Plugin/ContextObject.cs @@ -62,6 +62,11 @@ namespace QuickLook.Plugin /// public bool CanResize { get; set; } = true; + /// + /// Set whether user are allowed to set focus at the viewer window. + /// + public bool Focusable { get; set; } = false; + public void Dispose() { GC.SuppressFinalize(this); diff --git a/QuickLook/Plugin/IViewer.cs b/QuickLook/Plugin/IViewer.cs index 3c09250..fb4a8bb 100644 --- a/QuickLook/Plugin/IViewer.cs +++ b/QuickLook/Plugin/IViewer.cs @@ -18,11 +18,11 @@ bool CanHandle(string path); /// - /// Tell QuickLook the desired window size. Please not do any work that costs a lot of time. + /// Do some preparation stuff before the window is showing. Please not do any work that costs a lot of time. /// /// The full path of the target file. /// A runtime object which allows interaction between this plugin and QuickLook. - void BoundViewSize(string path, ContextObject context); + void Prepare(string path, ContextObject context); /// /// Start the loading process. During the process a busy indicator will be shown. Finish by setting context.IsBusy to diff --git a/QuickLook/Plugin/InfoPanel/PluginInterface.cs b/QuickLook/Plugin/InfoPanel/PluginInterface.cs index f538879..c497463 100644 --- a/QuickLook/Plugin/InfoPanel/PluginInterface.cs +++ b/QuickLook/Plugin/InfoPanel/PluginInterface.cs @@ -14,7 +14,7 @@ namespace QuickLook.Plugin.InfoPanel return true; } - public void BoundViewSize(string path, ContextObject context) + public void Prepare(string path, ContextObject context) { _ip = new InfoPanel(); diff --git a/QuickLook/PluginManager.cs b/QuickLook/PluginManager.cs index 4a7b16e..4df8f13 100644 --- a/QuickLook/PluginManager.cs +++ b/QuickLook/PluginManager.cs @@ -33,7 +33,19 @@ namespace QuickLook return null; var matched = GetInstance() - .LoadedPlugins.FirstOrDefault(plugin => plugin.CreateInstance().CanHandle(path)) + .LoadedPlugins.FirstOrDefault(plugin => + { + bool can = false; + try + { + can = plugin.CreateInstance().CanHandle(path); + } + catch (Exception) + { + // ignored + } + return can; + }) ?.CreateInstance(); return matched ?? DefaultPlugin.CreateInstance();