Add "Focusable" property to plugins

This commit is contained in:
Paddy Xu
2017-05-06 22:56:20 +03:00
parent fb1d67e5a0
commit 58886d3302
9 changed files with 27 additions and 9 deletions

View File

@@ -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};
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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)

View File

@@ -62,6 +62,11 @@ namespace QuickLook.Plugin
/// </summary>
public bool CanResize { get; set; } = true;
/// <summary>
/// Set whether user are allowed to set focus at the viewer window.
/// </summary>
public bool Focusable { get; set; } = false;
public void Dispose()
{
GC.SuppressFinalize(this);

View File

@@ -18,11 +18,11 @@
bool CanHandle(string path);
/// <summary>
/// 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.
/// </summary>
/// <param name="path">The full path of the target file.</param>
/// <param name="context">A runtime object which allows interaction between this plugin and QuickLook.</param>
void BoundViewSize(string path, ContextObject context);
void Prepare(string path, ContextObject context);
/// <summary>
/// Start the loading process. During the process a busy indicator will be shown. Finish by setting context.IsBusy to

View File

@@ -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();

View File

@@ -33,7 +33,19 @@ namespace QuickLook
return null;
var matched = GetInstance()
.LoadedPlugins.FirstOrDefault(plugin => plugin.CreateInstance<IViewer>().CanHandle(path))
.LoadedPlugins.FirstOrDefault(plugin =>
{
bool can = false;
try
{
can = plugin.CreateInstance<IViewer>().CanHandle(path);
}
catch (Exception)
{
// ignored
}
return can;
})
?.CreateInstance<IViewer>();
return matched ?? DefaultPlugin.CreateInstance<IViewer>();