Skip to content

Commit

Permalink
Merge pull request #120 from atc-net/feature/Add-CopyToClipboad-on-Js…
Browse files Browse the repository at this point in the history
…onViewer

Feature/add copy to clipboad on json viewer
  • Loading branch information
davidkallesen authored Apr 26, 2024
2 parents 0c024aa + e4a1858 commit 2949ad7
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.146" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.149" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.24.0.89429" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="ControlzEx" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Controls.Sample/Atc.Wpf.Controls.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="MdXaml" Version="1.27.0" />
</ItemGroup>

Expand Down
7 changes: 6 additions & 1 deletion src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ItemGroup>
<None Remove="Resources\collapse.svg" />
<None Remove="Resources\expand.svg" />
<None Remove="Resources\Icons\clipboard.svg" />
<None Remove="Resources\Icons\color_palette.svg" />
<None Remove="Resources\Icons\file.svg" />
<None Remove="Resources\Icons\folder.svg" />
Expand All @@ -23,7 +24,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<Resource Include="Resources\Icons\clipboard.svg" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
18 changes: 18 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Icons/clipboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Miscellaneous.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Miscellaneous.da-DK.resx
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,13 @@
<data name="ApplicationSettings" xml:space="preserve">
<value>Applikationsindstillinger</value>
</data>
<data name="CollapseAll" xml:space="preserve">
<value>Skjul alle</value>
</data>
<data name="ExpandAll" xml:space="preserve">
<value>Udvid alle</value>
</data>
<data name="CopyToClipboard" xml:space="preserve">
<value>Kopier til udklipsholder</value>
</data>
</root>
9 changes: 9 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Miscellaneous.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,13 @@
<data name="ApplicationSettings" xml:space="preserve">
<value>Anwendungseinstellungen</value>
</data>
<data name="CollapseAll" xml:space="preserve">
<value>Alles reduzieren</value>
</data>
<data name="ExpandAll" xml:space="preserve">
<value>Alle erweitern</value>
</data>
<data name="CopyToClipboard" xml:space="preserve">
<value>In die Zwischenablage kopieren</value>
</data>
</root>
9 changes: 9 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Miscellaneous.resx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="CollapseAll" xml:space="preserve">
<value>Collapse All</value>
</data>
<data name="Color" xml:space="preserve">
<value>Color</value>
</data>
Expand All @@ -135,9 +138,15 @@
<data name="ColorPicker" xml:space="preserve">
<value>Color Picker</value>
</data>
<data name="CopyToClipboard" xml:space="preserve">
<value>Copy to Clipboard</value>
</data>
<data name="Country" xml:space="preserve">
<value>Country</value>
</data>
<data name="ExpandAll" xml:space="preserve">
<value>Expand All</value>
</data>
<data name="FieldIsRequired" xml:space="preserve">
<value>Field is required</value>
</data>
Expand Down
36 changes: 34 additions & 2 deletions src/Atc.Wpf.Controls/Viewers/JsonViewer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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/tree/main/schemas"
xmlns:atcTranslation="https://github.com/atc-net/atc-wpf/tree/main/schemas/translations"
xmlns:atcValueConverters="https://github.com/atc-net/atc-wpf/tree/main/schemas/value-converters"
xmlns:controls="clr-namespace:Atc.Wpf.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -134,14 +135,14 @@
Orientation="Horizontal"
Spacing="10"
Visibility="{Binding Path=ShowActionAndInformationBar, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource BoolToVisibilityVisibleValueConverter}}">
<Button Click="ExpandAll" ToolTip="Expand All">
<Button Click="ExpandAll" ToolTip="{atcTranslation:Resx ResxName=Atc.Wpf.Controls.Resources.Miscellaneous, Key=ExpandAll}">
<atc:SvgImage
Width="16"
Height="16"
OverrideColor="DarkOrange"
Source="/Atc.Wpf.Controls;component/Resources/Icons/expand.svg" />
</Button>
<Button Click="CollapseAll" ToolTip="Collapse All">
<Button Click="CollapseAll" ToolTip="{atcTranslation:Resx ResxName=Atc.Wpf.Controls.Resources.Miscellaneous, Key=CollapseAll}">
<atc:SvgImage
Width="16"
Height="16"
Expand Down Expand Up @@ -243,6 +244,37 @@
<Setter Property="IsExpanded" Value="{Binding Path=StartExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, FallbackValue=False}" />
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Click="ExpandAll" Header="{atcTranslation:Resx ResxName=Atc.Wpf.Controls.Resources.Miscellaneous, Key=ExpandAll}">
<MenuItem.Icon>
<atc:SvgImage
Width="16"
Height="16"
OverrideColor="DarkOrange"
Source="/Atc.Wpf.Controls;component/Resources/Icons/expand.svg" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Click="CollapseAll" Header="{atcTranslation:Resx ResxName=Atc.Wpf.Controls.Resources.Miscellaneous, Key=CollapseAll}">
<MenuItem.Icon>
<atc:SvgImage
Width="16"
Height="16"
OverrideColor="DarkOrange"
Source="/Atc.Wpf.Controls;component/Resources/Icons/collapse.svg" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Click="CopyToClipboard" Header="{atcTranslation:Resx ResxName=Atc.Wpf.Controls.Resources.Miscellaneous, Key=CopyToClipboard}">
<MenuItem.Icon>
<atc:SvgImage
Width="16"
Height="16"
Source="/Atc.Wpf.Controls;component/Resources/Icons/clipboard.svg" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</DockPanel>

