update ui

This commit is contained in:
bluepilledgreat 2025-01-23 00:42:08 +00:00
parent 88be992176
commit 978e03d940
10 changed files with 196 additions and 0 deletions

View File

@ -11,6 +11,7 @@
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Dark" /> <ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary /> <ui:ControlsDictionary />
<ResourceDictionary x:Name="CustomTheme" Source="UI/Style/Dark.xaml" /> <!-- NOTE: WpfUiWindow::ApplyTheme relies on this order. If you plan to change the order, please update the index in the function. -->
<ResourceDictionary x:Name="Default" Source="UI/Style/Default.xaml" /> <ResourceDictionary x:Name="Default" Source="UI/Style/Default.xaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>

View File

@ -25,6 +25,8 @@
<Resource Include="Resources\MessageBox\Information.png" /> <Resource Include="Resources\MessageBox\Information.png" />
<Resource Include="Resources\MessageBox\Question.png" /> <Resource Include="Resources\MessageBox\Question.png" />
<Resource Include="Resources\MessageBox\Warning.png" /> <Resource Include="Resources\MessageBox\Warning.png" />
<EmbeddedResource Include="UI\Style\Editor-Theme-Dark.xshd" />
<EmbeddedResource Include="UI\Style\Editor-Theme-Light.xshd" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -18,9 +18,15 @@ namespace Bloxstrap.UI.Elements.Base
public void ApplyTheme() public void ApplyTheme()
{ {
const int customThemeIndex = 2; // index for CustomTheme merged dictionary
_themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light); _themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light);
_themeService.SetSystemAccent(); _themeService.SetSystemAccent();
// there doesn't seem to be a way to query the name for merged dictionaries
var dict = new ResourceDictionary { Source = new Uri($"pack://application:,,,/UI/Style/{Enum.GetName(App.Settings.Prop.Theme.GetFinal())}.xaml") };
Application.Current.Resources.MergedDictionaries[customThemeIndex] = dict;
#if QA_BUILD #if QA_BUILD
this.BorderBrush = System.Windows.Media.Brushes.Red; this.BorderBrush = System.Windows.Media.Brushes.Red;
this.BorderThickness = new Thickness(4); this.BorderThickness = new Thickness(4);

View File

@ -39,6 +39,7 @@
Grid.Row="1" Grid.Row="1"
Margin="10,10,10,0" Margin="10,10,10,0"
ShowLineNumbers="True" ShowLineNumbers="True"
Style="{StaticResource NewTextEditor}"
SyntaxHighlighting="XML" SyntaxHighlighting="XML"
TextChanged="OnCodeChanged" /> TextChanged="OnCodeChanged" />

View File

@ -1,8 +1,11 @@
using System.Windows.Input; using System.Windows.Input;
using System.Xml;
using ICSharpCode.AvalonEdit.CodeCompletion; using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.AvalonEdit.Highlighting;
using Bloxstrap.UI.Elements.Base; using Bloxstrap.UI.Elements.Base;
using Bloxstrap.UI.ViewModels.Editor; using Bloxstrap.UI.ViewModels.Editor;
@ -146,6 +149,18 @@ namespace Bloxstrap.UI.Elements.Editor
UIXML.Text = viewModel.Code; UIXML.Text = viewModel.Code;
UIXML.TextArea.TextEntered += OnTextAreaTextEntered; UIXML.TextArea.TextEntered += OnTextAreaTextEntered;
LoadHighlightingTheme();
}
private void LoadHighlightingTheme()
{
string name = $"Editor-Theme-{App.Settings.Prop.Theme.GetFinal()}.xshd";
using Stream xmlStream = Resource.GetStream(name);
using XmlReader reader = XmlReader.Create(xmlStream);
UIXML.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
UIXML.TextArea.TextView.SetResourceReference(ICSharpCode.AvalonEdit.Rendering.TextView.LinkTextForegroundBrushProperty, "NewTextEditorLink");
} }
private static string ToCRLF(string text) private static string ToCRLF(string text)

View File

@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="NewTextEditorBackground" Color="#2D2D2D" />
<SolidColorBrush x:Key="NewTextEditorForeground" Color="White" />
<SolidColorBrush x:Key="NewTextEditorLink" Color="#3A9CEA" />
</ResourceDictionary>

View File

@ -1,6 +1,7 @@
<ResourceDictionary <ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"> xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">
<!-- Taken from DefaultUiCardExpanderStyle --> <!-- Taken from DefaultUiCardExpanderStyle -->
@ -151,4 +152,38 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<!-- Taken from https://github.com/icsharpcode/AvalonEdit/blob/30cad99ce905412ed5f5e847e3c00e72e69aee77/ICSharpCode.AvalonEdit/TextEditor.xaml -->
<Style x:Key="NewTextEditor" TargetType="{x:Type avalonedit:TextEditor}">
<Setter Property="Foreground" Value="{DynamicResource NewTextEditorForeground}" />
<Setter Property="Background" Value="{DynamicResource NewTextEditorBackground}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type avalonedit:TextEditor}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4">
<ScrollViewer
Name="PART_ScrollViewer"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="Left"
VerticalContentAlignment="Top"
CanContentScroll="True"
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TextArea}"
Focusable="False"
HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="WordWrap" Value="True">
<Setter TargetName="PART_ScrollViewer" Property="HorizontalScrollBarVisibility" Value="Disabled" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary> </ResourceDictionary>

