Skip to content

Commit

Permalink
Merge pull request #125 from atc-net/feature/JsonFormatter
Browse files Browse the repository at this point in the history
Feature/json formatter
  • Loading branch information
davidkallesen authored Jun 13, 2024
2 parents 7e3f7f9 + 40eefb7 commit ca89959
Show file tree
Hide file tree
Showing 25 changed files with 789 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,62 @@
xmlns:atc="https://github.com/atc-net/atc-wpf/tree/main/schemas"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sourceCode="clr-namespace:Atc.Wpf.Controls.Documents.TextFormatters.SourceCode;assembly=Atc.Wpf"
xmlns:textFormatters="clr-namespace:Atc.Wpf.Controls.Documents.TextFormatters;assembly=Atc.Wpf"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">

<atc:AutoGrid Columns="*" Rows="Auto,*">
<Grid>
<GroupBox Header="Usage">
<TabControl>

<GroupBox
Margin="0,0,0,10"
Padding="10"
Header="Features" />
<TabItem Header=" XAML ">
<atc:RichTextBoxEx
Margin="5,10,5,5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{DynamicResource AtcApps.Brushes.ThemeBackground}"
FontFamily="Courier New"
Foreground="{DynamicResource AtcApps.Brushes.Text}"
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
Text="{Binding Path=DataContext.XamlCode, Mode=OneTime}"
TextFormatter="{x:Static textFormatters:XamlFormatter.Instance}"
VerticalScrollBarVisibility="Auto" />
</TabItem>

<GroupBox Header="Usage">
<ScrollViewer>
<atc:AutoGrid Columns="*" Rows="*,*">
<atc:AutoGrid Columns="*" Rows="Auto,*">
<TextBlock Text="XAML in RichTextBoxEx" />
<atc:RichTextBoxEx
Margin="5,10,5,5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{DynamicResource AtcApps.Brushes.ThemeBackground}"
FontFamily="Courier New"
Foreground="{DynamicResource AtcApps.Brushes.Text}"
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
Text="{Binding Path=DataContext.XamlCode, Mode=OneTime}"
TextFormatter="{x:Static sourceCode:XamlFormatter.Instance}"
VerticalScrollBarVisibility="Auto" />
</atc:AutoGrid>
<TabItem Header=" C# ">
<atc:RichTextBoxEx
Margin="5,10,5,5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{DynamicResource AtcApps.Brushes.ThemeBackground}"
FontFamily="Courier New"
Foreground="{DynamicResource AtcApps.Brushes.Text}"
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
Text="{Binding Path=DataContext.CSharpCode, Mode=OneTime}"
TextFormatter="{x:Static textFormatters:CSharpFormatter.Instance}"
VerticalScrollBarVisibility="Auto" />
</TabItem>

<TabItem Header=" JSON ">
<atc:RichTextBoxEx
Margin="5,10,5,5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{DynamicResource AtcApps.Brushes.ThemeBackground}"
FontFamily="Courier New"
Foreground="{DynamicResource AtcApps.Brushes.Text}"
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
Text="{Binding Path=DataContext.JsonText, Mode=OneTime}"
TextFormatter="{x:Static textFormatters:JsonFormatter.Instance}"
VerticalScrollBarVisibility="Auto" />
</TabItem>

<atc:AutoGrid Columns="*" Rows="Auto,*">
<TextBlock Text="C# code in RichTextBoxEx" />
<atc:RichTextBoxEx
Margin="5,10,5,5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{DynamicResource AtcApps.Brushes.ThemeBackground}"
FontFamily="Courier New"
Foreground="{DynamicResource AtcApps.Brushes.Text}"
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
Text="{Binding Path=DataContext.CSharpCode, Mode=OneTime}"
TextFormatter="{x:Static sourceCode:CSharpFormatter.Instance}"
VerticalScrollBarVisibility="Auto" />
</atc:AutoGrid>
</atc:AutoGrid>
</ScrollViewer>
</TabControl>
</GroupBox>
</atc:AutoGrid>
</Grid>

</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,72 @@ public RichTextBoxExView()
}

