diff --git a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj index ca67dc56..c4dd0e8a 100644 --- a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj +++ b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj @@ -426,6 +426,12 @@ Resources\fabric-icons.ttf + + Resources\xshd\CSharp-Dark.xshd + + + Resources\xshd\XML-Dark.xshd + Resources\Registry.txt diff --git a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj index 6166da8a..f3ea7b42 100644 --- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj +++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj @@ -428,6 +428,12 @@ Resources\fabric-icons.ttf + + Resources\xshd\CSharp-Dark.xshd + + + Resources\xshd\XML-Dark.xshd + Resources\Registry.txt diff --git a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs index 338898e1..989304b7 100644 --- a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs +++ b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs @@ -52,5 +52,7 @@ public static readonly string LangUpdated = nameof(LangUpdated); + public static readonly string SkinUpdated = nameof(SkinUpdated); + } } diff --git a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt index e01ca42f..085e6c30 100644 --- a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt +++ b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt @@ -28,7 +28,8 @@ var messageList = new List "NavigationWindow", "TouchDragMoveWindow", "DialogContainer", - "LangUpdated" + "LangUpdated", + "SkinUpdated" }; #> namespace HandyControlDemo.Data @@ -40,4 +41,4 @@ namespace HandyControlDemo.Data <#}#> } -} \ No newline at end of file +} diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems index 2d609b3b..2243a048 100644 --- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems +++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems @@ -40,6 +40,7 @@ + Avatar.xaml diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Themes/Basic/Colors/ColorsDark.xaml b/src/Shared/HandyControlDemo_Shared/Resources/Themes/Basic/Colors/ColorsDark.xaml index 46258ae5..05da8bdf 100644 --- a/src/Shared/HandyControlDemo_Shared/Resources/Themes/Basic/Colors/ColorsDark.xaml +++ b/src/Shared/HandyControlDemo_Shared/Resources/Themes/Basic/Colors/ColorsDark.xaml @@ -13,8 +13,8 @@ #ff929292 #2FFFFFFF #FFAAAAFF - #18FFFFFF + Transparent - \ No newline at end of file + diff --git a/src/Shared/HandyControlDemo_Shared/Resources/xshd/CSharp-Dark.xshd b/src/Shared/HandyControlDemo_Shared/Resources/xshd/CSharp-Dark.xshd new file mode 100644 index 00000000..f7383ffd --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/Resources/xshd/CSharp-Dark.xshd @@ -0,0 +1,310 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TODO + FIXME + + + HACK + UNDONE + + + + + + + \# + + + + (define|undef|if|elif|else|endif|line)\b + + + + // + + + + + + (region|endregion|error|warning|pragma)\b + + + + + + + ///(?!/) + + + + + + + + // + + + + /\* + \*/ + + + + " + " + + + + + + + + ' + ' + + + + + + + + @" + " + + + + + + + + \$" + " + + + + + + + + + + + + @[\w\d_]+ + + + + this + base + + + + as + is + new + sizeof + typeof + stackalloc + + + + true + false + + + + else + if + switch + case + default + do + for + foreach + in + while + lock + + + + break + continue + goto + return + + + + yield + partial + global + where + select + group + by + into + from + ascending + descending + orderby + let + join + on + equals + var + dynamic + await + + + + try + throw + catch + finally + + + + checked + unchecked + + + + fixed + unsafe + + + + bool + byte + char + decimal + double + enum + float + int + long + sbyte + short + struct + uint + ushort + ulong + + + + class + interface + delegate + object + string + void + + + + explicit + implicit + operator + + + + params + ref + out + + + + abstract + const + event + extern + override + readonly + sealed + static + virtual + volatile + async + + + + public + protected + private + internal + + + + namespace + using + + + + get + set + add + remove + + + + null + value + + + + nameof + + + + + \b + [\d\w_]+ # an identifier + (?=\s*\() # followed by ( + + + + + \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 + + + + [?,.;()\[\]{}+\-/%*<>^+~!|&]+ + + + diff --git a/src/Shared/HandyControlDemo_Shared/Resources/xshd/XML-Dark.xshd b/src/Shared/HandyControlDemo_Shared/Resources/xshd/XML-Dark.xshd new file mode 100644 index 00000000..72f67744 --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/Resources/xshd/XML-Dark.xshd @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + <!-- + --> + + + <!\[CDATA\[ + ]]> + + + <!DOCTYPE + > + + + <\? + \?> + + + < + > + + + + " + "|(?=<) + + + ' + '|(?=<) + + [\d\w_\-\.]+(?=(\s*=)) + = + + + + + + + + & + [\w\d\#]+ + ; + + + + & + [\w\d\#]* + #missing ; + + + diff --git a/src/Shared/HandyControlDemo_Shared/Tools/HighlightingProvider.cs b/src/Shared/HandyControlDemo_Shared/Tools/HighlightingProvider.cs new file mode 100644 index 00000000..48770e36 --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/Tools/HighlightingProvider.cs @@ -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(() => new HighlightingProvider()).Value; + + protected static readonly Lazy DefaultDefinition = new(() => HighlightingManager.Instance.GetDefinition("C#")); + + private static readonly Dictionary Providers = new(); + + protected Dictionary> 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> + { + ["XML"] = new(() => HighlightingManager.Instance.GetDefinition("XML")), + ["C#"] = new(() => DefaultDefinition.Value) + }; + } + } + + internal class HighlightingProviderDark : HighlightingProvider + { + protected override void InitDefinitions() + { + Definition = new Dictionary> + { + ["XML"] = new(() => LoadDefinition("XML-Dark")), + ["C#"] = new(() => LoadDefinition("CSharp-Dark")), + }; + } + } +} diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainContent.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainContent.xaml.cs index 3e779888..173ed9b6 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainContent.xaml.cs +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainContent.xaml.cs @@ -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(this, MessageToken.FullSwitch, FullSwitch); + Messenger.Default.Register(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