View File

@ -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="#529955" name="Comment" exampleText="&lt;!-- comment --&gt;" />
<Color foreground="White" name="CData" exampleText="&lt;![CDATA[data]]&gt;" />
<Color foreground="White" name="DocType" exampleText="&lt;!DOCTYPE rootElement&gt;" />
<Color foreground="White" name="XmlDeclaration" exampleText='&lt;?xml version="1.0"?&gt;' />
<Color foreground="#569CD6" name="XmlTag" exampleText='&lt;tag attribute="value" /&gt;' />
<Color foreground="#9CDCFE" name="AttributeName" exampleText='&lt;tag attribute="value" /&gt;' />
<Color foreground="#CE9178" name="AttributeValue" exampleText='&lt;tag attribute="value" /&gt;' />
<Color foreground="White" name="Entity" exampleText="index.aspx?a=1&amp;amp;b=2" />
<Color foreground="White" name="BrokenEntity" exampleText="index.aspx?a=1&amp;b=2" />
<RuleSet>
<Span color="Comment" multiline="true">
<Begin>&lt;!--</Begin>
<End>--&gt;</End>
</Span>
<Span color="CData" multiline="true">
<Begin>&lt;!\[CDATA\[</Begin>
<End>]]&gt;</End>
</Span>
<Span color="DocType" multiline="true">
<Begin>&lt;!DOCTYPE</Begin>
<End>&gt;</End>
</Span>
<Span color="XmlDeclaration" multiline="true">
<Begin>&lt;\?</Begin>
<End>\?&gt;</End>
</Span>
<Span color="XmlTag" multiline="true">
<Begin>&lt;</Begin>
<End>&gt;</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>"|(?=&lt;)</End>
</Span>
<Span color="AttributeValue" multiline="true" ruleSet="EntitySet">
<Begin>'</Begin>
<End>'|(?=&lt;)</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">
&amp;
[\w\d\#]+
;
</Rule>
<Rule color="BrokenEntity">
&amp;
[\w\d\#]*
#missing ;
</Rule>
</RuleSet>
</SyntaxDefinition>

View File

@ -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="&lt;!-- comment --&gt;" />
<Color foreground="Blue" name="CData" exampleText="&lt;![CDATA[data]]&gt;" />
<Color foreground="Blue" name="DocType" exampleText="&lt;!DOCTYPE rootElement&gt;" />
<Color foreground="Blue" name="XmlDeclaration" exampleText='&lt;?xml version="1.0"?&gt;' />
<Color foreground="DarkMagenta" name="XmlTag" exampleText='&lt;tag attribute="value" /&gt;' />
<Color foreground="Red" name="AttributeName" exampleText='&lt;tag attribute="value" /&gt;' />
<Color foreground="Blue" name="AttributeValue" exampleText='&lt;tag attribute="value" /&gt;' />
<Color foreground="Teal" name="Entity" exampleText="index.aspx?a=1&amp;amp;b=2" />
<Color foreground="Olive" name="BrokenEntity" exampleText="index.aspx?a=1&amp;b=2" />
<RuleSet>
<Span color="Comment" multiline="true">
<Begin>&lt;!--</Begin>
<End>--&gt;</End>
</Span>
<Span color="CData" multiline="true">
<Begin>&lt;!\[CDATA\[</Begin>
<End>]]&gt;</End>
</Span>
<Span color="DocType" multiline="true">
<Begin>&lt;!DOCTYPE</Begin>
<End>&gt;</End>
</Span>
<Span color="XmlDeclaration" multiline="true">
<Begin>&lt;\?</Begin>
<End>\?&gt;</End>
</Span>
<Span color="XmlTag" multiline="true">
<Begin>&lt;</Begin>
<End>&gt;</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>"|(?=&lt;)</End>
</Span>
<Span color="AttributeValue" multiline="true" ruleSet="EntitySet">
<Begin>'</Begin>
<End>'|(?=&lt;)</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">
&amp;
[\w\d\#]+
;
</Rule>
<Rule color="BrokenEntity">
&amp;
[\w\d\#]*
#missing ;
</Rule>
</RuleSet>
</SyntaxDefinition>

View File

@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="NewTextEditorBackground" Color="White" />
<SolidColorBrush x:Key="NewTextEditorForeground" Color="Black" />
<SolidColorBrush x:Key="NewTextEditorLink" Color="Blue" />
</ResourceDictionary>