Skip to content

A Swiss Army knife for developers.

Added Json Formatter tool

Etienne Baudoux425897402509
diff --git a/src/dev/impl/DevTools.Common/DevTools.Common.csproj b/src/dev/impl/DevTools.Common/DevTools.Common.csproj
index 6b31f52c0..b770e056f 100644
--- a/src/dev/impl/DevTools.Common/DevTools.Common.csproj
+++ b/src/dev/impl/DevTools.Common/DevTools.Common.csproj
@@ -123,6 +123,9 @@
<Name>DevTools.Providers</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <PRIResource Include="Strings\en\JsonFormatter.resw" />
+ </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/src/dev/impl/DevTools.Common/LanguageManager.cs b/src/dev/impl/DevTools.Common/LanguageManager.cs
index e2fec57f0..1fb300655 100644
--- a/src/dev/impl/DevTools.Common/LanguageManager.cs
+++ b/src/dev/impl/DevTools.Common/LanguageManager.cs
@@ -22,6 +22,7 @@ namespace DevTools.Common
private static LanguageManager _languageManager;
private readonly Base64EncoderDecoderStrings _base64encoderdecoder = new Base64EncoderDecoderStrings();
+ private readonly JsonFormatterStrings _jsonformatter = new JsonFormatterStrings();
private readonly MainPageStrings _mainpage = new MainPageStrings();
private readonly SettingsStrings _settings = new SettingsStrings();
@@ -40,6 +41,11 @@ namespace DevTools.Common
/// </summary>
public Base64EncoderDecoderStrings Base64EncoderDecoder => _base64encoderdecoder;
+ /// <summary>
+ /// Gets the <see cref="JsonFormatterStrings"/>.
+ /// </summary>
+ public JsonFormatterStrings JsonFormatter => _jsonformatter;
+
/// <summary>
/// Gets the <see cref="MainPageStrings"/>.
/// </summary>
@@ -91,6 +97,16 @@ namespace DevTools.Common
public string DisplayName => _resources.GetString("DisplayName");
}
+ public class JsonFormatterStrings : ObservableObject
+ {
+ private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("DevTools.Common/JsonFormatter");
+
+ /// <summary>
+ /// Gets the resource DisplayName.
+ /// </summary>
+ public string DisplayName => _resources.GetString("DisplayName");
+ }
+
public class MainPageStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("DevTools.Common/MainPage");
diff --git a/src/dev/impl/DevTools.Common/Strings/en/JsonFormatter.resw b/src/dev/impl/DevTools.Common/Strings/en/JsonFormatter.resw
new file mode 100644
index 000000000..74f54e5fd
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/Strings/en/JsonFormatter.resw
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="DisplayName" xml:space="preserve">
+ <value>Json Formatter</value>
+ </data>
+</root>
\ No newline at end of file
diff --git a/src/dev/impl/DevTools.Common/Themes/Custom.xaml b/src/dev/impl/DevTools.Common/Themes/Custom.xaml
index bedad5ae3..38e44d6a4 100644
--- a/src/dev/impl/DevTools.Common/Themes/Custom.xaml
+++ b/src/dev/impl/DevTools.Common/Themes/Custom.xaml
@@ -7,4 +7,7 @@
<!-- Icons. Most of them are from https://github.com/microsoft/fluentui-system-icons/blob/master/icons.md -->
<x:String x:Key="EnterCompactOverlayPathIconData">M41.6339 8.13376C42.122 7.64561 42.122 6.85415 41.6339 6.36599C41.1457 5.87784 40.3543 5.87784 39.8661 6.36599L29.5002 16.732V7.25C29.5002 6.55964 28.9405 6 28.2502 6C27.5598 6 27.0002 6.55964 27.0002 7.25V19.75C27.0002 20.4404 27.5598 21 28.2502 21H40.75C41.4404 21 42 20.4404 42 19.75C42 19.0596 41.4404 18.5 40.75 18.5H31.2676L41.6339 8.13376ZM8.5 12.25C8.5 10.1789 10.1789 8.5 12.25 8.5H20.1346C20.825 8.5 21.3846 7.94036 21.3846 7.25C21.3846 6.55964 20.825 6 20.1346 6H12.25C8.79822 6 6 8.79822 6 12.25V35.75C6 39.2018 8.79822 42 12.25 42H35.75C39.2018 42 42 39.2018 42 35.75V27.8654C42 27.175 41.4404 26.6154 40.75 26.6154C40.0596 26.6154 39.5 27.175 39.5 27.8654V35.75C39.5 37.8211 37.8211 39.5 35.75 39.5H24V29.2499C24 26.3504 21.6495 23.9999 18.75 23.9999H8.5V12.25ZM8.5 26.4999H18.75C20.2688 26.4999 21.5 27.7311 21.5 29.2499V39.5H12.25C10.1789 39.5 8.5 37.8211 8.5 35.75V26.4999Z</x:String>
<x:String x:Key="ExitCompactOverlayPathIconData">M39.5 12.25C39.5 10.1789 37.8211 8.5 35.75 8.5H27.8654C27.175 8.5 26.6154 7.94036 26.6154 7.25C26.6154 6.55964 27.175 6 27.8654 6H35.75C39.2018 6 42 8.79822 42 12.25V35.75C42 39.2018 39.2018 42 35.75 42H12.25C8.79822 42 6 39.2018 6 35.75V27.8654C6 27.175 6.55964 26.6154 7.25 26.6154C7.94036 26.6154 8.5 27.175 8.5 27.8654V35.75C8.5 37.8211 10.1789 39.5 12.25 39.5H24V29.25C24 26.3505 26.3505 24 29.25 24H39.5V12.25ZM39.5 26.5H29.25C27.7312 26.5 26.5 27.7312 26.5 29.25V39.5H35.75C37.8211 39.5 39.5 37.8211 39.5 35.75V26.5ZM21 7.25C21 6.55964 20.4404 6 19.75 6H7.25015C6.55979 6 6.00015 6.55964 6.00015 7.25V19.75C6.00015 20.4404 6.55979 21 7.25015 21C7.94051 21 8.50015 20.4404 8.50015 19.75V10.2679L18.8661 20.6339C19.3543 21.122 20.1457 21.122 20.6339 20.6339C21.122 20.1457 21.122 19.3543 20.6339 18.8661L10.2678 8.5H19.75C20.4404 8.5 21 7.94036 21 7.25Z</x:String>
+
+ <x:String x:Key="Base64EncoderDecoderToolProvider">M 0.008 0.008 L 0.008 31.992 L 31.992 31.992 L 31.992 0.008 Z M 2.916 2.916 L 29.084 2.916 L 29.084 29.084 L 2.916 29.084 Z M 11.957 10.094 L 8.777 13.774 C 7.823 14.87 7.276 16.273 7.276 17.727 L 7.276 18.18 C 7.276 20.169 8.924 21.816 10.912 21.816 L 12.366 21.816 C 14.353 21.816 16 20.169 16 18.18 C 16 16.193 14.353 14.546 12.366 14.546 L 11.957 14.546 L 14.137 12.002 Z M 21.816 10.184 L 21.816 14.546 L 20.362 14.546 L 20.362 10.231 L 17.454 10.231 L 17.454 17.454 L 21.816 17.454 L 21.816 21.816 L 24.722 21.816 L 24.722 10.184 Z M 10.276 17.454 L 12.366 17.454 C 12.781 17.454 13.092 17.766 13.092 18.18 C 13.092 18.595 12.781 18.908 12.366 18.908 L 10.912 18.908 C 10.497 18.908 10.184 18.595 10.184 18.18 L 10.184 17.727 C 10.184 17.629 10.264 17.55 10.276 17.454 Z</x:String>
+ <x:String x:Key="JsonFormatterToolProvider">M 9.5703125 4 C 5.9553125 4 4.4385 5.3040312 4.4375 8.4570312 L 4.4375 10.648438 C 4.4375 12.498437 3.9412656 13.115234 2.4472656 13.115234 L 2.4472656 16.398438 C 3.9402656 16.398437 4.4375 17.014563 4.4375 18.851562 L 4.4375 21.435547 C 4.4375 24.660547 5.9673125 26 9.5703125 26 L 10.816406 26 L 10.816406 23.404297 L 10.283203 23.404297 C 8.3622031 23.404297 7.7460938 22.835328 7.7460938 20.986328 L 7.7460938 17.904297 C 7.7460938 16.091297 6.8912969 15.024141 5.2792969 14.869141 L 5.2792969 14.65625 C 6.9632969 14.50225 7.7460938 13.578656 7.7460938 11.847656 L 7.7460938 9.0371094 C 7.7460938 7.1761094 8.3512031 6.6074219 10.283203 6.6074219 L 10.816406 6.6074219 L 10.816406 4 L 9.5703125 4 z M 19.183594 4 L 19.183594 6.6074219 L 19.716797 6.6074219 C 21.648797 6.6074219 22.253906 7.1761094 22.253906 9.0371094 L 22.253906 11.847656 C 22.253906 13.577656 23.037703 14.50225 24.720703 14.65625 L 24.720703 14.871094 C 23.107703 15.025094 22.253906 16.090297 22.253906 17.904297 L 22.253906 20.986328 C 22.253906 22.835328 21.636797 23.404297 19.716797 23.404297 L 19.183594 23.404297 L 19.183594 26.001953 L 20.429688 26.001953 C 24.033688 26.001953 25.5625 24.6615 25.5625 21.4375 L 25.5625 18.853516 C 25.5625 17.015516 26.058734 16.398438 27.552734 16.398438 L 27.552734 13.115234 C 26.059734 13.115234 25.5625 12.499391 25.5625 10.650391 L 25.5625 8.4570312 C 25.5625 5.3040312 24.044687 4 20.429688 4 L 19.183594 4 z</x:String>
</ResourceDictionary>
diff --git a/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs b/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
index f0e517f19..63038deb2 100644
--- a/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
+++ b/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
@@ -260,6 +260,7 @@ namespace DevTools.Impl.ViewModels
{
if (!snapshot.Contains(item.Key))
{
+ // TODO: Use Insert instead of Add so we can insert the item in the right order it deserves.
ToolsMenuItems.Add(item.Key);
}
diff --git a/src/dev/impl/DevTools.Providers.Impl/DevTools.Providers.Impl.csproj b/src/dev/impl/DevTools.Providers.Impl/DevTools.Providers.Impl.csproj
index 3b7122a27..cdc3fcd69 100644
--- a/src/dev/impl/DevTools.Providers.Impl/DevTools.Providers.Impl.csproj
+++ b/src/dev/impl/DevTools.Providers.Impl/DevTools.Providers.Impl.csproj
@@ -76,6 +76,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ToolProviderFactory.cs" />
<Compile Include="Tools\Base64EncoderDecoder\Base64EncoderDecoderToolProvider.cs" />
+ <Compile Include="Tools\JsonFormatter\JsonFormatterToolProvider.cs" />
<Compile Include="Tools\ToolProviderBase.cs" />
</ItemGroup>
<ItemGroup>
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolProvider.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolProvider.cs
index 1bdc15fd6..3f350e036 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolProvider.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolProvider.cs
@@ -21,9 +21,7 @@ namespace DevTools.Providers.Impl.Tools.Base64EncoderDecoder
public Base64EncoderDecoderToolProvider(IThread thread)
: base(thread)
{
- IconSource
- = CreatePathIconFromPath(
- "M 0.008 0.008 L 0.008 31.992 L 31.992 31.992 L 31.992 0.008 Z M 2.916 2.916 L 29.084 2.916 L 29.084 29.084 L 2.916 29.084 Z M 11.957 10.094 L 8.777 13.774 C 7.823 14.87 7.276 16.273 7.276 17.727 L 7.276 18.18 C 7.276 20.169 8.924 21.816 10.912 21.816 L 12.366 21.816 C 14.353 21.816 16 20.169 16 18.18 C 16 16.193 14.353 14.546 12.366 14.546 L 11.957 14.546 L 14.137 12.002 Z M 21.816 10.184 L 21.816 14.546 L 20.362 14.546 L 20.362 10.231 L 17.454 10.231 L 17.454 17.454 L 21.816 17.454 L 21.816 21.816 L 24.722 21.816 L 24.722 10.184 Z M 10.276 17.454 L 12.366 17.454 C 12.781 17.454 13.092 17.766 13.092 18.18 C 13.092 18.595 12.781 18.908 12.366 18.908 L 10.912 18.908 C 10.497 18.908 10.184 18.595 10.184 18.18 L 10.184 17.727 C 10.184 17.629 10.264 17.55 10.276 17.454 Z");
+ IconSource = CreatePathIconFromPath(nameof(Base64EncoderDecoderToolProvider));
}
public bool CanBeTreatedByTool(string data)
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolProvider.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolProvider.cs
new file mode 100644
index 000000000..67693128b
--- /dev/null
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolProvider.cs
@@ -0,0 +1,38 @@
+#nullable enable
+
+using DevTools.Core.Threading;
+using DevTools.Common;
+using System;
+using System.Composition;
+using Windows.ApplicationModel.DataTransfer;
+
+namespace DevTools.Providers.Impl.Tools.JsonFormatter
+{
+ [Export(typeof(IToolProvider))]
+ [Name("Json Formatter")]
+ [ProtocolName("jsonformat")]
+ [Order(0)]
+ internal sealed class JsonFormatterToolProvider : ToolProviderBase, IToolProvider
+ {
+ public string DisplayName => LanguageManager.Instance.JsonFormatter.DisplayName;
+
+ public object IconSource { get; }
+
+ [ImportingConstructor]
+ public JsonFormatterToolProvider(IThread thread)
+ : base(thread)
+ {
+ IconSource = CreatePathIconFromPath(nameof(JsonFormatterToolProvider));
+ }
+
+ public bool CanBeTreatedByTool(string data)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IToolViewModel CreateTool()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/ToolProviderBase.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/ToolProviderBase.cs
index ca0280e73..f96864752 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/ToolProviderBase.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/ToolProviderBase.cs
@@ -4,6 +4,7 @@ using DevTools.Core;
using DevTools.Core.Threading;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System.Threading.Tasks;
+using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
@@ -21,12 +22,16 @@ namespace DevTools.Providers.Impl.Tools
_thread = Arguments.NotNull(thread, nameof(thread));
}
- protected TaskCompletionNotifier<IconElement> CreatePathIconFromPath(string pathMarkup)
+ protected TaskCompletionNotifier<IconElement> CreatePathIconFromPath(string resourceName)
{
+ Arguments.NotNullOrWhiteSpace(resourceName, nameof(resourceName));
+
return new TaskCompletionNotifier<IconElement>(
_thread,
_thread.RunOnUIThreadAsync(() =>
{
+ string? pathMarkup = Application.Current.Resources[resourceName] as string;
+ Assumes.NotNullOrWhiteSpace(pathMarkup, nameof(pathMarkup));
return Task.FromResult<IconElement>(new PathIcon
{
Data = (Geometry)XamlBindingHelper.ConvertValue(typeof(Geometry), pathMarkup)