mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-01-13 07:05:24 +08:00
Add blocked file type handling to viewer
Updates the InsvBlocker plugin to mark files as blocked and sets a blocked message in the viewer window. The viewer now displays a message for blocked file types instead of attempting to preview them.
This commit is contained in:
Submodule QuickLook.Common updated: ffda8978fa...709f26fa38
@@ -45,31 +45,16 @@ public class Plugin : IViewer
|
||||
|
||||
public void Prepare(string path, ContextObject context)
|
||||
{
|
||||
// Set a minimal window size (1x1 pixels) to make the window as small as possible
|
||||
// This window will be closed immediately in View() before becoming visible
|
||||
context.PreferredSize = new Size { Width = 1, Height = 1 };
|
||||
// Set Ignore to true to display "blocked" in the preview window
|
||||
context.IsBlocked = true;
|
||||
context.Title = $"[BLOCKED] {Path.GetFileName(path)}";
|
||||
context.PreferredSize = new Size(400, 200);
|
||||
}
|
||||
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
// Create an empty text block as content (required to avoid errors)
|
||||
var textBlock = new TextBlock
|
||||
{
|
||||
Text = "",
|
||||
Visibility = Visibility.Collapsed
|
||||
};
|
||||
context.ViewerContent = textBlock;
|
||||
context.IsBusy = false;
|
||||
|
||||
// Close the window immediately using Send priority for immediate execution
|
||||
// This prevents the window from becoming visible to the user
|
||||
Application.Current?.Dispatcher?.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (context.Source is Window window)
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}), DispatcherPriority.Send);
|
||||
// This should not be called since Ignore is set to true in Prepare
|
||||
// But if called, do nothing
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
|
||||
@@ -201,6 +201,19 @@ public partial class ViewerWindow
|
||||
return;
|
||||
}
|
||||
|
||||
if (ContextObject.IsBlocked)
|
||||
{
|
||||
ContextObject.ViewerContent = new System.Windows.Controls.TextBlock
|
||||
{
|
||||
Text = "This file type is blocked.",
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
FontSize = 14,
|
||||
};
|
||||
ContextObject.IsBusy = false;
|
||||
return;
|
||||
}
|
||||
|
||||
SetOpenWithButtonAndPath();
|
||||
|
||||
// Revert UI changes
|
||||
|
||||
Reference in New Issue
Block a user