Skip to content

A Swiss Army knife for developers.

Added test tool to test the UI.

Etienne Baudouxf6eeaef19d97
diff --git a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
index abdcdae8a..2d98a3372 100644
--- a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
+++ b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
@@ -30,6 +30,11 @@
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
+ <Compile Update="Tools\Test\Test.Designer.cs">
+ <DependentUpon>Test.resx</DependentUpon>
+ <DesignTime>True</DesignTime>
+ <AutoGen>True</AutoGen>
+ </Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Tools\Sample\Sample.resx">
@@ -40,6 +45,10 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
</EmbeddedResource>
+ <EmbeddedResource Update="Tools\Test\Test.resx">
+ <LastGenOutput>Test.Designer.cs</LastGenOutput>
+ <Generator>ResXFileCodeGenerator</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
@@ -51,12 +60,6 @@
<ItemGroup>
<PluginOutput Include="$(OutputPath)\**\*" />
</ItemGroup>
- <Copy
- SourceFiles="@(PluginOutput)"
- DestinationFolder="$(RepoRoot)bin\$(Configuration)\Plugins\DevToys.Tools"
- SkipUnchangedFiles="false"
- OverwriteReadOnlyFiles="true"
- Retries="10"
- RetryDelayMilliseconds="1000" />
+ <Copy SourceFiles="@(PluginOutput)" DestinationFolder="$(RepoRoot)bin\$(Configuration)\Plugins\DevToys.Tools" SkipUnchangedFiles="false" OverwriteReadOnlyFiles="true" Retries="10" RetryDelayMilliseconds="1000" />
</Target>
</Project>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/Tools/Test/Test.Designer.cs b/src/app/dev/DevToys.Tools/Tools/Test/Test.Designer.cs
new file mode 100644
index 000000000..18220a7af
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Test/Test.Designer.cs
@@ -0,0 +1,90 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace DevToys.Tools.Tools.Test {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Test {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Test() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DevToys.Tools.Tools.Test.Test", typeof(Test).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Test.
+ /// </summary>
+ internal static string AccessibleName {
+ get {
+ return ResourceManager.GetString("AccessibleName", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Test tool.
+ /// </summary>
+ internal static string Description {
+ get {
+ return ResourceManager.GetString("Description", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Test.
+ /// </summary>
+ internal static string ShortDisplayTitle {
+ get {
+ return ResourceManager.GetString("ShortDisplayTitle", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/Test/Test.resx b/src/app/dev/DevToys.Tools/Tools/Test/Test.resx
new file mode 100644
index 000000000..effc2c962
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Test/Test.resx
@@ -0,0 +1,129 @@
+<?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="AccessibleName" xml:space="preserve">
+ <value>Test</value>
+ </data>
+ <data name="Description" xml:space="preserve">
+ <value>Test tool</value>
+ </data>
+ <data name="ShortDisplayTitle" xml:space="preserve">
+ <value>Test</value>
+ </data>
+</root>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/Tools/Test/TestGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Test/TestGuiTool.cs
new file mode 100644
index 000000000..e67014c2f
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Test/TestGuiTool.cs
@@ -0,0 +1,231 @@
+#if DEBUG
+using DevToys.Api;
+using Newtonsoft.Json.Linq;
+
+namespace DevToys.Tools.Tools.Test;
+
+[Export(typeof(IGuiTool))] // Register this class as a tool with a GUI.
+[Name("Test")] // Internal tool name.
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons", // Font to use for the icon of the tool.
+ IconGlyph = '\uE670', // Icon glyph
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier), // Reference to the IResourceManagerAssemblyIdentifier containing the resource manager
+ ResourceManagerBaseName = "DevToys.Tools.Tools.Test.Test", // Full name to the .RESX.
+ ShortDisplayTitleResourceName = nameof(Test.ShortDisplayTitle), // Name of the resource in the .RESX for the title of the tool.
+ LongDisplayTitleResourceName = nameof(Test.ShortDisplayTitle),
+ DescriptionResourceName = nameof(Test.Description),
+ AccessibleNameResourceName = nameof(Test.AccessibleName))]
+[AcceptedDataTypeName(PredefinedCommonDataTypeNames.Json)] // Register this tool as supporting JSON from Smart Detection.
+[MenuPlacement(MenuPlacement.Footer)] // Place the tool in the footer of the menu
+internal sealed class TestGuiTool : IGuiTool
+{
+ private enum GridTestRow
+ {
+ Header,
+ Content,
+ Footer
+ }
+
+ private enum GridTestColumn
+ {
+ Left,
+ Right
+ }
+
+ private static readonly SettingDefinition<bool> DummyBooleanSetting
+ = new(name: nameof(DummyBooleanSetting), defaultValue: true);
+
+ public static readonly SettingDefinition<AvailableApplicationTheme> DummyListSetting
+ = new(name: nameof(DummyListSetting), defaultValue: AvailableApplicationTheme.Default);
+
+ private readonly ISettingsProvider _settingsProvider = null!;
+ private readonly IUIMultiLineTextInput _inputJsonEditor;
+
+ [ImportingConstructor]
+ public TestGuiTool(ISettingsProvider settingsProvider)
+ {
+ _settingsProvider = settingsProvider;
+ _inputJsonEditor = MultilineTextInput();
+ _inputJsonEditor.TextChanged += InputJsonEditor_TextChanged;
+ }
+
+ public UIToolView View
+ => new(
+ isScrollable: false, // This tool is non-scrollable.
+
+ Grid()
+ .ColumnLargeSpacing()
+ .RowLargeSpacing()
+
+ // Grid has 3 rows. One fit its content. One takes all the space available. One is 150px of height.
+ .Rows(
+ (GridTestRow.Header, Auto),
+ (GridTestRow.Content, new UIGridLength(1, UIGridUnitType.Fraction)),
+ (GridTestRow.Footer, 150))
+
+ // Grid has 2 columns. One takes 2/3 of the space. One takes 1/3 of the space.
+ .Columns(
+ (GridTestColumn.Left, new UIGridLength(2, UIGridUnitType.Fraction)),
+ (GridTestColumn.Right, new UIGridLength(1, UIGridUnitType.Fraction)))
+
+ .Cells(
+ // Cell that is at the top left in the grid.
+ Cell(
+ GridTestRow.Header,
+ GridTestColumn.Left,
+
+ Stack()
+ .Vertical()
+
+ .WithChildren(
+ // Allow the user to import PNG, JPG, JPEG or BMP files.
+ FileSelector()
+ .CanSelectManyFiles()
+ .LimitFileTypesTo("png", ".jpg", "*.jpeg", "BMP")
+ .OnFilesSelected(OnFilesSelectedAsync),
+
+ Wrap() // A horizontal Stack that wraps when needed.
+ .WithChildren(
+ Button().Text("Disable Input").OnClick(OnMyButtonClickAsync),
+ Button().Text("Top Center button"),
+ Button().Text("Top Right button")),
+
+ Wrap() // A horizontal Stack that wraps when needed.
+ .Disable()
+ .WithChildren(
+ Button().Text("Bottom Left button"),
+ Button().Text("Bottom Center button"),
+ Button().Text("Bottom Right button")))),
+
+ // Cell that is at the top right in the grid.
+ Cell(
+ GridTestRow.Header,
+ GridTestColumn.Right,
+
+ DiffTextInput().Title("Just a diff editor")),
+
+ // Cell that is at the Content Left in the grid.
+ Cell(
+ GridTestRow.Content,
+ GridTestColumn.Left,
+
+ Stack()
+ .Vertical()
+
+ .WithChildren(
+ SettingGroup()
+ .Icon("FluentSystemIcons", '\uF6A9')
+ .Title("Dummy list setting")
+ .Description("Description")
+
+ // Enum and struct settings can be handled automatically. Just need to set a list of items and associate them to a value.
+ .Handle(
+ _settingsProvider,
+ DummyListSetting,
+ OnDummyListSettingChangedAsync,
+ Item("Use system settings", AvailableApplicationTheme.Default),
+ Item("Light", AvailableApplicationTheme.Light),
+ Item("Dark", AvailableApplicationTheme.Dark))
+
+ .WithSettings(
+ Setting()
+ .Title("Dummy setting")
+ // Boolean settings can also be handled automatically.
+ .Handle(_settingsProvider, DummyBooleanSetting),
+
+ Setting()
+ .Title("Title")
+ .Description("Description")
+ // We can also set any kind of content in the setting card.
+ .InteractiveElement(
+ Button().Text("Button setting"))),
+
+ InfoBar()
+ .Title("Title")
+ .Description("Description")
+ .Informational()
+ .WithActionButton("Click me", isAccent: false, actionOnClick: null)
+ .Open())),
+
+ // Cell that is at the Content Right in the grid.
+ Cell(
+ GridTestRow.Content,
+ GridTestColumn.Right,
+
+ Stack()
+ .Vertical()
+
+ .WithChildren(
+ SingleLineTextInput()
+ .Title("Single-line input text"),
+
+ NumberInput()
+ .Title("Number input")
+ .Maximum(100)
+ .Minimum(0)
+ .Step(0.5)
+ .Value(1.5),
+
+ SelectDropDownList()
+ .Title("Drop down list")
+ .WithItems(
+ Item("Item 1", value: null),
+ Item("Item 2", value: null),
+ Item("Item 3", value: null)))),
+
+ // Cell that is in the Footer row and take the whole width of the grid (it takes the 2 columns).
+ Cell(
+ GridTestRow.Footer, GridTestRow.Footer, // This cell is in the last row
+ GridTestColumn.Left, GridTestColumn.Right, // and spans from first to last column
+
+ SplitGrid()
+ .Vertical()
+
+ .WithLeftPaneChild(
+ _inputJsonEditor
+ .Language("json")
+ .Title("Input"))
+
+ .WithRightPaneChild(
+ MultilineTextInput()
+ .Language("json")
+ .Title("Output")
+ .ReadOnly()
+ .Extendable()))));
+
+ // Smart detection handler.
+ public void OnDataReceived(string dataTypeName, object? parsedData)
+ {
+ if (dataTypeName == PredefinedCommonDataTypeNames.Json && parsedData is Tuple<JToken, string> strongTypedParsedData)
+ {
+ // Pass the JSON from Smart Detection into the Input text editor.
+ _inputJsonEditor.Text(strongTypedParsedData.Item2);
+ }
+ }
+
+ // Invoked when the user selects some files in the FileSelector.
+ private ValueTask OnFilesSelectedAsync(PickedFile[] files)
+ {
+ return ValueTask.CompletedTask;
+ }
+
+ // Invoked on click on "Disable Input" button.
+ private ValueTask OnMyButtonClickAsync()
+ {
+ _inputJsonEditor.Disable();
+ return ValueTask.CompletedTask;
+ }
+
+ // Invoked when user change the setting "DummyListSetting".
+ private ValueTask OnDummyListSettingChangedAsync(AvailableApplicationTheme theme)
+ {
+ return ValueTask.CompletedTask;
+ }
+
+ // Invoked when Input text editor's text changed.
+ private void InputJsonEditor_TextChanged(object? sender, EventArgs e)
+ {
+ string editorText = _inputJsonEditor.Text;
+ }
+}
+#endif