Skip to content

Commit

Permalink
Added hex converter toys (#86)
Browse files Browse the repository at this point in the history
* Added hexconverter toy

* added french localization and Accessibility name

* renamed HexConverter to NumberBaseConverter

* cleaned csproj *.resw
  • Loading branch information
btiteux authored Nov 29, 2021
1 parent f69a6c3 commit f6fb37e
Show file tree
Hide file tree
Showing 18 changed files with 1,950 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src/dev/impl/DevToys/DevToys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
<Compile Include="Api\Core\OOP\IAppService.cs" />
<Compile Include="Core\OOP\AppService.cs" />
<Compile Include="Core\Threading\AsyncLazy.cs" />
<Compile Include="Models\Radix.cs" />
<Compile Include="Models\NumberBaseFormat.cs" />
<Compile Include="UI\Converters\BooleanToDoubleConverter.cs" />
<Compile Include="UI\Converters\BooleanToIntegerConverter.cs" />
<Compile Include="ViewModels\Tools\HtmlEncoderDecoder\HtmlEncoderDecoderToolProvider.cs" />
<Compile Include="ViewModels\Tools\HtmlEncoderDecoder\HtmlEncoderDecoderToolViewModel.cs" />
<Compile Include="ViewModels\Tools\PngJpgCompressor\ImageCompressionWorkItem.cs" />
<Compile Include="ViewModels\Tools\PngJpgCompressor\PngJpgCompressorToolProvider.cs" />
<Compile Include="ViewModels\Tools\PngJpgCompressor\PngJpgCompressorToolViewModel.cs" />
<Compile Include="Views\Tools\GuidGenerator\GuidGeneratorToolPage.xaml.cs">
<DependentUpon>GuidGeneratorToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\HtmlEncoderDecoder\HtmlEncoderDecoderToolPage.xaml.cs">
<DependentUpon>HtmlEncoderDecoderToolPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -198,6 +203,7 @@
<Compile Include="Core\Clipboard.cs" />
<Compile Include="Core\Collections\OrderedObservableCollection.cs" />
<Compile Include="Core\Constants.cs" />
<Compile Include="ViewModels\Tools\NumberBaseConverter\NumberBaseFormatter.cs" />
<Compile Include="Core\Logger.cs" />
<Compile Include="Core\MarketingService.cs" />
<Compile Include="Core\Navigation\WindowManager.cs" />
Expand All @@ -224,6 +230,8 @@
<Compile Include="UI\Converters\NullToVisibilityConverter.cs" />
<Compile Include="Helpers\JsonHelper.cs" />
<Compile Include="Helpers\YamlHelper.cs" />
<Compile Include="ViewModels\Tools\NumberBaseConverter\NumberBaseConverterToolProvider.cs" />
<Compile Include="ViewModels\Tools\NumberBaseConverter\NumberBaseConverterToolViewModel.cs" />
<Compile Include="ViewModels\Tools\GuidGenerator\GuidGeneratorToolProvider.cs" />
<Compile Include="ViewModels\Tools\GuidGenerator\GuidGeneratorToolViewModel.cs" />
<Compile Include="ViewModels\Tools\JsonYaml\JsonYamlToolProvider.cs" />
Expand Down Expand Up @@ -294,8 +302,8 @@
<Compile Include="Views\Tools\Base64EncoderDecoder\Base64EncoderDecoderToolPage.xaml.cs">
<DependentUpon>Base64EncoderDecoderToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\GuidGenerator\GuidGeneratorToolPage.xaml.cs">
<DependentUpon>GuidGeneratorToolPage.xaml</DependentUpon>
<Compile Include="Views\Tools\NumberBaseConverter\NumberBaseConverterToolPage.xaml.cs">
<DependentUpon>NumberBaseConverterToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\HashGenerator\HashGeneratorToolPage.xaml.cs">
<DependentUpon>HashGeneratorToolPage.xaml</DependentUpon>
Expand Down Expand Up @@ -354,7 +362,7 @@
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<PRIResource Include="Strings\en-US\PngJpgCompressor.resw" />
<PRIResource Include="Strings\*\*.resw" />
<Page Include="Themes\Custom.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -395,6 +403,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Tools\NumberBaseConverter\NumberBaseConverterToolPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Tools\HashGenerator\HashGeneratorToolPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -447,7 +459,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<PRIResource Include="Strings\*\*.resw" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitInfo" Version="$(Nuget_GitInfo)" />
Expand Down Expand Up @@ -481,6 +492,9 @@
<Name>Windows Desktop Extensions for the UWP</Name>
</SDKReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Core\Formatter\" />
</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.
Expand Down
86 changes: 86 additions & 0 deletions src/dev/impl/DevToys/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public partial class LanguageManager : ObservableObject
private readonly JwtDecoderEncoderStrings _jwtdecoderencoder = new JwtDecoderEncoderStrings();
private readonly MainPageStrings _mainpage = new MainPageStrings();
private readonly MarkdownPreviewStrings _markdownpreview = new MarkdownPreviewStrings();
private readonly NumberBaseConverterStrings _numberbaseconverter = new NumberBaseConverterStrings();
private readonly PngJpgCompressorStrings _pngjpgcompressor = new PngJpgCompressorStrings();
private readonly RegExStrings _regex = new RegExStrings();
private readonly SettingsStrings _settings = new SettingsStrings();
Expand Down Expand Up @@ -101,6 +102,11 @@ public partial class LanguageManager : ObservableObject
/// </summary>
public MarkdownPreviewStrings MarkdownPreview => _markdownpreview;

/// <summary>
/// Gets the <see cref="NumberBaseConverterStrings"/>.
/// </summary>
public NumberBaseConverterStrings NumberBaseConverter => _numberbaseconverter;

/// <summary>
/// Gets the <see cref="PngJpgCompressorStrings"/>.
/// </summary>
Expand Down Expand Up @@ -829,6 +835,86 @@ public class MarkdownPreviewStrings : ObservableObject
public string ThemeDescription => _resources.GetString("ThemeDescription");
}

