Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a "All tools" menu #111

Merged
merged 1 commit into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/dev/impl/DevToys/Api/Tools/IToolProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public interface IToolProviderFactory
IEnumerable<IToolProvider> GetAllChildrenTools(IToolProvider toolProvider);

/// <summary>
/// Gets the list of tools available that have the <see cref="IsFooterItemAttribute"/>.
/// Gets the list of tools available that have should be displayed in the header.
/// </summary>
Task<IEnumerable<MatchedToolProvider>> GetHeaderToolsAsync();

/// <summary>
/// Gets the list of tools available that have should be displayed in the footer.
/// </summary>
Task<IEnumerable<MatchedToolProvider>> GetFooterToolsAsync();

Expand Down
11 changes: 11 additions & 0 deletions src/dev/impl/DevToys/Api/Tools/MenuPlacement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#nullable enable

namespace DevToys.Api.Tools
{
public enum MenuPlacement
{
Body,
Header,
Footer
}
}
22 changes: 22 additions & 0 deletions src/dev/impl/DevToys/Api/Tools/MenuPlacementAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#nullable enable

using System;
using System.Composition;

namespace DevToys.Api.Tools
{
/// <summary>
/// Indicates where the <see cref="IToolProvider"/> should be displayed in the navigation view.
/// </summary>
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class MenuPlacementAttribute : Attribute
{
public MenuPlacement MenuPlacement { get; }

public MenuPlacementAttribute(MenuPlacement menuPlacement)
{
MenuPlacement = menuPlacement;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
namespace DevToys.Api.Tools
{
/// <summary>
/// Indicates whether the <see cref="IToolProvider"/> should be displayed at the bottom in the navigation view or not.
/// Indicates that the tool can not be searched.
/// </summary>
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class IsFooterItemAttribute : Attribute
public sealed class NotSearchableAttribute : Attribute
{
public bool IsFooterItem { get; } = true;
public bool NotSearchable { get; } = true;
}
}
12 changes: 9 additions & 3 deletions src/dev/impl/DevToys/Api/Tools/ToolProviderMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public sealed class ToolProviderMetadata
public int? Order { get; set; }

/// <summary>
/// Gets or sets whether the tool should be displayed in the footer of the menu.
/// Gets or sets where the tool should be displayed in navigation view.
/// </summary>
[DefaultValue(false)]
public bool IsFooterItem { get; set; }
[DefaultValue(MenuPlacement.Body)]
public MenuPlacement MenuPlacement { get; set; }

/// <summary>
/// Gets or sets the tool name used through URI Activation Protocol to access this tool.
Expand Down Expand Up @@ -59,5 +59,11 @@ public sealed class ToolProviderMetadata
/// </summary>
[DefaultValue(false)]
public bool NotScrollable { get; set; }

/// <summary>
/// Gets or sets whether the tool can be searched.
/// </summary>
[DefaultValue(false)]
public bool NotSearchable { get; set; }
}
}
43 changes: 40 additions & 3 deletions src/dev/impl/DevToys/Core/ToolProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal sealed class ToolProviderFactory : IToolProviderFactory
{
private readonly ImmutableArray<MatchedToolProvider> _allProviders;
private readonly Task<ImmutableArray<MatchedToolProvider>> _providersTree;
private readonly Task<ImmutableArray<MatchedToolProvider>> _headerProviders;
private readonly Task<ImmutableArray<MatchedToolProvider>> _footerProviders;
private readonly Dictionary<IToolProvider, IToolViewModel> _toolProviderToViewModelCache = new();

Expand All @@ -28,6 +29,7 @@ public ToolProviderFactory(
{
_allProviders = BuildAllTools(providers);
_providersTree = BuildToolsTreeAsync();
_headerProviders = BuildHeaderToolsAsync();
_footerProviders = BuildFooterToolsAsync();

App.Current.Suspending += OnAppSuspending;
Expand Down Expand Up @@ -81,6 +83,11 @@ public IEnumerable<IToolProvider> GetAllChildrenTools(IToolProvider toolProvider
return Array.Empty<IToolProvider>();
}

public async Task<IEnumerable<MatchedToolProvider>> GetHeaderToolsAsync()
{
return await _headerProviders;
}

public async Task<IEnumerable<MatchedToolProvider>> GetFooterToolsAsync()
{
return await _footerProviders;
Expand Down Expand Up @@ -140,7 +147,8 @@ private IEnumerable<MatchedToolProvider> SearchTools(string[]? searchQueries)
{
foreach (MatchedToolProvider provider in GetAllTools())
{
if (provider.ChildrenTools.Count == 0 // do not search groups.
if (!provider.Metadata.NotSearchable // do not search tools marked as non-searchable
&& provider.ChildrenTools.Count == 0 // do not search groups.
&& !string.IsNullOrWhiteSpace(provider.ToolProvider.SearchDisplayName)) // do not search tools without search display name.
{
var matches = new List<MatchSpan>();
Expand Down Expand Up @@ -233,7 +241,7 @@ private async Task<ImmutableArray<MatchedToolProvider>> BuildToolsTreeAsync()
var results = new List<MatchedToolProvider>();
IEnumerable<MatchedToolProvider> matchedToolProviders
= GetAllTools()
.Where(item => !item.Metadata.IsFooterItem);
.Where(item => item.Metadata.MenuPlacement == MenuPlacement.Body);

foreach (MatchedToolProvider provider in matchedToolProviders)
{
Expand Down Expand Up @@ -266,12 +274,41 @@ IEnumerable<MatchedToolProvider> matchedToolProviders
return SortTools(results, takeConsiderationOfMatches: false).ToImmutableArray();
}

private async Task<ImmutableArray<MatchedToolProvider>> BuildHeaderToolsAsync()
{
await TaskScheduler.Default;

ImmutableArray<MatchedToolProvider>.Builder result = ImmutableArray.CreateBuilder<MatchedToolProvider>();
foreach (
MatchedToolProvider provider
in
SortTools(
GetAllTools()
.Where(
item => item.Metadata.MenuPlacement == MenuPlacement.Header)
.ToList(),
takeConsiderationOfMatches: false))
{
result.Add(provider);
}

return result.ToImmutable();
}

private async Task<ImmutableArray<MatchedToolProvider>> BuildFooterToolsAsync()
{
await TaskScheduler.Default;

ImmutableArray<MatchedToolProvider>.Builder result = ImmutableArray.CreateBuilder<MatchedToolProvider>();
foreach (MatchedToolProvider provider in SortTools(GetAllTools().Where(item => item.Metadata.IsFooterItem).ToList(), takeConsiderationOfMatches: false))
foreach (
MatchedToolProvider provider
in
SortTools(
GetAllTools()
.Where(
item => item.Metadata.MenuPlacement == MenuPlacement.Footer)
.ToList(),
takeConsiderationOfMatches: false))
{
result.Add(provider);
}
Expand Down
16 changes: 15 additions & 1 deletion src/dev/impl/DevToys/DevToys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Api\Core\OOP\IAppService.cs" />
<Compile Include="Api\Tools\MenuPlacement.cs" />
<Compile Include="Api\Tools\NotSearchableAttribute.cs" />
<Compile Include="Api\Tools\ParentAttribute.cs" />
<Compile Include="Core\OOP\AppService.cs" />
<Compile Include="Core\Threading\AsyncLazy.cs" />
Expand All @@ -36,6 +38,9 @@
</Compile>
<Compile Include="UI\Converters\BooleanToDoubleConverter.cs" />
<Compile Include="UI\Converters\BooleanToIntegerConverter.cs" />
<Compile Include="UI\MainMenuNavigationViewMenuItemSelector.cs" />
<Compile Include="ViewModels\Tools\AllTools\AllToolsToolProvider.cs" />
<Compile Include="ViewModels\Tools\AllTools\AllToolsToolViewModel.cs" />
<Compile Include="ViewModels\Tools\Converters\ConvertersGroupToolProvider.cs" />
<Compile Include="ViewModels\Tools\EncodersDecoders\EncodersDecodersGroupToolProvider.cs" />
<Compile Include="ViewModels\Tools\Generators\GeneratorsGroupToolProvider.cs" />
Expand All @@ -48,7 +53,11 @@
<Compile Include="ViewModels\Tools\Graphic\PngJpgCompressor\PngJpgCompressorToolProvider.cs" />
<Compile Include="ViewModels\Tools\Graphic\PngJpgCompressor\PngJpgCompressorToolViewModel.cs" />
<Compile Include="ViewModels\Tools\Formatters\FormattersGroupToolProvider.cs" />
<Compile Include="ViewModels\Tools\GroupToolViewModelBase.cs" />
<Compile Include="ViewModels\Tools\Text\TextGroupToolProvider.cs" />
<Compile Include="Views\Tools\AllTools\AllToolsToolPage.xaml.cs">
<DependentUpon>AllToolsToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\GroupToolPage.xaml.cs">
<DependentUpon>GroupToolPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -240,7 +249,7 @@
<Compile Include="Api\Core\Theme\AppTheme.cs" />
<Compile Include="Api\Core\Theme\IThemeListener.cs" />
<Compile Include="Api\Tools\CompactOverlaySizeAttribute.cs" />
<Compile Include="Api\Tools\IsFooterItemAttribute.cs" />
<Compile Include="Api\Tools\MenuPlacementAttribute.cs" />
<Compile Include="Api\Tools\IToolProvider.cs" />
<Compile Include="Api\Tools\IToolProviderFactory.cs" />
<Compile Include="Api\Tools\IToolViewModel.cs" />
Expand Down Expand Up @@ -413,6 +422,7 @@
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<PRIResource Include="Strings\en-US\AllTools.resw" />
<PRIResource Include="Strings\*\*.resw" />
<Page Include="Themes\Custom.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -450,6 +460,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Tools\AllTools\AllToolsToolPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Tools\Base64EncoderDecoder\Base64EncoderDecoderToolPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
21 changes: 21 additions & 0 deletions src/dev/impl/DevToys/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class LanguageManager : ObservableObject
{
private static LanguageManager? _languageManager;

private readonly AllToolsStrings _alltools = new AllToolsStrings();
private readonly Base64EncoderDecoderStrings _base64encoderdecoder = new Base64EncoderDecoderStrings();
private readonly CommonStrings _common = new CommonStrings();
private readonly GuidGeneratorStrings _guidgenerator = new GuidGeneratorStrings();
Expand Down Expand Up @@ -53,6 +54,11 @@ public partial class LanguageManager : ObservableObject
/// </summary>
public FlowDirection FlowDirection { get; private set; }

/// <summary>
/// Gets the <see cref="AllToolsStrings"/>.
/// </summary>
public AllToolsStrings AllTools => _alltools;

/// <summary>
/// Gets the <see cref="Base64EncoderDecoderStrings"/>.
/// </summary>
Expand Down Expand Up @@ -190,6 +196,21 @@ public void SetCurrentCulture(LanguageDefinition language)
}
}

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

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

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

public class Base64EncoderDecoderStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("Base64EncoderDecoder");
Expand Down
Loading