Skip to content

Commit

Permalink
Merge pull request #110 from atc-net/feature/Improve-JsonViewer
Browse files Browse the repository at this point in the history
Feature/improve json viewer
  • Loading branch information
davidkallesen authored Feb 22, 2024
2 parents 8b95c1b + 2b54975 commit 64efd22
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Orientation="Horizontal" />

<atc:LabelComboBox
InformationText="This is a help text.."
InformationText="This is a help text..."
IsMandatory="True"
Items="{Binding Source={atc:EnumToKeyValueBindingSource {x:Type wpf:ControlSizeType}, KeyAsString=True, IncludeDefault=True}}"
LabelText="MyLabel2"
Expand Down
12 changes: 12 additions & 0 deletions src/Atc.Wpf.Controls/BaseControls/ImageButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public string SvgImageSource
set => SetValue(ImageSourceProperty, value);
}

public static readonly DependencyProperty SvgImageOverrideColorProperty = DependencyProperty.Register(
nameof(SvgImageOverrideColor),
typeof(Color?),
typeof(ImageButton),
new PropertyMetadata(default(Color?)));

public Color? SvgImageOverrideColor
{
get => (Color?)GetValue(SvgImageOverrideColorProperty);
set => SetValue(SvgImageOverrideColorProperty, value);
}

public static readonly DependencyProperty RowIndexProperty = DependencyProperty.Register(
nameof(RowIndex),
typeof(int),
Expand Down
1 change: 1 addition & 0 deletions src/Atc.Wpf.Controls/BaseControls/ImageButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
Margin="{Binding Path=ImageLocation, RelativeSource={RelativeSource AncestorType=baseControls:ImageButton}, Converter={StaticResource ImageLocationToMarginValueConverter}}"
ControlSizeType="ContentToSizeNoStretch"
IsEnabled="{Binding Path=IsEnabled, RelativeSource={RelativeSource AncestorType=baseControls:ImageButton}}"
OverrideColor="{Binding Path=SvgImageOverrideColor, RelativeSource={RelativeSource AncestorType=baseControls:ImageButton}}"
Source="{Binding Path=SvgImageSource, RelativeSource={RelativeSource AncestorType=baseControls:ImageButton}}"
Visibility="Collapsed" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ public static bool TryParseUsingCurrentUiCulture(
return false;
}

public static bool TryParseUsingCurrentUiCulture(
string dateValue,
string timeValue,
out DateTime result)
{
result = DateTime.MinValue;
if (!string.IsNullOrWhiteSpace(dateValue) &&
!string.IsNullOrWhiteSpace(timeValue) &&
DateTime.TryParse(
$"{dateValue} {timeValue}",
Thread.CurrentThread.CurrentUICulture.DateTimeFormat,
DateTimeStyles.None,
out var resShort))
{
result = resShort;
return true;
}

return false;
}

public static bool HandlePrerequisiteForOnTextTimeChanged(
TextBox control,
TextChangedEventArgs e)
Expand Down
46 changes: 31 additions & 15 deletions src/Atc.Wpf.Controls/LabelControls/LabelDatePicker.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable ConvertIfStatementToSwitchStatement
namespace Atc.Wpf.Controls.LabelControls;

/// <summary>
Expand Down Expand Up @@ -273,30 +274,45 @@ private static void ValidateText(
return;
}

if (!control.IsMandatory &&
string.IsNullOrWhiteSpace(control.Text))
{
control.ValidationText = string.Empty;
if (raiseEvents)
{
OnLostFocusFireValidEvent(control, e);
}

return;
}

if (DateTimeTextBoxHelper.TryParseUsingCurrentUiCulture(
control.SelectedDateFormat,
control.Text,
out _))
{
control.ValidationText = string.Empty;
OnLostFocusFireValidEvent(control, e);
}
else
{
control.ValidationText = control.SelectedDateFormat == DatePickerFormat.Short
? string.Format(
CultureInfo.CurrentUICulture,
Validations.InvalidDate1,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern)
: string.Format(
CultureInfo.CurrentUICulture,
Validations.InvalidDate1,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.LongDatePattern);

if (raiseEvents)
{
OnLostFocusFireInvalidEvent(control, e);
OnLostFocusFireValidEvent(control, e);
}

return;
}

control.ValidationText = control.SelectedDateFormat == DatePickerFormat.Short
? string.Format(
CultureInfo.CurrentUICulture,
Validations.InvalidDate1,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern)
: string.Format(
CultureInfo.CurrentUICulture,
Validations.InvalidDate1,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.LongDatePattern);

if (raiseEvents)
{
OnLostFocusFireInvalidEvent(control, e);
}
}

