Skip to content

Commit

Permalink
Improve dark mode text preview
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Jan 1, 2025
1 parent bfa28fc commit 9327382
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 224 deletions.
10 changes: 6 additions & 4 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void View(string path, ContextObject context)
else
{
_tvp = new TextViewerPanel(path, context);
AssignHighlightingManager(_tvp, context);
AssignHighlightingManager(path, _tvp, context);

context.ViewerContent = _tvp;
}
Expand Down Expand Up @@ -146,10 +146,12 @@ private HighlightingManager getHighlightingManager(Themes theme, string dirName)
return hlm;
}

private void AssignHighlightingManager(TextViewerPanel tvp, ContextObject context)
private void AssignHighlightingManager(string path, TextViewerPanel tvp, ContextObject context)
{
var darkThemeAllowed = SettingHelper.Get("AllowDarkTheme", false, "QuickLook.Plugin.TextViewer");
var def = _hlmDark.GetDefinitionByExtension(Path.GetExtension(path));
var darkThemeAllowed = SettingHelper.Get("AllowDarkTheme", def != null, "QuickLook.Plugin.TextViewer");
var isDark = darkThemeAllowed && OSThemeHelper.AppsUseDarkTheme();

tvp.HighlightingManager = isDark ? _hlmDark : _hlmLight;
if (isDark)
{
Expand All @@ -160,7 +162,7 @@ private void AssignHighlightingManager(TextViewerPanel tvp, ContextObject contex
{
// if os dark mode, but not AllowDarkTheme, make background light
tvp.Background = OSThemeHelper.AppsUseDarkTheme()
? new SolidColorBrush(Color.FromArgb(150, 255, 255, 255))
? new SolidColorBrush(Color.FromArgb(175, 255, 255, 255))
: Brushes.Transparent;
}
}
Expand Down
Empty file.
73 changes: 73 additions & 0 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Dark/JSON.xshd
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8" ?>

<SyntaxDefinition name="Json" extensions=".json" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Bool" foreground="#569CD6" exampleText="true | false" />
<Color name="Number" foreground="#B5CEA8" exampleText="3.14" />
<Color name="String" foreground="#CE9178" exampleText="" />
<Color name="Null" foreground="#569CD6" exampleText="" />
<Color name="FieldName" foreground="#9CDCF0" />
<Color name="Punctuation1" foreground="#DA66BE" />
<Color name="Punctuation2" foreground="#FFD710" />
<Color name="Punctuation3" foreground="#FFFFFF" />

<RuleSet name="String">
<Span begin="\\" end="."/>
</RuleSet>

<RuleSet name="Object">
<Span color="FieldName" ruleSet="String">
<Begin>"</Begin>
<End>"</End>
</Span>
<Span color="FieldName" ruleSet="String">
<Begin>'</Begin>
<End>'</End>
</Span>
<Span color="Punctuation3" ruleSet="Expression">
<Begin>:</Begin>
</Span>
<Span color="Punctuation3">
<Begin>,</Begin>
</Span>
</RuleSet>

<RuleSet name="Array">
<Import ruleSet="Expression"/>
<Span color="Punctuation3">
<Begin>,</Begin>
</Span>
</RuleSet>

<RuleSet name="Expression">
<Keywords color="Bool" >
<Word>true</Word>
<Word>false</Word>
</Keywords>
<Keywords color="Null" >
<Word>null</Word>
</Keywords>
<Span color="String" ruleSet="String">
<Begin>"</Begin>
<End>"</End>
</Span>
<Span color="String" ruleSet="String">
<Begin>'</Begin>
<End>'</End>
</Span>
<Span color="Punctuation1" ruleSet="Object" multiline="true">
<Begin>\{</Begin>
<End>\}</End>
</Span>
<Span color="Punctuation2" ruleSet="Array" multiline="true">
<Begin>\[</Begin>
<End>\]</End>
</Span>
<Rule color="Number">
\b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?
</Rule>
</RuleSet>

<RuleSet>
<Import ruleSet="Expression"/>
</RuleSet>
</SyntaxDefinition>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ [email protected]
https://github.com/ei
-->

<SyntaxDefinition name="Assembly" extensions=".asm;.ASM">
<SyntaxDefinition name="Assembly" extensions=".asm">

<Environment>
<Default color="Black" bgcolor="#FFFFFF"/>
Expand Down
21 changes: 0 additions & 21 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/_LICENSE

This file was deleted.

198 changes: 0 additions & 198 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/_README.md

This file was deleted.

0 comments on commit 9327382

Please sign in to comment.