Expand Down
8 changes: 8 additions & 0 deletions src/Atc.Wpf.Controls/Viewers/JsonViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ private static void OnDataChanged(
control.Load(jsonData);
}

private void CopyToClipboard(
object sender,
RoutedEventArgs e)
=> Clipboard.SetText(
string.IsNullOrEmpty(Data)
? "{ }"
: Data);

private void ExpandAll(
object sender,
RoutedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Theming/Atc.Wpf.Theming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="ControlzEx" version="6.0.0" />

<!-- Uncomment XAMLTools.MSBuild to run Tool for generating Themes-xaml files -->
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf/Atc.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<PackageReference Include="Atc" Version="2.0.472" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 17 additions & 1 deletion src/Atc.Wpf/Controls/Media/W3cSvg/Svg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public Svg(XmlNode svgTag, IExternalFileLoader externalFileLoader)

public Size Size { get; set; }

public Brush? Fill { get; set; }

public Brush? Stroke { get; set; }

public IExternalFileLoader? ExternalFileLoader { get; }

public Dictionary<string, Brush>? CustomBrushes
Expand Down Expand Up @@ -299,6 +303,18 @@ private List<Shape> Parse(XmlNode node)
SvgXmlUtil.AttrValue(node, "width", 300),
SvgXmlUtil.AttrValue(node, "height", 150));

var fill = node.Attributes?.GetNamedItem("fill");
if (fill?.Value is not null)
{
Fill = SolidColorBrushHelper.GetBrushFromString(fill.Value, GlobalizationConstants.EnglishCultureInfo);
}

var stroke = node.Attributes?.GetNamedItem("stroke");
if (stroke?.Value is not null)
{
Stroke = SolidColorBrushHelper.GetBrushFromString(stroke.Value, GlobalizationConstants.EnglishCultureInfo);
}

var lstElements = new List<Shape>();
if (node.Name != SvgTagConstants.Svg && node.Name != SvgTagConstants.Pattern)
{
Expand All @@ -307,7 +323,7 @@ private List<Shape> Parse(XmlNode node)

foreach (XmlNode childNode in node.ChildNodes)
{
Atc.Wpf.Controls.Media.W3cSvg.Shapes.Group.AddToList(this, lstElements, childNode, parent: null);
W3cSvg.Shapes.Group.AddToList(this, lstElements, childNode, parent: null);
}

return lstElements;
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf/Controls/Media/W3cSvg/SvgRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private GeometryDrawing NewDrawingItem(Shape shape, Geometry geometry)
}
else
{
geometryDrawing.Brush = shape.Fill.FillBrush(Svg, this, shape, shape.Opacity, geometry.Bounds);
geometryDrawing.Brush = Svg.Fill ?? shape.Fill.FillBrush(Svg, this, shape, shape.Opacity, geometry.Bounds);
if (OverrideColor is not null)
{
geometryDrawing.Brush = new SolidColorBrush(Color.FromArgb((byte)(255 * shape.Opacity), OverrideColor.Value.R, OverrideColor.Value.G, OverrideColor.Value.B));
Expand Down
8 changes: 4 additions & 4 deletions test/Atc.Wpf.Controls.Tests/Atc.Wpf.Controls.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<PackageReference Include="Atc.XUnit" Version="2.0.462" />
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="Atc.XUnit" Version="2.0.472" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions test/Atc.Wpf.Tests/Atc.Wpf.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<PackageReference Include="Atc.XUnit" Version="2.0.462" />
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="Atc.XUnit" Version="2.0.472" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions test/Atc.Wpf.Theming.Tests/Atc.Wpf.Theming.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<PackageReference Include="Atc.XUnit" Version="2.0.462" />
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="Atc.XUnit" Version="2.0.472" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.462" />
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="ControlzEx" Version="6.0.0" />
<PackageReference Include="CssParser" Version="1.3.0">
<NoWarn>NU1701</NoWarn>
Expand Down

0 comments on commit 2949ad7

Please sign in to comment.