Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
PieroCastillo committed Feb 7, 2024
1 parent 258acf0 commit fe0139a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
4 changes: 2 additions & 2 deletions samples/Aura.UI.Gallery/Controls/CodeExample.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ using System;
BorderThickness="1" Padding="15"
Content="{TemplateBinding Control}"/>
<StackPanel Background="{DynamicResource SystemControlBackgroundBaseLowBrush}">
<ae:TextEditor Name="editor_xaml" SyntaxHighlighting="XML"
<ae:TextEditor Name="PART_editor_xaml" SyntaxHighlighting="XML"
HorizontalScrollBarVisibility="Auto"
Background="Transparent"
IsVisible="{TemplateBinding XAMLVisible}"
IsReadOnly="True"
Padding="15"/>
<ae:TextEditor Name="editor_csharp" SyntaxHighlighting="C#"
<ae:TextEditor Name="PART_editor_csharp" SyntaxHighlighting="C#"
HorizontalScrollBarVisibility="Auto"
Background="Transparent"
IsVisible="{TemplateBinding CSharpVisible}"
Expand Down
36 changes: 29 additions & 7 deletions samples/Aura.UI.Gallery/Controls/CodeExample.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
using System;
using Avalonia.Collections;
using Avalonia.LogicalTree;
using Avalonia.Controls.Metadata;
using TextMateSharp.Grammars;
using AvaloniaEdit.TextMate;
using Avalonia.Styling;

namespace Aura.UI.Gallery.Controls
{
[TemplatePart(Name = "PART_editor_xaml", Type = typeof(TextEditor))]
[TemplatePart(Name = "PART_editor_csharp", Type = typeof(TextEditor))]
public class CodeExample : TemplatedControl
{
static CodeExample()
{
ControlProperty.Changed.Subscribe(ControlChildChanged);
}
private TextEditor xaml_edit;
private TextEditor c_edit;

private static void ControlChildChanged(AvaloniaPropertyChangedEventArgs e)
{
Expand All @@ -39,14 +43,32 @@ private static void ControlChildChanged(AvaloniaPropertyChangedEventArgs e)
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
this.GetControl(e, "PART_editor_csharp", out TextEditor editor_csharp);
this.GetControl(e, "PART_editor_xaml", out TextEditor editor_xaml);

xaml_edit = this.GetControl<TextEditor>(e, "editor_xaml");
c_edit = this.GetControl<TextEditor>(e, "editor_csharp");
editor_xaml.Text = XAMLText;
editor_csharp.Text = CSharpText;

c_edit.TextArea.IndentationStrategy = new CSharpIndentationStrategy();
editor_xaml.ShowLineNumbers = true;
editor_csharp.ShowLineNumbers = true;

xaml_edit.Text = XAMLText;
c_edit.Text = CSharpText;
RegistryOptions _registryOptions;
if (App.Current.RequestedThemeVariant == ThemeVariant.Light)
{
_registryOptions = new RegistryOptions(ThemeName.Light);
}
else
{
_registryOptions = new RegistryOptions(ThemeName.Dark);
}


//Initial setup of TextMate.
var _textMateCSharp = editor_csharp.InstallTextMate(_registryOptions);
_textMateCSharp.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(".cs").Id));

var _textMateXaml = editor_xaml.InstallTextMate(_registryOptions);
_textMateXaml.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(".axaml").Id));
}

[Content]
Expand Down
4 changes: 2 additions & 2 deletions samples/Aura.UI.Gallery/Pages/BadgePage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<CodeExample Title="Badge" TitleTwo="RightTop" CSharpVisible="False">
<Badge BadgePosition="RightTop" BadgeContent="9+">
<Button Content="Messages"/>
</Badge>
<CodeExample.XAMLText>
</Badge>
<CodeExample.XAMLText>
&lt;Badge BadgePosition="RightTop" BadgeContent="9+">
&lt;Button Content="Messages"/>
&lt;/Badge>
Expand Down
2 changes: 1 addition & 1 deletion samples/Aura.UI.Gallery/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Control Build(object data)
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);

if (type != null)
if (type != null)
{
return (Control)Activator.CreateInstance(type)!;
}
Expand Down
2 changes: 1 addition & 1 deletion samples/Aura.UI.Gallery/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</GroupBox>
</NavigationViewItem.Content>
</NavigationViewItem>
<Separator/>
<!--<Separator/>-->
<NavigationViewItem Header="Basic Input" Title="Basic Input"
Icon="{DynamicResource FontAwesome.CheckSquareRegular}">
<NavigationViewItem.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
x:Key="LevelConv" />

</Styles.Resources>
<Style Selector="NavigationViewItemBase">
<Style Selector=":is(NavigationViewItemBase)">
<Setter Property="Padding" Value="0 5" />
<Setter Property="MinWidth" Value="0" />
<Setter Property="DockPanel.Dock" Value="Top" />
Expand Down Expand Up @@ -129,7 +129,7 @@
</Style>


<Style Selector="NavigationViewItemBase /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector=":is(NavigationViewItemBase) /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
Expand Down

0 comments on commit fe0139a

Please sign in to comment.