public class NumberBaseConverterStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("NumberBaseConverter");

/// <summary>
/// Gets the resource AccessibleName.
/// </summary>
public string AccessibleName => _resources.GetString("AccessibleName");

/// <summary>
/// Gets the resource BinaryLabel.
/// </summary>
public string BinaryLabel => _resources.GetString("BinaryLabel");

/// <summary>
/// Gets the resource ConfigurationTitle.
/// </summary>
public string ConfigurationTitle => _resources.GetString("ConfigurationTitle");

/// <summary>
/// Gets the resource DecimalLabel.
/// </summary>
public string DecimalLabel => _resources.GetString("DecimalLabel");

/// <summary>
/// Gets the resource DisplayName.
/// </summary>
public string DisplayName => _resources.GetString("DisplayName");

/// <summary>
/// Gets the resource Format.
/// </summary>
public string Format => _resources.GetString("Format");

/// <summary>
/// Gets the resource HexadecimalLabel.
/// </summary>
public string HexadecimalLabel => _resources.GetString("HexadecimalLabel");

/// <summary>
/// Gets the resource Input.
/// </summary>
public string Input => _resources.GetString("Input");

/// <summary>
/// Gets the resource InputTypeBinary.
/// </summary>
public string InputTypeBinary => _resources.GetString("InputTypeBinary");

/// <summary>
/// Gets the resource InputTypeDecimal.
/// </summary>
public string InputTypeDecimal => _resources.GetString("InputTypeDecimal");

/// <summary>
/// Gets the resource InputTypeDescription.
/// </summary>
public string InputTypeDescription => _resources.GetString("InputTypeDescription");

/// <summary>
/// Gets the resource InputTypeHexadecimal.
/// </summary>
public string InputTypeHexadecimal => _resources.GetString("InputTypeHexadecimal");

/// <summary>
/// Gets the resource InputTypeOctal.
/// </summary>
public string InputTypeOctal => _resources.GetString("InputTypeOctal");

/// <summary>
/// Gets the resource InputTypeTitle.
/// </summary>
public string InputTypeTitle => _resources.GetString("InputTypeTitle");

/// <summary>
/// Gets the resource OctalLabel.
/// </summary>
public string OctalLabel => _resources.GetString("OctalLabel");
}

public class PngJpgCompressorStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("PngJpgCompressor");
Expand Down
62 changes: 62 additions & 0 deletions src/dev/impl/DevToys/Models/NumberBaseFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Globalization;

namespace DevToys.Models
{
public class NumberBaseFormat : IEquatable<NumberBaseFormat>
{
private static NumberBaseConverterStrings Strings => LanguageManager.Instance.NumberBaseConverter;

public static readonly NumberBaseFormat Octal = new(
displayName: Strings.OctalLabel,
value: Radix.Octal,
baseNumber:8,
groupSize: CultureInfo.CurrentCulture.NumberFormat.NumberGroupSizes[0],
groupSeparator: ' ');

public static readonly NumberBaseFormat Binary = new(
displayName: Strings.BinaryLabel,
value: Radix.Binary,
baseNumber: 2,
groupSize: 4,
groupSeparator: ' ');

public static readonly NumberBaseFormat Decimal = new(
displayName: Strings.DecimalLabel,
value: Radix.Decimal,
baseNumber: 10,
groupSize: CultureInfo.CurrentCulture.NumberFormat.NumberGroupSizes[0],
groupSeparator: Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator));

public static readonly NumberBaseFormat Hexadecimal = new(
displayName: Strings.HexadecimalLabel,
value: Radix.Hexdecimal,
baseNumber: 16,
groupSize: 4,
groupSeparator: ' ');

public string DisplayName { get; }

public Radix Value { get; }

public int BaseNumber { get; }

public int GroupSize { get; }

public char GroupSeparator { get; }

private NumberBaseFormat(string displayName, Radix value, int baseNumber, int groupSize, char groupSeparator)
{
DisplayName = displayName;
Value = value;
BaseNumber = baseNumber;
GroupSize = groupSize;
GroupSeparator = groupSeparator;
}

public bool Equals(NumberBaseFormat other)
{
return other.Value == Value;
}
}
}
10 changes: 10 additions & 0 deletions src/dev/impl/DevToys/Models/Radix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DevToys.Models
{
public enum Radix
{
Octal,
Binary,
Decimal,
Hexdecimal
}
}
Loading

0 comments on commit f6fb37e

Please sign in to comment.