Expand Down
63 changes: 40 additions & 23 deletions src/Atc.Wpf.Controls/LabelControls/LabelDateTimePicker.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable InvertIf
// ReSharper disable ConvertIfStatementToSwitchStatement
namespace Atc.Wpf.Controls.LabelControls;

/// <summary>
Expand Down Expand Up @@ -82,7 +83,7 @@ public DateTime? SelectedDate
nameof(SelectedDateFormat),
typeof(DatePickerFormat),
typeof(LabelDateTimePicker),
new PropertyMetadata(defaultValue: DatePickerFormat.Long));
new PropertyMetadata(defaultValue: DatePickerFormat.Short));

public DatePickerFormat SelectedDateFormat
{
Expand Down Expand Up @@ -253,8 +254,8 @@ private void OnTextDateChanged(
var control = (TextBox)sender;

if (DateTimeTextBoxHelper.TryParseUsingCurrentUiCulture(
SelectedDateFormat,
$"{control.Text} {TextTime}",
control.Text,
TextTime,
out var result))
{
SelectedDate = result;
Expand All @@ -277,8 +278,8 @@ private void OnTextTimeChanged(
}

if (DateTimeTextBoxHelper.TryParseUsingCurrentUiCulture(
SelectedDateFormat,
$"{TextDate} {control.Text}",
TextDate,
control.Text,
out var result))
{
SelectedDate = result;
Expand Down Expand Up @@ -347,32 +348,48 @@ private static void ValidateText(
return;
}

if (!control.IsMandatory &&
string.IsNullOrWhiteSpace(control.TextDate) &&
string.IsNullOrWhiteSpace(control.TextTime))
{
control.ValidationText = string.Empty;
if (raiseEvents)
{
OnLostFocusFireValidEvent(control, e);
}

return;
}

if (DateTimeTextBoxHelper.TryParseUsingCurrentUiCulture(
control.SelectedDateFormat,
control.TextDate,
control.TextTime,
out _))
{
control.ValidationText = string.Empty;
OnLostFocusFireValidEvent(control, e);
}
else
{
control.ValidationText = control.SelectedDateFormat == DatePickerFormat.Short
? string.Format(
CultureInfo.CurrentUICulture,
Validations.InvalidDate2,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern)
: string.Format(
CultureInfo.CurrentUICulture,
Validations.InvalidDate2,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.LongDatePattern,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern);

if (raiseEvents)
{
OnLostFocusFireInvalidEvent(control, e);
OnLostFocusFireValidEvent(control, e);
}

return;
}

control.ValidationText = control.SelectedDateFormat == DatePickerFormat.Short
? string.Format(
CultureInfo.CurrentUICulture,
Validations.InvalidDate2,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern)
: string.Format(
CultureInfo.CurrentUICulture,
Validations.InvalidDate2,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.LongDatePattern,
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern);

if (raiseEvents)
{
OnLostFocusFireInvalidEvent(control, e);
}
}

Expand Down
29 changes: 22 additions & 7 deletions src/Atc.Wpf.Controls/LabelControls/LabelTimePicker.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,36 @@ private static void ValidateText(
return;
}

if (!control.IsMandatory &&
string.IsNullOrWhiteSpace(control.Text))
{
control.ValidationText = string.Empty;
if (raiseEvents)
{
OnLostFocusFireValidEvent(control, e);
}

return;
}

if (DateTimeHelper.TryParseShortTimeUsingCurrentUiCulture(
control.Text,
out _))
{
control.ValidationText = string.Empty;
OnLostFocusFireValidEvent(control, e);
}
else
{
control.ValidationText = Validations.InvalidTime;

if (raiseEvents)
{
OnLostFocusFireInvalidEvent(control, e);
OnLostFocusFireValidEvent(control, e);
}

return;
}

control.ValidationText = Validations.InvalidTime;

if (raiseEvents)
{
OnLostFocusFireInvalidEvent(control, e);
}
}

Expand Down
48 changes: 33 additions & 15 deletions src/Atc.Wpf.Controls/Viewers/JsonViewer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:atc="https://github.com/atc-net/atc-wpf/tree/main/schemas"
xmlns:atcValueConverters="https://github.com/atc-net/atc-wpf/tree/main/schemas/value-converters"
xmlns:baseControls="clr-namespace:Atc.Wpf.Controls.BaseControls"
xmlns:controls="clr-namespace:Atc.Wpf.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:jLinq="clr-namespace:Newtonsoft.Json.Linq;assembly=Newtonsoft.Json"
Expand All @@ -21,6 +20,7 @@

<UserControl.Resources>

<atcValueConverters:MathSubtractValueConverter x:Key="MathSubtractValueConverter" />
<atcValueConverters:BoolToVisibilityVisibleValueConverter x:Key="BoolToVisibilityVisibleValueConverter" />
<valueConverters:MethodToValueConverter x:Key="MethodToValueConverter" />
<valueConverters:ComplexPropertyMethodToValueConverter x:Key="ComplexPropertyMethodToValueConverter" />
Expand Down Expand Up @@ -77,10 +77,16 @@
<TextBlock Foreground="{DynamicResource AtcApps.Brushes.Text}" Text=" : " />
<TextBlock Text=" " />
<TextBlock
Width="300"
Foreground="{Binding Converter={StaticResource JPropertyTypeToColorConverter}}"
Text="{Binding Path=Value, Converter={StaticResource JValueConverter}}"
TextWrapping="Wrap" />
TextWrapping="Wrap">
<TextBlock.Width>
<MultiBinding Converter="{StaticResource MathSubtractValueConverter}">
<Binding ElementName="UcJsonTreeViewer" Path="ActualWidth" />
<Binding Source="250" />
</MultiBinding>
</TextBlock.Width>
</TextBlock>
</StackPanel>
</DataTemplate>

Expand All @@ -107,10 +113,16 @@

<DataTemplate DataType="{x:Type jLinq:JValue}">
<TextBlock
Width="300"
Foreground="{Binding Converter={StaticResource JValueTypeToColorConverter}}"
Text="{Binding Converter={StaticResource JValueConverter}}"
TextWrapping="Wrap" />
TextWrapping="Wrap">
<TextBlock.Width>
<MultiBinding Converter="{StaticResource MathSubtractValueConverter}">
<Binding ElementName="UcJsonTreeViewer" Path="ActualWidth" />
<Binding Source="250" />
</MultiBinding>
</TextBlock.Width>
</TextBlock>
</DataTemplate>

</UserControl.Resources>
Expand All @@ -122,16 +134,20 @@
Orientation="Horizontal"
Spacing="10"
Visibility="{Binding Path=ShowActionAndInformationBar, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource BoolToVisibilityVisibleValueConverter}}">
<baseControls:ImageButton
Click="ExpandAll"
ImageLocation="Center"
SvgImageSource="/Atc.Wpf.Controls;component/Resources/Icons/expand.svg"
ToolTip="Expand All" />
<baseControls:ImageButton
Click="CollapseAll"
ImageLocation="Center"
SvgImageSource="/Atc.Wpf.Controls;component/Resources/Icons/collapse.svg"
ToolTip="Collapse All" />
<Button Click="ExpandAll" ToolTip="Expand All">
<atc:SvgImage
Width="16"
Height="16"
OverrideColor="DarkOrange"
Source="/Atc.Wpf.Controls;component/Resources/Icons/expand.svg" />
</Button>
<Button Click="CollapseAll" ToolTip="Collapse All">
<atc:SvgImage
Width="16"
Height="16"
OverrideColor="DarkOrange"
Source="/Atc.Wpf.Controls;component/Resources/Icons/collapse.svg" />
</Button>
<Border
Background="{x:Static controls:Constants.JTokenColorString}"
BorderBrush="{x:Static controls:Constants.JTokenColorString}"
Expand Down Expand Up @@ -222,6 +238,8 @@
ItemTemplateSelector="{StaticResource JPropertyDataTemplateSelector}">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="IsExpanded" Value="{Binding Path=StartExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, FallbackValue=False}" />
</Style>
</TreeView.ItemContainerStyle>
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Theming/Styles/BaseControls/ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
<Condition Property="IsEditable" Value="False" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource AtcApps.Brushes.Gray9}" />
<Setter Property="Background" Value="{DynamicResource AtcApps.Brushes.ThemeBackground1}" />
<Setter Property="BorderBrush" Value="{DynamicResource AtcApps.Brushes.ComboBox.Border.MouseOver}" />
</MultiTrigger>
<MultiTrigger>
Expand Down

0 comments on commit 64efd22

Please sign in to comment.