public static string XamlCode =>
@"<UserControl x:Class=""Atc.Wpf.Sample.SamplesWpf.Controls.GridExView""
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:atc=""https://github.com/atc-net/atc-wpf""
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
d:DesignHeight=""450""
d:DesignWidth=""800""
mc:Ignorable=""d"">
"""
<UserControl x:Class="Atc.Wpf.Sample.SamplesWpf.Controls.GridExView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:atc="https://github.com/atc-net/atc-wpf"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<atc:GridEx Margin="5"
Columns="*,*"
Rows="*,*">
<Rectangle Grid.Row="0"
Grid.Column="0"
Fill="Blue" />
<Rectangle Grid.Row="0"
Grid.Column="1"
Fill="Red" />
<Rectangle Grid.Row="1"
Grid.Column="0"
Fill="Green" />
<Rectangle Grid.Row="1"
Grid.Column="2"
Fill="Yellow" />
</atc:GridEx>
<atc:GridEx Margin=""5""
Columns=""*,*""
Rows=""*,*"">
</UserControl>
<Rectangle Grid.Row=""0""
Grid.Column=""0""
Fill=""Blue"" />
<Rectangle Grid.Row=""0""
Grid.Column=""1""
Fill=""Red"" />
<Rectangle Grid.Row=""1""
Grid.Column=""0""
Fill=""Green"" />
<Rectangle Grid.Row=""1""
Grid.Column=""2""
Fill=""Yellow"" />
</atc:GridEx>
</UserControl>
";
""";

public static string CSharpCode =>
@"namespace Atc.Wpf.Sample.SamplesWpf.Layouts
{
/// <summary>
/// Interaction logic for GridExView.
/// </summary>
public partial class GridExView
{
public GridExView()
"""
namespace Atc.Wpf.Sample.SamplesWpf.Layouts
{
this.InitializeComponent();
/// <summary>
/// Interaction logic for GridExView.
/// </summary>
public partial class GridExView
{
public GridExView()
{
this.InitializeComponent();
}
}
}
}
}";
""";

public static string JsonText =>
"""
{
"Application": {
"String": "Hallo world",
"Boolean": true,
"Integer": 27,
"Float": 5.5,
"Guid": "56EEDF56-3633-4BCF-9BF0-3AD69C9AE769",
"Uri": "https://google.com/",
"Date": "2000-10-31T01:30:00.000-05:00",
"Data": [
{ "Item": "Value1" },
{ "Item": "Value2" }
]
}
}
""";
}
5 changes: 4 additions & 1 deletion sample/Atc.Wpf.Sample/SamplesWpfControlsTreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
Header="ColorPicker"
IsExpanded="True"
SamplePath="BaseControls.ColorPickerView" />
<sample:SampleTreeViewItem Header="RichTextBoxEx" SamplePath="BaseControls.RichTextBoxExView" />
<sample:SampleTreeViewItem
Header="RichTextBoxEx"
IsExpanded="True"
SamplePath="BaseControls.RichTextBoxExView" />
</TreeViewItem>

<TreeViewItem Header="Color Controls">
Expand Down
8 changes: 4 additions & 4 deletions src/Atc.Wpf.Controls.Sample/SampleViewerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mdXaml="https://github.com/whistyun/MdXaml"
xmlns:sample="clr-namespace:Atc.Wpf.Controls.Sample"
xmlns:sourceCode="clr-namespace:Atc.Wpf.Controls.Documents.TextFormatters.SourceCode;assembly=Atc.Wpf"
xmlns:textFormatters="clr-namespace:Atc.Wpf.Controls.Documents.TextFormatters;assembly=Atc.Wpf"
x:Name="UcSampleViewerView"
d:DataContext="{d:DesignInstance Type=sample:SampleViewerViewModel}"
d:DesignHeight="450"
Expand Down Expand Up @@ -53,7 +53,7 @@
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
Text="{Binding Path=XamlCode}"
TextFormatter="{x:Static sourceCode:XamlFormatter.Instance}"
TextFormatter="{x:Static textFormatters:XamlFormatter.Instance}"
VerticalScrollBarVisibility="Auto" />
</TabItem>
<TabItem Header="CodeBehind" IsEnabled="{Binding Path=HasCodeBehindCode}">
Expand All @@ -67,7 +67,7 @@
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
Text="{Binding Path=CodeBehindCode}"
TextFormatter="{x:Static sourceCode:CSharpFormatter.Instance}"
TextFormatter="{x:Static textFormatters:CSharpFormatter.Instance}"
VerticalScrollBarVisibility="Auto" />
</TabItem>
<TabItem Header="ViewModel" IsEnabled="{Binding Path=HasViewModelCode}">
Expand All @@ -81,7 +81,7 @@
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
Text="{Binding Path=ViewModelCode}"
TextFormatter="{x:Static sourceCode:CSharpFormatter.Instance}"
TextFormatter="{x:Static textFormatters:CSharpFormatter.Instance}"
VerticalScrollBarVisibility="Auto" />
</TabItem>
<TabItem Header="Readme" IsEnabled="{Binding Path=HasReadmeMarkdown}">
Expand Down
5 changes: 4 additions & 1 deletion src/Atc.Wpf.Controls/BaseControls/RichTextBoxEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Atc.Wpf.Controls.BaseControls;
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "OK.")]
public class RichTextBoxEx : RichTextBox
{
/// <summary>
/// The ThemeMode property.
/// </summary>
public static readonly DependencyProperty ThemeModeProperty = DependencyProperty.Register(
nameof(ThemeMode),
typeof(ThemeMode),
Expand Down Expand Up @@ -77,7 +80,7 @@ public RichTextBoxEx(FlowDocument document)
}

/// <summary>
/// Gets or sets the text.
/// Gets or sets the ThemeMode.
/// </summary>
/// <value>
/// The text.
Expand Down
25 changes: 0 additions & 25 deletions src/Atc.Wpf.Controls/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,4 @@ namespace Atc.Wpf.Controls;
public static class Constants
{
public const string DefaultLabelControlLabel = "-Label-";

public const string JTokenHexColorString = "#4e9a06";
public const string JTokenHexColorFloat = "#ad7fa8";
public const string JTokenHexColorInteger = "#ad7fa8";
public const string JTokenHexColorBoolean = "#c4a000";
public const string JTokenHexColorDate = "#f4a000";
public const string JTokenHexColorGuid = "#f4af00";
public const string JTokenHexColorUri = "#f4a0f0";
public const string JTokenHexColorNull = "#ff6e00";

public static Brush JTokenColorString => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorString)!;

public static Brush JTokenColorFloat => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorFloat)!;

