TextEditor support for dark theme
This commit is contained in:
1 parent
552ad7398e
commit
f160be7dc9
12 files changed
+590
-62
No files matched your search
@@ -426,6 +426,12 @@
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\fabric-icons.ttf">
|
||||
<Link>Resources\fabric-icons.ttf</Link>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\xshd\CSharp-Dark.xshd">
|
||||
<Link>Resources\xshd\CSharp-Dark.xshd</Link>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\xshd\XML-Dark.xshd">
|
||||
<Link>Resources\xshd\XML-Dark.xshd</Link>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Registry.txt">
|
||||
<Link>Resources\Registry.txt</Link>
|
||||
</Resource>
|
||||
|
||||
@@ -428,6 +428,12 @@
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\fabric-icons.ttf">
|
||||
<Link>Resources\fabric-icons.ttf</Link>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\xshd\CSharp-Dark.xshd">
|
||||
<Link>Resources\xshd\CSharp-Dark.xshd</Link>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\xshd\XML-Dark.xshd">
|
||||
<Link>Resources\xshd\XML-Dark.xshd</Link>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Registry.txt">
|
||||
<Link>Resources\Registry.txt</Link>
|
||||
</Resource>
|
||||
|
||||
@@ -52,5 +52,7 @@
|
||||
|
||||
public static readonly string LangUpdated = nameof(LangUpdated);
|
||||
|
||||
public static readonly string SkinUpdated = nameof(SkinUpdated);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ var messageList = new List<string>
|
||||
"NavigationWindow",
|
||||
"TouchDragMoveWindow",
|
||||
"DialogContainer",
|
||||
"LangUpdated"
|
||||
"LangUpdated",
|
||||
"SkinUpdated"
|
||||
};
|
||||
#>
|
||||
namespace HandyControlDemo.Data
|
||||
@@ -40,4 +41,4 @@ namespace HandyControlDemo.Data
|
||||
|
||||
<#}#>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\AssemblyHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\VersionHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\Win32Helper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\HighlightingProvider.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Basic\Avatar.xaml.cs">
|
||||
<DependentUpon>Avatar.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
<Color x:Key="EditorLineNumbersForegroundColor">#ff929292</Color>
|
||||
<Color x:Key="EditorNonPrintableCharacterColor">#2FFFFFFF</Color>
|
||||
<Color x:Key="EditorLinkTextForegroundColor">#FFAAAAFF</Color>
|
||||
<Color x:Key="EditorLinkTextBackgroundColor">#18FFFFFF</Color>
|
||||
<Color x:Key="EditorLinkTextBackgroundColor">Transparent</Color>
|
||||
|
||||
<!--endregion-->
|
||||
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,310 @@
|
||||
<?xml version="1.0"?>
|
||||
<SyntaxDefinition name="C#" extensions=".cs" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
|
||||
<!-- The named colors 'Comment' and 'String' are used in SharpDevelop to detect if a line is inside a multiline string/comment -->
|
||||
<Color name="Comment" foreground="Green" exampleText="// comment" />
|
||||
<Color name="String" foreground="#b47044" exampleText="string text = "Hello, World!""/>
|
||||
<Color name="StringInterpolation" foreground="#b47044" exampleText="string text = $"Hello, {name}!""/>
|
||||
<Color name="Char" foreground="Magenta" exampleText="char linefeed = '\n';"/>
|
||||
<Color name="Preprocessor" foreground="Green" exampleText="#region Title" />
|
||||
<Color name="Punctuation" exampleText="a(b.c);" />
|
||||
<Color name="ValueTypeKeywords" fontWeight="bold" foreground="#4e8cc1" exampleText="bool b = true;" />
|
||||
<Color name="ReferenceTypeKeywords" foreground="#4e8cc1" exampleText="object o;" />
|
||||
<Color name="MethodCall" foreground="#c4c498" fontWeight="bold" exampleText="o.ToString();"/>
|
||||
<Color name="NumberLiteral" foreground="DarkBlue" exampleText="3.1415f"/>
|
||||
<Color name="ThisOrBaseReference" fontWeight="bold" exampleText="this.Do(); base.Do();"/>
|
||||
<Color name="NullOrValueKeywords" fontWeight="bold" exampleText="if (value == null)"/>
|
||||
<Color name="Keywords" fontWeight="bold" foreground="#4e8cc1" exampleText="if (a) {} else {}"/>
|
||||
<Color name="GotoKeywords" foreground="#4e8cc1" exampleText="continue; return null;"/>
|
||||
<Color name="ContextKeywords" foreground="#4e8cc1" exampleText="var a = from x in y select z;"/>
|
||||
<Color name="ExceptionKeywords" fontWeight="bold" foreground="Teal" exampleText="try {} catch {} finally {}"/>
|
||||
<Color name="CheckedKeyword" fontWeight="bold" foreground="DarkGray" exampleText="checked {}"/>
|
||||
<Color name="UnsafeKeywords" foreground="Olive" exampleText="unsafe { fixed (..) {} }"/>
|
||||
<Color name="OperatorKeywords" fontWeight="bold" foreground="Pink" exampleText="public static implicit operator..."/>
|
||||
<Color name="ParameterModifiers" fontWeight="bold" foreground="DeepPink" exampleText="(ref int a, params int[] b)"/>
|
||||
<Color name="Modifiers" foreground="Brown" exampleText="static readonly int a;"/>
|
||||
<Color name="Visibility" fontWeight="bold" foreground="#4e8cc1" exampleText="public override void ToString();"/>
|
||||
<Color name="NamespaceKeywords" fontWeight="bold" foreground="#4e8cc1" exampleText="namespace A.B { using System; }"/>
|
||||
<Color name="GetSetAddRemove" foreground="#4e8cc1" exampleText="int Prop { get; set; }"/>
|
||||
<Color name="TrueFalse" fontWeight="bold" foreground="DarkCyan" exampleText="b = false; a = true;" />
|
||||
<Color name="TypeKeywords" fontWeight="bold" foreground="DarkCyan" exampleText="if (x is int) { a = x as int; type = typeof(int); size = sizeof(int); c = new object(); }"/>
|
||||
<Color name="SemanticKeywords" fontWeight="bold" foreground="DarkCyan" exampleText="if (args == null) throw new ArgumentNullException(nameof(args));" />
|
||||
|
||||
<Property name="DocCommentMarker" value="///" />
|
||||
|
||||
<RuleSet name="CommentMarkerSet">
|
||||
<Keywords fontWeight="bold" foreground="Red">
|
||||
<Word>TODO</Word>
|
||||
<Word>FIXME</Word>
|
||||
</Keywords>
|
||||
<Keywords fontWeight="bold" foreground="#E0E000">
|
||||
<Word>HACK</Word>
|
||||
<Word>UNDONE</Word>
|
||||
</Keywords>
|
||||
</RuleSet>
|
||||
|
||||
<!-- This is the main ruleset. -->
|
||||
<RuleSet>
|
||||
<Span color="Preprocessor">
|
||||
<Begin>\#</Begin>
|
||||
<RuleSet name="PreprocessorSet">
|
||||
<Span> <!-- preprocessor directives that allows comments -->
|
||||
<Begin fontWeight="bold">
|
||||
(define|undef|if|elif|else|endif|line)\b
|
||||
</Begin>
|
||||
<RuleSet>
|
||||
<Span color="Comment" ruleSet="CommentMarkerSet">
|
||||
<Begin>//</Begin>
|
||||
</Span>
|
||||
</RuleSet>
|
||||
</Span>
|
||||
<Span> <!-- preprocessor directives that don't allow comments -->
|
||||
<Begin fontWeight="bold">
|
||||
(region|endregion|error|warning|pragma)\b
|
||||
</Begin>
|
||||
</Span>
|
||||
</RuleSet>
|
||||
</Span>
|
||||
|
||||
<Span color="Comment">
|
||||
<Begin color="XmlDoc/DocComment">///(?!/)</Begin>
|
||||
<RuleSet>
|
||||
<Import ruleSet="XmlDoc/DocCommentSet"/>
|
||||
<Import ruleSet="CommentMarkerSet"/>
|
||||
</RuleSet>
|
||||
</Span>
|
||||
|
||||
<Span color="Comment" ruleSet="CommentMarkerSet">
|
||||
<Begin>//</Begin>
|
||||
</Span>
|
||||
|
||||
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
|
||||
<Begin>/\*</Begin>
|
||||
<End>\*/</End>
|
||||
</Span>
|
||||
|
||||
<Span color="String">
|
||||
<Begin>"</Begin>
|
||||
<End>"</End>
|
||||
<RuleSet>
|
||||
<!-- span for escape sequences -->
|
||||
<Span begin="\\" end="."/>
|
||||
</RuleSet>
|
||||
</Span>
|
||||
|
||||
<Span color="Char">
|
||||
<Begin>'</Begin>
|
||||
<End>'</End>
|
||||
<RuleSet>
|
||||
<!-- span for escape sequences -->
|
||||
<Span begin="\\" end="."/>
|
||||
</RuleSet>
|
||||
</Span>
|
||||
|
||||
<Span color="String" multiline="true">
|
||||
<Begin>@"</Begin>
|
||||
<End>"</End>
|
||||
<RuleSet>
|
||||
<!-- span for escape sequences -->
|
||||
<Span begin='""' end=""/>
|
||||
</RuleSet>
|
||||
</Span>
|
||||
|
||||
<Span color="String">
|
||||
<Begin>\$"</Begin>
|
||||
<End>"</End>
|
||||
<RuleSet>
|
||||
<!-- span for escape sequences -->
|
||||
<Span begin="\\" end="."/>
|
||||
<Span begin="\{\{" end=""/>
|
||||
<!-- string interpolation -->
|
||||
<Span begin="{" end="}" color="StringInterpolation" ruleSet=""/>
|
||||
</RuleSet>
|
||||
</Span>
|
||||
|
||||
<!-- don't highlight "@int" as keyword -->
|
||||
<Rule>
|
||||
@[\w\d_]+
|
||||
</Rule>
|
||||
|
||||
<Keywords color="ThisOrBaseReference">
|
||||
<Word>this</Word>
|
||||
<Word>base</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="TypeKeywords">
|
||||
<Word>as</Word>
|
||||
<Word>is</Word>
|
||||
<Word>new</Word>
|
||||
<Word>sizeof</Word>
|
||||
<Word>typeof</Word>
|
||||
<Word>stackalloc</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="TrueFalse">
|
||||
<Word>true</Word>
|
||||
<Word>false</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="Keywords">
|
||||
<Word>else</Word>
|
||||
<Word>if</Word>
|
||||
<Word>switch</Word>
|
||||
<Word>case</Word>
|
||||
<Word>default</Word>
|
||||
<Word>do</Word>
|
||||
<Word>for</Word>
|
||||
<Word>foreach</Word>
|
||||
<Word>in</Word>
|
||||
<Word>while</Word>
|
||||
<Word>lock</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="GotoKeywords">
|
||||
<Word>break</Word>
|
||||
<Word>continue</Word>
|
||||
<Word>goto</Word>
|
||||
<Word>return</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="ContextKeywords">
|
||||
<Word>yield</Word>
|
||||
<Word>partial</Word>
|
||||
<Word>global</Word>
|
||||
<Word>where</Word>
|
||||
<Word>select</Word>
|
||||
<Word>group</Word>
|
||||
<Word>by</Word>
|
||||
<Word>into</Word>
|
||||
<Word>from</Word>
|
||||
<Word>ascending</Word>
|
||||
<Word>descending</Word>
|
||||
<Word>orderby</Word>
|
||||
<Word>let</Word>
|
||||
<Word>join</Word>
|
||||
<Word>on</Word>
|
||||
<Word>equals</Word>
|
||||
<Word>var</Word>
|
||||
<Word>dynamic</Word>
|
||||
<Word>await</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="ExceptionKeywords">
|
||||
<Word>try</Word>
|
||||
<Word>throw</Word>
|
||||
<Word>catch</Word>
|
||||
<Word>finally</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="CheckedKeyword">
|
||||
<Word>checked</Word>
|
||||
<Word>unchecked</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="UnsafeKeywords">
|
||||
<Word>fixed</Word>
|
||||
<Word>unsafe</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="ValueTypeKeywords">
|
||||
<Word>bool</Word>
|
||||
<Word>byte</Word>
|
||||
<Word>char</Word>
|
||||
<Word>decimal</Word>
|
||||
<Word>double</Word>
|
||||
<Word>enum</Word>
|
||||
<Word>float</Word>
|
||||
<Word>int</Word>
|
||||
<Word>long</Word>
|
||||
<Word>sbyte</Word>
|
||||
<Word>short</Word>
|
||||
<Word>struct</Word>
|
||||
<Word>uint</Word>
|
||||
<Word>ushort</Word>
|
||||
<Word>ulong</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="ReferenceTypeKeywords">
|
||||
<Word>class</Word>
|
||||
<Word>interface</Word>
|
||||
<Word>delegate</Word>
|
||||
<Word>object</Word>
|
||||
<Word>string</Word>
|
||||
<Word>void</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="OperatorKeywords">
|
||||
<Word>explicit</Word>
|
||||
<Word>implicit</Word>
|
||||
<Word>operator</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="ParameterModifiers">
|
||||
<Word>params</Word>
|
||||
<Word>ref</Word>
|
||||
<Word>out</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="Modifiers">
|
||||
<Word>abstract</Word>
|
||||
<Word>const</Word>
|
||||
<Word>event</Word>
|
||||
<Word>extern</Word>
|
||||
<Word>override</Word>
|
||||
<Word>readonly</Word>
|
||||
<Word>sealed</Word>
|
||||
<Word>static</Word>
|
||||
<Word>virtual</Word>
|
||||
<Word>volatile</Word>
|
||||
<Word>async</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="Visibility">
|
||||
<Word>public</Word>
|
||||
<Word>protected</Word>
|
||||
<Word>private</Word>
|
||||
<Word>internal</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="NamespaceKeywords">
|
||||
<Word>namespace</Word>
|
||||
<Word>using</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="GetSetAddRemove">
|
||||
<Word>get</Word>
|
||||
<Word>set</Word>
|
||||
<Word>add</Word>
|
||||
<Word>remove</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="NullOrValueKeywords">
|
||||
<Word>null</Word>
|
||||
<Word>value</Word>
|
||||
</Keywords>
|
||||
|
||||
<Keywords color="SemanticKeywords">
|
||||
<Word>nameof</Word>
|
||||
</Keywords>
|
||||
|
||||
<!-- Mark previous rule-->
|
||||
<Rule color="MethodCall">
|
||||
\b
|
||||
[\d\w_]+ # an identifier
|
||||
(?=\s*\() # followed by (
|
||||
</Rule>
|
||||
|
||||
<!-- Digits -->
|
||||
<Rule color="NumberLiteral">
|
||||
\b0[xX][0-9a-fA-F]+ # hex number
|
||||
|
|
||||
( \b\d+(\.[0-9]+)? #number with optional floating point
|
||||
| \.[0-9]+ #or just starting with floating point
|
||||
)
|
||||
([eE][+-]?[0-9]+)? # optional exponent
|
||||
</Rule>
|
||||
|
||||
<Rule color="Punctuation">
|
||||
[?,.;()\[\]{}+\-/%*<>^+~!|&]+
|
||||
</Rule>
|
||||
</RuleSet>
|
||||
</SyntaxDefinition>
|
||||
@@ -0,0 +1,63 @@
|
||||
<SyntaxDefinition name="XML" extensions=".xml;.xsl;.xslt;.xsd;.manifest;.config;.addin;.xshd;.wxs;.wxi;.wxl;.proj;.csproj;.vbproj;.ilproj;.booproj;.build;.xfrm;.targets;.xaml;.xpt;.xft;.map;.wsdl;.disco;.ps1xml;.nuspec" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
|
||||
<Color foreground="Green" name="Comment" exampleText="<!-- comment -->" />
|
||||
<Color foreground="Blue" name="CData" exampleText="<![CDATA[data]]>" />
|
||||
<Color foreground="Blue" name="DocType" exampleText="<!DOCTYPE rootElement>" />
|
||||
<Color foreground="Blue" name="XmlDeclaration" exampleText='<?xml version="1.0"?>' />
|
||||
<Color foreground="White" name="XmlTag" exampleText='<tag attribute="value" />' />
|
||||
<Color foreground="#92caf4" name="AttributeName" exampleText='<tag attribute="value" />' />
|
||||
<Color foreground="#569cd6" name="AttributeValue" exampleText='<tag attribute="value" />' />
|
||||
<Color foreground="Teal" name="Entity" exampleText="index.aspx?a=1&amp;b=2" />
|
||||
<Color foreground="Olive" name="BrokenEntity" exampleText="index.aspx?a=1&b=2" />
|
||||
|
||||
<RuleSet>
|
||||
<Span color="Comment" multiline="true">
|
||||
<Begin><!--</Begin>
|
||||
<End>--></End>
|
||||
</Span>
|
||||
<Span color="CData" multiline="true">
|
||||
<Begin><!\[CDATA\[</Begin>
|
||||
<End>]]></End>
|
||||
</Span>
|
||||
<Span color="DocType" multiline="true">
|
||||
<Begin><!DOCTYPE</Begin>
|
||||
<End>></End>
|
||||
</Span>
|
||||
<Span color="XmlDeclaration" multiline="true">
|
||||
<Begin><\?</Begin>
|
||||
<End>\?></End>
|
||||
</Span>
|
||||
<Span color="XmlTag" multiline="true">
|
||||
<Begin><</Begin>
|
||||
<End>></End>
|
||||
<RuleSet>
|
||||
<!-- Treat the position before '<' as end, as that's not a valid character
|
||||
in attribute names and indicates the user forgot a closing quote. -->
|
||||
<Span color="AttributeValue" multiline="true" ruleSet="EntitySet">
|
||||
<Begin>"</Begin>
|
||||
<End>"|(?=<)</End>
|
||||
</Span>
|
||||
<Span color="AttributeValue" multiline="true" ruleSet="EntitySet">
|
||||
<Begin>'</Begin>
|
||||
<End>'|(?=<)</End>
|
||||
</Span>
|
||||
<Rule color="AttributeName">[\d\w_\-\.]+(?=(\s*=))</Rule>
|
||||
<Rule color="AttributeValue">=</Rule>
|
||||
</RuleSet>
|
||||
</Span>
|
||||
<Import ruleSet="EntitySet"/>
|
||||
</RuleSet>
|
||||
|
||||
<RuleSet name="EntitySet">
|
||||
<Rule color="Entity">
|
||||
&
|
||||
[\w\d\#]+
|
||||
;
|
||||
</Rule>
|
||||
|
||||
<Rule color="BrokenEntity">
|
||||
&
|
||||
[\w\d\#]*
|
||||
#missing ;
|
||||
</Rule>
|
||||
</RuleSet>
|
||||
</SyntaxDefinition>
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Xml;
|
||||
using HandyControl.Data;
|
||||
using ICSharpCode.AvalonEdit.Highlighting;
|
||||
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
|
||||
|
||||
namespace HandyControlDemo.Tools
|
||||
{
|
||||
internal class HighlightingProvider
|
||||
{
|
||||
public static HighlightingProvider Default = new Lazy<HighlightingProvider>(() => new HighlightingProvider()).Value;
|
||||
|
||||
protected static readonly Lazy<IHighlightingDefinition> DefaultDefinition = new(() => HighlightingManager.Instance.GetDefinition("C#"));
|
||||
|
||||
private static readonly Dictionary<SkinType, HighlightingProvider> Providers = new();
|
||||
|
||||
protected Dictionary<string, Lazy<IHighlightingDefinition>> Definition;
|
||||
|
||||
public static void Register(SkinType skinType, HighlightingProvider provider)
|
||||
{
|
||||
Providers[skinType] = provider ?? throw new ArgumentNullException(nameof(provider));
|
||||
provider.InitDefinitions();
|
||||
}
|
||||
|
||||
public static IHighlightingDefinition GetDefinition(SkinType skinType, string name)
|
||||
{
|
||||
if (Providers.TryGetValue(skinType, out var provider))
|
||||
{
|
||||
return provider.GetDefinition(name);
|
||||
}
|
||||
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
protected static IHighlightingDefinition LoadDefinition(string xshdName)
|
||||
{
|
||||
var streamResourceInfo = Application.GetResourceStream(new Uri($"pack://application:,,,/Resources/xshd/{xshdName}.xshd"));
|
||||
if (streamResourceInfo == null)
|
||||
{
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
using var reader = new XmlTextReader(streamResourceInfo.Stream);
|
||||
return HighlightingLoader.Load(reader, HighlightingManager.Instance);
|
||||
}
|
||||
|
||||
protected virtual IHighlightingDefinition GetDefinition(string name)
|
||||
{
|
||||
if (Definition.TryGetValue(name, out var definition))
|
||||
{
|
||||
return definition.Value;
|
||||
}
|
||||
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
protected virtual void InitDefinitions()
|
||||
{
|
||||
Definition = new Dictionary<string, Lazy<IHighlightingDefinition>>
|
||||
{
|
||||
["XML"] = new(() => HighlightingManager.Instance.GetDefinition("XML")),
|
||||
["C#"] = new(() => DefaultDefinition.Value)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal class HighlightingProviderDark : HighlightingProvider
|
||||
{
|
||||
protected override void InitDefinitions()
|
||||
{
|
||||
Definition = new Dictionary<string, Lazy<IHighlightingDefinition>>
|
||||
{
|
||||
["XML"] = new(() => LoadDefinition("XML-Dark")),
|
||||
["C#"] = new(() => LoadDefinition("CSharp-Dark")),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,13 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
using HandyControl.Tools.Extension;
|
||||
using HandyControlDemo.Data;
|
||||
using HandyControlDemo.Tools;
|
||||
using HandyControlDemo.ViewModel;
|
||||
using ICSharpCode.AvalonEdit;
|
||||
using ICSharpCode.AvalonEdit.Highlighting;
|
||||
|
||||
|
||||
namespace HandyControlDemo.UserControl
|
||||
@@ -30,12 +31,18 @@ namespace HandyControlDemo.UserControl
|
||||
InitializeComponent();
|
||||
|
||||
Messenger.Default.Register<bool>(this, MessageToken.FullSwitch, FullSwitch);
|
||||
Messenger.Default.Register<SkinType>(this, MessageToken.SkinUpdated, SkinUpdated);
|
||||
}
|
||||
|
||||
private void FullSwitch(bool isFull)
|
||||
{
|
||||
if (_isFull == isFull) return;
|
||||
if (_isFull == isFull)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isFull = isFull;
|
||||
|
||||
if (_isFull)
|
||||
{
|
||||
BorderRootEffect.Show();
|
||||
@@ -60,58 +67,79 @@ namespace HandyControlDemo.UserControl
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawerCode_OnOpened(object sender, RoutedEventArgs e)
|
||||
private void SkinUpdated(SkinType skinType)
|
||||
{
|
||||
if (!_drawerCodeUsed)
|
||||
{
|
||||
var textEditorCustomStyle = ResourceHelper.GetResource<Style>("TextEditorCustom");
|
||||
_textEditor = new Dictionary<string, TextEditor>
|
||||
{
|
||||
["XAML"] = new()
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML")
|
||||
},
|
||||
["C#"] = new()
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#")
|
||||
},
|
||||
["VM"] = new()
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#")
|
||||
}
|
||||
};
|
||||
BorderCode.Child = new TabControl
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>("TabControlInLine"),
|
||||
Items =
|
||||
{
|
||||
new TabItem
|
||||
{
|
||||
Header = "XAML",
|
||||
Content = _textEditor["XAML"]
|
||||
},
|
||||
new TabItem
|
||||
{
|
||||
Header = "C#",
|
||||
Content = _textEditor["C#"]
|
||||
},
|
||||
new TabItem
|
||||
{
|
||||
Header = "VM",
|
||||
Content = _textEditor["VM"]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_drawerCodeUsed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_textEditor[ConstString.Xaml].SyntaxHighlighting = HighlightingProvider.GetDefinition(skinType, ConstString.Xml);
|
||||
_textEditor[ConstString.Cs].SyntaxHighlighting = HighlightingProvider.GetDefinition(skinType, ConstString.Cs);
|
||||
_textEditor[ConstString.Vm].SyntaxHighlighting = HighlightingProvider.GetDefinition(skinType, ConstString.Cs);
|
||||
}
|
||||
|
||||
private void InitTextEditor()
|
||||
{
|
||||
HighlightingProvider.Register(SkinType.Default, HighlightingProvider.Default);
|
||||
HighlightingProvider.Register(SkinType.Dark, new HighlightingProviderDark());
|
||||
HighlightingProvider.Register(SkinType.Violet, HighlightingProvider.Default);
|
||||
|
||||
var textEditorCustomStyle = ResourceHelper.GetResource<Style>("TextEditorCustom");
|
||||
var skinType = GlobalData.Config.Skin;
|
||||
|
||||
_textEditor = new Dictionary<string, TextEditor>
|
||||
{
|
||||
[ConstString.Xaml] = new()
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingProvider.GetDefinition(skinType, ConstString.Xml)
|
||||
},
|
||||
[ConstString.Cs] = new()
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingProvider.GetDefinition(skinType, ConstString.Cs)
|
||||
},
|
||||
[ConstString.Vm] = new()
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingProvider.GetDefinition(skinType, ConstString.Cs)
|
||||
}
|
||||
};
|
||||
|
||||
BorderCode.Child = new TabControl
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>("TabControlInLine"),
|
||||
Items =
|
||||
{
|
||||
new TabItem
|
||||
{
|
||||
Header = ConstString.Xaml,
|
||||
Content = _textEditor[ConstString.Xaml]
|
||||
},
|
||||
new TabItem
|
||||
{
|
||||
Header = ConstString.Cs,
|
||||
Content = _textEditor[ConstString.Cs]
|
||||
},
|
||||
new TabItem
|
||||
{
|
||||
Header = ConstString.Vm,
|
||||
Content = _textEditor[ConstString.Vm]
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void UpdateTextEditor()
|
||||
{
|
||||
var typeKey = ViewModelLocator.Instance.Main.DemoInfoCurrent.Key;
|
||||
var demoKey = ViewModelLocator.Instance.Main.DemoItemCurrent.TargetCtlName;
|
||||
if (Equals(_currentDemoKey, demoKey)) return;
|
||||
if (Equals(_currentDemoKey, demoKey))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_currentDemoKey = demoKey;
|
||||
|
||||
if (ViewModelLocator.Instance.Main.SubContent is FrameworkElement demoCtl)
|
||||
@@ -124,10 +152,32 @@ namespace HandyControlDemo.UserControl
|
||||
? $"ViewModel/{dcTypeName}"
|
||||
: xamlPath;
|
||||
|
||||
_textEditor["XAML"].Text = DemoHelper.GetCode(xamlPath);
|
||||
_textEditor["C#"].Text = DemoHelper.GetCode($"{xamlPath}.cs");
|
||||
_textEditor["VM"].Text = DemoHelper.GetCode($"{vmPath}.cs");
|
||||
_textEditor[ConstString.Xaml].Text = DemoHelper.GetCode(xamlPath);
|
||||
_textEditor[ConstString.Cs].Text = DemoHelper.GetCode($"{xamlPath}.cs");
|
||||
_textEditor[ConstString.Vm].Text = DemoHelper.GetCode($"{vmPath}.cs");
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawerCode_OnOpened(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!_drawerCodeUsed)
|
||||
{
|
||||
InitTextEditor();
|
||||
_drawerCodeUsed = true;
|
||||
}
|
||||
|
||||
UpdateTextEditor();
|
||||
}
|
||||
|
||||
private static class ConstString
|
||||
{
|
||||
public const string Xaml = "XAML";
|
||||
|
||||
public const string Vm = "VM";
|
||||
|
||||
public const string Cs = "C#";
|
||||
|
||||
public const string Xml = "XML";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,17 @@ namespace HandyControlDemo.UserControl
|
||||
|
||||
private void ButtonLangs_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is Button button && button.Tag is string langName)
|
||||
if (e.OriginalSource is Button {Tag: string langName})
|
||||
{
|
||||
PopupConfig.IsOpen = false;
|
||||
if (langName.Equals(GlobalData.Config.Lang)) return;
|
||||
if (langName.Equals(GlobalData.Config.Lang))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigHelper.Instance.SetLang(langName);
|
||||
LangProvider.Culture = new CultureInfo(langName);
|
||||
Messenger.Default.Send<object>(null, "LangUpdated");
|
||||
Messenger.Default.Send<object>(null, MessageToken.LangUpdated);
|
||||
|
||||
GlobalData.Config.Lang = langName;
|
||||
GlobalData.Save();
|
||||
@@ -36,13 +40,18 @@ namespace HandyControlDemo.UserControl
|
||||
|
||||
private void ButtonSkins_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is Button button && button.Tag is SkinType tag)
|
||||
if (e.OriginalSource is Button {Tag: SkinType skinType})
|
||||
{
|
||||
PopupConfig.IsOpen = false;
|
||||
if (tag.Equals(GlobalData.Config.Skin)) return;
|
||||
GlobalData.Config.Skin = tag;
|
||||
if (skinType.Equals(GlobalData.Config.Skin))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GlobalData.Config.Skin = skinType;
|
||||
GlobalData.Save();
|
||||
((App) Application.Current).UpdateSkin(tag);
|
||||
((App) Application.Current).UpdateSkin(skinType);
|
||||
Messenger.Default.Send(skinType, MessageToken.SkinUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace HandyControlDemo.ViewModel
|
||||
SimpleIoc.Default.Register<TagDemoViewModel>();
|
||||
}
|
||||
|
||||
public static ViewModelLocator Instance => new Lazy<ViewModelLocator>(() =>
|
||||
public static ViewModelLocator Instance = new Lazy<ViewModelLocator>(() =>
|
||||
Application.Current.TryFindResource("Locator") as ViewModelLocator).Value;
|
||||
|
||||
#region Vm
|
||||
|
||||
Reference in new issue
Block a user