mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 18:39:45 +00:00
Move resource dictionary initialization
This commit is contained in:
@@ -25,7 +25,7 @@ namespace QuickLook.Plugin.HelixViewer;
|
|||||||
|
|
||||||
public class Plugin : IViewer
|
public class Plugin : IViewer
|
||||||
{
|
{
|
||||||
private static readonly HashSet<string> WellKnownImageExtensions = new(
|
private static readonly HashSet<string> WellKnownExtensions = new(
|
||||||
[
|
[
|
||||||
".stl", ".obj", ".3ds", ".lwo", ".ply",
|
".stl", ".obj", ".3ds", ".lwo", ".ply",
|
||||||
]);
|
]);
|
||||||
@@ -41,7 +41,7 @@ public class Plugin : IViewer
|
|||||||
public bool CanHandle(string path)
|
public bool CanHandle(string path)
|
||||||
{
|
{
|
||||||
return !Directory.Exists(path)
|
return !Directory.Exists(path)
|
||||||
&& WellKnownImageExtensions.Contains(Path.GetExtension(path.ToLower()))
|
&& WellKnownExtensions.Contains(Path.GetExtension(path.ToLower()))
|
||||||
&& Handler.CanHandle(path);
|
&& Handler.CanHandle(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ namespace QuickLook.Plugin.ImageViewer;
|
|||||||
|
|
||||||
public class Plugin : IViewer
|
public class Plugin : IViewer
|
||||||
{
|
{
|
||||||
private static readonly HashSet<string> WellKnownImageExtensions = new(
|
private static readonly HashSet<string> WellKnownExtensions = new(
|
||||||
[
|
[
|
||||||
".apng", ".ari", ".arw", ".avif", ".ani",
|
".apng", ".ari", ".arw", ".avif", ".ani",
|
||||||
".bay", ".bmp",
|
".bay", ".bmp",
|
||||||
@@ -108,7 +108,7 @@ public class Plugin : IViewer
|
|||||||
|
|
||||||
// Disabled due mishandling text file types e.g., "*.config".
|
// Disabled due mishandling text file types e.g., "*.config".
|
||||||
// Only check extension for well known image and animated image types.
|
// Only check extension for well known image and animated image types.
|
||||||
return !Directory.Exists(path) && WellKnownImageExtensions.Contains(Path.GetExtension(path).ToLower());
|
return !Directory.Exists(path) && WellKnownExtensions.Contains(Path.GetExtension(path).ToLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Prepare(string path, ContextObject context)
|
public void Prepare(string path, ContextObject context)
|
||||||
|
@@ -27,25 +27,17 @@ namespace QuickLook.Plugin.TextViewer;
|
|||||||
|
|
||||||
public class Plugin : IViewer
|
public class Plugin : IViewer
|
||||||
{
|
{
|
||||||
|
private static readonly HashSet<string> WellKnownExtensions = new(
|
||||||
|
[
|
||||||
|
".txt", ".rtf",
|
||||||
|
]);
|
||||||
|
|
||||||
private TextViewerPanel _tvp;
|
private TextViewerPanel _tvp;
|
||||||
|
|
||||||
public int Priority => -5;
|
public int Priority => -5;
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
// Implementation of the Search Panel Styled with Fluent Theme
|
|
||||||
{
|
|
||||||
var groupDictionary = new ResourceDictionary();
|
|
||||||
groupDictionary.MergedDictionaries.Add(new ResourceDictionary()
|
|
||||||
{
|
|
||||||
Source = new Uri("pack://application:,,,/QuickLook.Plugin.TextViewer;component/Controls/DropDownButton.xaml", UriKind.Absolute)
|
|
||||||
});
|
|
||||||
groupDictionary.MergedDictionaries.Add(new ResourceDictionary()
|
|
||||||
{
|
|
||||||
Source = new Uri("pack://application:,,,/QuickLook.Plugin.TextViewer;component/Controls/SearchPanel.xaml", UriKind.Absolute)
|
|
||||||
});
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(groupDictionary);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanHandle(string path)
|
public bool CanHandle(string path)
|
||||||
@@ -53,14 +45,10 @@ public class Plugin : IViewer
|
|||||||
if (Directory.Exists(path))
|
if (Directory.Exists(path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (new[] { ".txt", ".rtf" }.Any(ext => path.EndsWith(ext, StringComparison.OrdinalIgnoreCase)))
|
if (WellKnownExtensions.Any(ext => path.EndsWith(ext, StringComparison.OrdinalIgnoreCase)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// if there is a matched highlighting scheme (by file extension), treat it as a plain text file
|
// Read the first 16KB, check if we can get something.
|
||||||
// if (HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(path)) != null)
|
|
||||||
// return true;
|
|
||||||
|
|
||||||
// otherwise, read the first 16KB, check if we can get something.
|
|
||||||
using var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
const int bufferLength = 16 * 1024;
|
const int bufferLength = 16 * 1024;
|
||||||
var buffer = new byte[bufferLength];
|
var buffer = new byte[bufferLength];
|
||||||
@@ -94,7 +82,7 @@ public class Plugin : IViewer
|
|||||||
_tvp.LoadFileAsync(path, context);
|
_tvp.LoadFileAsync(path, context);
|
||||||
context.ViewerContent = _tvp;
|
context.ViewerContent = _tvp;
|
||||||
}
|
}
|
||||||
context.Title = $"{Path.GetFileName(path)}";
|
context.Title = Path.GetFileName(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cleanup()
|
public void Cleanup()
|
||||||
|
@@ -29,6 +29,7 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
@@ -42,6 +43,21 @@ public partial class TextViewerPanel : TextEditor, IDisposable
|
|||||||
|
|
||||||
static TextViewerPanel()
|
static TextViewerPanel()
|
||||||
{
|
{
|
||||||
|
// Implementation of the Search Panel Styled with Fluent Theme
|
||||||
|
{
|
||||||
|
var groupDictionary = new ResourceDictionary();
|
||||||
|
groupDictionary.MergedDictionaries.Add(new ResourceDictionary()
|
||||||
|
{
|
||||||
|
Source = new Uri("pack://application:,,,/QuickLook.Plugin.TextViewer;component/Controls/DropDownButton.xaml", UriKind.Absolute)
|
||||||
|
});
|
||||||
|
groupDictionary.MergedDictionaries.Add(new ResourceDictionary()
|
||||||
|
{
|
||||||
|
Source = new Uri("pack://application:,,,/QuickLook.Plugin.TextViewer;component/Controls/SearchPanel.xaml", UriKind.Absolute)
|
||||||
|
});
|
||||||
|
Application.Current.Resources.MergedDictionaries.Add(groupDictionary);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the Highlighting Theme Manager
|
||||||
HighlightingThemeManager.Initialize();
|
HighlightingThemeManager.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ namespace QuickLook.Plugin.ThumbnailViewer;
|
|||||||
|
|
||||||
public class Plugin : IViewer
|
public class Plugin : IViewer
|
||||||
{
|
{
|
||||||
private static readonly HashSet<string> WellKnownImageExtensions = new(
|
private static readonly HashSet<string> WellKnownExtensions = new(
|
||||||
[
|
[
|
||||||
".cdr", // CorelDraw
|
".cdr", // CorelDraw
|
||||||
".fig", // Figma
|
".fig", // Figma
|
||||||
@@ -47,7 +47,7 @@ public class Plugin : IViewer
|
|||||||
|
|
||||||
public bool CanHandle(string path)
|
public bool CanHandle(string path)
|
||||||
{
|
{
|
||||||
return !Directory.Exists(path) && WellKnownImageExtensions.Contains(Path.GetExtension(path.ToLower()));
|
return !Directory.Exists(path) && WellKnownExtensions.Contains(Path.GetExtension(path.ToLower()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Prepare(string path, ContextObject context)
|
public void Prepare(string path, ContextObject context)
|
||||||
|
Reference in New Issue
Block a user