public static Brush JTokenColorInteger => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorInteger)!;

public static Brush JTokenColorBoolean => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorBoolean)!;

public static Brush JTokenColorDate => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorDate)!;

public static Brush JTokenColorGuid => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorGuid)!;

public static Brush JTokenColorUri => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorUri)!;

public static Brush JTokenColorNull => (Brush)new BrushConverter().ConvertFrom(JTokenHexColorNull)!;
}
1 change: 1 addition & 0 deletions src/Atc.Wpf.Controls/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
global using Atc.Wpf.Controls.BaseControls.Internal;
global using Atc.Wpf.Controls.ColorControls.Internal;
global using Atc.Wpf.Controls.Dialogs;
global using Atc.Wpf.Controls.Documents.ColorSchemas;
global using Atc.Wpf.Controls.Documents.TextFormatters;
global using Atc.Wpf.Controls.LabelControls;
global using Atc.Wpf.Controls.LabelControls.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ namespace Atc.Wpf.Controls.TemplateSelectors;

public sealed class JPropertyDataTemplateSelector : DataTemplateSelector
{
public DataTemplate? PrimitivePropertyTemplate { get; set; }

public DataTemplate? ComplexPropertyTemplate { get; set; }
public DataTemplate? ObjectPropertyTemplate { get; set; }

public DataTemplate? ArrayPropertyTemplate { get; set; }

public DataTemplate? ObjectPropertyTemplate { get; set; }
public DataTemplate? PrimitivePropertyTemplate { get; set; }

public override DataTemplate? SelectTemplate(
object? item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public sealed class ComplexPropertyMethodToValueConverter : IValueConverter
public object? Convert(
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture)
{
if (value == null || parameter is not string methodName)
Expand All @@ -19,15 +19,15 @@ public sealed class ComplexPropertyMethodToValueConverter : IValueConverter
return null;
}

var invocationResult = methodInfo.Invoke(value, Array.Empty<object>());
var invocationResult = methodInfo.Invoke(value, []);
var jTokens = (IEnumerable<JToken>)invocationResult!;
return jTokens.First().Children();
}

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture)
=> throw new NotSupportedException(GetType().Name + " can only be used for one way conversion.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Atc.Wpf.Controls.ValueConverters;
public sealed class JArrayLengthValueConverter : IValueConverter
{
public object Convert(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture)
{
if (value is not JToken jToken)
Expand All @@ -30,9 +30,9 @@ public object Convert(
}

public object ConvertBack(
object value,
object? value,
Type targetType,
object parameter,
object? parameter,
CultureInfo culture)
=> throw new NotSupportedException(GetType().Name + " can only be used for one way conversion.");
}
Loading

0 comments on commit ca89959

Please sign in to comment.