Skip to content

A Swiss Army knife for developers.

Added group tool page layout

Etienne Baudoux9efae41ae810
diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props
index d44b8579b..8ad36ede9 100644
--- a/src/Directory.Packages.props
+++ b/src/Directory.Packages.props
@@ -5,11 +5,13 @@
them in projects explicitely so we keep consistent package version number across the repository.
-->
<CommunityToolkitVersion>8.1.0</CommunityToolkitVersion>
+ <CommunityToolkitWinUINuGetVersion>7.1.2</CommunityToolkitWinUINuGetVersion>
<DotNetVersion>7.0.0</DotNetVersion>
<MicrosoftFastComponentsFluentUIVersion>2.0.1</MicrosoftFastComponentsFluentUIVersion>
<MicrosoftNETCoreUniversalWindowsPlatformVersion>6.2.14</MicrosoftNETCoreUniversalWindowsPlatformVersion>
<MicrosoftWindowsSDKBuildToolsVersion>10.0.22621.755</MicrosoftWindowsSDKBuildToolsVersion>
<UnoVersion>4.7.37</UnoVersion>
+ <UnoCommunityToolkitWinUINuGetVersion>7.1.100</UnoCommunityToolkitWinUINuGetVersion>
<UnoWasmBootstrapVersion>8.0.0-dev.65</UnoWasmBootstrapVersion>
<WebView2Version>1.0.1462.37</WebView2Version>
<MicrosoftTypeScriptMSBuildVersion>4.9.4</MicrosoftTypeScriptMSBuildVersion>
@@ -19,6 +21,8 @@
<PackageVersion Include="CommunityToolkit.Common" Version="$(CommunityToolkitVersion)" />
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="$(CommunityToolkitVersion)" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="$(CommunityToolkitVersion)" />
+ <PackageVersion Include="CommunityToolkit.WinUI.UI" Version="$(CommunityToolkitWinUINuGetVersion)" />
+ <PackageVersion Include="CommunityToolkit.WinUI.UI.Animations" Version="$(CommunityToolkitWinUINuGetVersion)" />
<PackageVersion Include="coverlet.collector" Version="3.1.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
@@ -45,6 +49,8 @@
<PackageVersion Include="System.ComponentModel.Composition" Version="$(DotNetVersion)" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" />
+ <PackageVersion Include="Uno.CommunityToolkit.WinUI.UI" Version="$(UnoCommunityToolkitWinUINuGetVersion)" />
+ <PackageVersion Include="Uno.CommunityToolkit.WinUI.UI.Animations" Version="$(UnoCommunityToolkitWinUINuGetVersion)" />
<PackageVersion Include="Uno.Core.Extensions.Logging" Version="4.0.1" />
<PackageVersion Include="Uno.Core.Extensions.Logging.Singleton" Version="4.0.1" />
<PackageVersion Include="Uno.Extensions.Logging.OSLog" Version="1.4.0" />
diff --git a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
index 70aab2e5e..e77fff51f 100644
--- a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
+++ b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
@@ -109,6 +109,31 @@ public sealed partial class GuiToolProvider
LogSetMostRecentUsedTool(guiToolInstance.InternalComponentName);
}
+ /// <summary>
+ /// Gets the list of most recently used tools.
+ /// </summary>
+ public IEnumerable<GuiToolInstance> GetMostRecentUsedTools()
+ {
+ GuiToolInstance? recentTool1 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool1));
+ GuiToolInstance? recentTool2 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool2));
+ GuiToolInstance? recentTool3 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool3));
+
+ if (recentTool1 is not null)
+ {
+ yield return recentTool1;
+ }
+
+ if (recentTool2 is not null)
+ {
+ yield return recentTool2;
+ }
+
+ if (recentTool3 is not null)
+ {
+ yield return recentTool3;
+ }
+ }
+
/// <summary>
/// Sets whether the given tool is marked as favorite or not.
/// </summary>
@@ -307,6 +332,7 @@ public sealed partial class GuiToolProvider
{
// "All tools" menu item.
yield return new GroupViewItem(
+ ReservedGuiToolGroupNames.AllTools,
iconFontName: "FluentSystemIcons",
iconGlyph: "\uE70F",
displayTitle: MainMenu.AllToolsDisplayTitle,
@@ -337,26 +363,16 @@ public sealed partial class GuiToolProvider
private IEnumerable<INotifyPropertyChanged> BuildRecentToolViewItems()
{
- GuiToolInstance? recentTool1 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool1));
- GuiToolInstance? recentTool2 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool2));
- GuiToolInstance? recentTool3 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool3));
- if (recentTool1 is not null || recentTool2 is not null || recentTool3 is not null)
- {
- if (recentTool1 is not null)
- {
- yield return new GuiToolViewItem(recentTool1);
- }
+ bool anyRecentTool = false;
- if (recentTool2 is not null)
- {
- yield return new GuiToolViewItem(recentTool2);
- }
-
- if (recentTool3 is not null)
- {
- yield return new GuiToolViewItem(recentTool3);
- }
+ foreach (GuiToolInstance recentTool in GetMostRecentUsedTools())
+ {
+ anyRecentTool = true;
+ yield return new GuiToolViewItem(recentTool);
+ }
+ if (anyRecentTool)
+ {
// Separator.
_separatorAfterRecentTools = new SeparatorViewItem();
yield return _separatorAfterRecentTools;
@@ -404,7 +420,7 @@ public sealed partial class GuiToolProvider
// Create a group view presentation, if needed.
if (!groups.TryGetValue(tool.GroupName, out Lazy<GroupViewItem, GuiToolGroupMetadata>? groupViewItem))
{
- groupViewItem = new(() => new GroupViewItem(toolGroup.Value, new ObservableCollection<GuiToolViewItem>()), toolGroup.Metadata);
+ groupViewItem = new(() => new GroupViewItem(toolGroup.Metadata.InternalComponentName, toolGroup.Value, new ObservableCollection<GuiToolViewItem>()), toolGroup.Metadata);
groups[tool.GroupName] = groupViewItem;
}
@@ -446,6 +462,7 @@ public sealed partial class GuiToolProvider
Guard.IsNull(_favoriteToolsGroupViewItem);
_favoriteToolsGroupViewItem
= new GroupViewItem(
+ ReservedGuiToolGroupNames.FavoriteTools,
iconFontName: "FluentSystemIcons",
iconGlyph: "\uF70E",
displayTitle: MainMenu.FavoriteToolsDisplayTitle,
diff --git a/src/app/dev/DevToys.Core/Tools/Metadata/GuiToolGroupMetadata.cs b/src/app/dev/DevToys.Core/Tools/Metadata/GuiToolGroupMetadata.cs
index 4b7e0fac8..974ec7253 100644
--- a/src/app/dev/DevToys.Core/Tools/Metadata/GuiToolGroupMetadata.cs
+++ b/src/app/dev/DevToys.Core/Tools/Metadata/GuiToolGroupMetadata.cs
@@ -18,6 +18,16 @@ public sealed class GuiToolGroupMetadata : IOrderableMetadata
After = metadata.GetValueOrDefault(nameof(OrderAttribute.After)) as IReadOnlyList<string> ?? Array.Empty<string>();
Guard.IsNotNullOrWhiteSpace(InternalComponentName);
+ if (string.Equals(ReservedGuiToolGroupNames.AllTools, InternalComponentName, StringComparison.OrdinalIgnoreCase))
+ {
+ ThrowHelper.ThrowInvalidDataException($"The tool group name '{ReservedGuiToolGroupNames.AllTools}' is reserved.");
+ }
+
+ if (string.Equals(ReservedGuiToolGroupNames.FavoriteTools, InternalComponentName, StringComparison.OrdinalIgnoreCase))
+ {
+ ThrowHelper.ThrowInvalidDataException($"The tool group name '{ReservedGuiToolGroupNames.FavoriteTools}' is reserved.");
+ }
+
if (Before.Count > 0)
{
var before = new List<string>();
diff --git a/src/app/dev/DevToys.Core/Tools/Metadata/ReservedGuiToolGroupNames.cs b/src/app/dev/DevToys.Core/Tools/Metadata/ReservedGuiToolGroupNames.cs
new file mode 100644
index 000000000..7212ba4bb
--- /dev/null
+++ b/src/app/dev/DevToys.Core/Tools/Metadata/ReservedGuiToolGroupNames.cs
@@ -0,0 +1,7 @@
+namespace DevToys.Core.Tools.Metadata;
+
+public static class ReservedGuiToolGroupNames
+{
+ public static readonly string AllTools = nameof(AllTools);
+ public static readonly string FavoriteTools = nameof(FavoriteTools);
+}
diff --git a/src/app/dev/DevToys.Core/Tools/ViewItems/GroupViewItem.cs b/src/app/dev/DevToys.Core/Tools/ViewItems/GroupViewItem.cs
index 6e2c8c9b3..cd960e1d6 100644
--- a/src/app/dev/DevToys.Core/Tools/ViewItems/GroupViewItem.cs
+++ b/src/app/dev/DevToys.Core/Tools/ViewItems/GroupViewItem.cs
@@ -11,9 +11,11 @@ namespace DevToys.Core.Tools.ViewItems;
public sealed class GroupViewItem : ObservableObject
{
internal GroupViewItem(
+ string internalName,
GuiToolGroup groupInfo,
ObservableCollection<GuiToolViewItem>? children = null)
: this(
+ internalName,
groupInfo.IconFontName,
groupInfo.IconGlyph,
groupInfo.DisplayTitle,
@@ -23,6 +25,7 @@ public sealed class GroupViewItem : ObservableObject
}
internal GroupViewItem(
+ string internalName,
string iconFontName,
string iconGlyph,
string displayTitle,
@@ -30,9 +33,11 @@ public sealed class GroupViewItem : ObservableObject
ObservableCollection<GuiToolViewItem>? children = null,
bool isExpandedByDefault = false)
{
+ Guard.IsNotNullOrWhiteSpace(internalName);
Guard.IsNotNullOrWhiteSpace(iconFontName);
Guard.IsNotNullOrWhiteSpace(iconGlyph);
Guard.IsNotNullOrWhiteSpace(displayTitle);
+ InternalName = internalName;
DisplayTitle = displayTitle;
AccessibleName = accessibleName ?? string.Empty;
IconFontName = iconFontName;
@@ -41,6 +46,11 @@ public sealed class GroupViewItem : ObservableObject
IsExpandedByDefault = isExpandedByDefault;
}
+ /// <summary>
+ /// Gets the internal name of the group.
+ /// </summary>
+ public string InternalName { get; }
+
/// <summary>
/// Gets the long title to display in the menu.
/// </summary>
diff --git a/src/app/dev/DevToys.Localization/Strings/MainMenu/MainMenu.Designer.cs b/src/app/dev/DevToys.Localization/Strings/MainMenu/MainMenu.Designer.cs
index 7e6e65a2d..5931dc592 100644
--- a/src/app/dev/DevToys.Localization/Strings/MainMenu/MainMenu.Designer.cs
+++ b/src/app/dev/DevToys.Localization/Strings/MainMenu/MainMenu.Designer.cs
@@ -95,5 +95,14 @@ namespace DevToys.Localization.Strings.MainMenu {
return ResourceManager.GetString("FavoriteToolsDisplayTitle", resourceCulture);
}
}
+
+ /// <summary>
+ /// Looks up a localized string similar to Recents.
+ /// </summary>
+ public static string RecentToolsDisplayTitle {
+ get {
+ return ResourceManager.GetString("RecentToolsDisplayTitle", resourceCulture);
+ }
+ }
}
}
diff --git a/src/app/dev/DevToys.Localization/Strings/MainMenu/MainMenu.resx b/src/app/dev/DevToys.Localization/Strings/MainMenu/MainMenu.resx
index 2e0b3c6eb..133371420 100644
--- a/src/app/dev/DevToys.Localization/Strings/MainMenu/MainMenu.resx
+++ b/src/app/dev/DevToys.Localization/Strings/MainMenu/MainMenu.resx
@@ -129,4 +129,7 @@
<data name="FavoriteToolsDisplayTitle" xml:space="preserve">
<value>Favorites</value>
</data>
+ <data name="RecentToolsDisplayTitle" xml:space="preserve">
+ <value>Recents</value>
+ </data>
</root>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/Sample/Sample.Designer.cs b/src/app/dev/DevToys.Tools/Sample/Sample.Designer.cs
index e618e7e2d..c35b7cb10 100644
--- a/src/app/dev/DevToys.Tools/Sample/Sample.Designer.cs
+++ b/src/app/dev/DevToys.Tools/Sample/Sample.Designer.cs
@@ -61,7 +61,7 @@ namespace DevToys.Tools.Sample {
}
/// <summary>
- /// Looks up a localized string similar to A dummy description.
+ /// Looks up a localized string similar to Base64 Image Encoder / Decoder.
/// </summary>
internal static string CommandDescription {
get {
@@ -69,6 +69,15 @@ namespace DevToys.Tools.Sample {
}
}
+ /// <summary>
+ /// Looks up a localized string similar to Encode or decode all the applicable characters to their corresponding HTML entities.
+ /// </summary>
+ internal static string Description {
+ get {
+ return ResourceManager.GetString("Description", resourceCulture);
+ }
+ }
+
/// <summary>
/// Looks up a localized string similar to File to treat.
/// </summary>
@@ -78,6 +87,15 @@ namespace DevToys.Tools.Sample {
}
}
+ /// <summary>
+ /// Looks up a localized string similar to HTML Encoder / Decoder.
+ /// </summary>
+ internal static string LongTitle {
+ get {
+ return ResourceManager.GetString("LongTitle", resourceCulture);
+ }
+ }
+
/// <summary>
/// Looks up a localized string similar to A dummy UTF8 option description.
/// </summary>
diff --git a/src/app/dev/DevToys.Tools/Sample/Sample.resx b/src/app/dev/DevToys.Tools/Sample/Sample.resx
index e537be38c..ace243e7d 100644
--- a/src/app/dev/DevToys.Tools/Sample/Sample.resx
+++ b/src/app/dev/DevToys.Tools/Sample/Sample.resx
@@ -118,11 +118,17 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CommandDescription" xml:space="preserve">
- <value>A dummy description</value>
+ <value>Base64 Image Encoder / Decoder</value>
+ </data>
+ <data name="Description" xml:space="preserve">
+ <value>Encode or decode all the applicable characters to their corresponding HTML entities</value>
</data>
<data name="FileOptionDescription" xml:space="preserve">
<value>File to treat</value>
</data>
+ <data name="LongTitle" xml:space="preserve">
+ <value>HTML Encoder / Decoder</value>
+ </data>
<data name="Utf8OptionDescription" xml:space="preserve">
<value>A dummy UTF8 option description</value>
</data>
diff --git a/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs b/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
index fd37f1e92..05d96ff08 100644
--- a/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
+++ b/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
@@ -39,6 +39,29 @@ internal sealed class SampleCommandLineTool : ICommandLineTool
[Export(typeof(IGuiTool))]
[Name("Sample tool")]
[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.LongTitle),
+ DescriptionResourceName = nameof(Sample.Description),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool2")]
+[Author("John Doe")]
[ToolDisplayInformation(
IconFontName = "FluentSystemIcons",
IconGlyph = "\uE670",
@@ -54,7 +77,352 @@ internal sealed class SampleCommandLineTool : ICommandLineTool
[TargetPlatform(Platform.Linux)]
[TargetPlatform(Platform.MacCatalyst)]
[TargetPlatform(Platform.WASM)]
-internal sealed class SampleGuiTool : IGuiTool
+internal sealed class SampleGuiTool2 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool3")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool3 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool4")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool4 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool5")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool5 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool6")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool6 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool7")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool7 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool8")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool8 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool9")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool9 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool10")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool10 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool11")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool11 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool12")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool12 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool13")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool13 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool14")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool14 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool15")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool15 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool16")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool16 : IGuiTool
+{
+ public UIElement View => throw new NotImplementedException();
+}
+
+[Export(typeof(IGuiTool))]
+[Name("Sample tool17")]
+[Author("John Doe")]
+[ToolDisplayInformation(
+ IconFontName = "FluentSystemIcons",
+ IconGlyph = "\uE670",
+ GroupName = "Encoders / Decoders",
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Sample.Sample",
+ ShortDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ LongDisplayTitleResourceName = nameof(Sample.CommandDescription),
+ DescriptionResourceName = nameof(Sample.CommandDescription),
+ AccessibleNameResourceName = nameof(Sample.CommandDescription),
+ SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
+[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
+[TargetPlatform(Platform.Linux)]
+[TargetPlatform(Platform.MacCatalyst)]
+[TargetPlatform(Platform.WASM)]
+internal sealed class SampleGuiTool17 : IGuiTool
{
public UIElement View => throw new NotImplementedException();
}
diff --git a/src/app/dev/DevToys.UI/Models/NavigationParameters.cs b/src/app/dev/DevToys.UI/Models/NavigationParameters.cs
new file mode 100644
index 000000000..3d140726f
--- /dev/null
+++ b/src/app/dev/DevToys.UI/Models/NavigationParameters.cs
@@ -0,0 +1,5 @@
+using DevToys.Api;
+
+namespace DevToys.UI.Models;
+
+internal record NavigationParameters<T>(IMefProvider MefProvider, T Parameter);
diff --git a/src/app/dev/DevToys.UI/ViewModels/MainWindowViewModel.cs b/src/app/dev/DevToys.UI/ViewModels/MainWindowViewModel.cs
index 055d5f47d..1fd9db0c7 100644
--- a/src/app/dev/DevToys.UI/ViewModels/MainWindowViewModel.cs
+++ b/src/app/dev/DevToys.UI/ViewModels/MainWindowViewModel.cs
@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
-using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DevToys.Core.Tools;
@@ -7,7 +6,7 @@ using DevToys.Core.Tools.ViewItems;
namespace DevToys.UI.ViewModels;
-[Export(typeof(MainWindowViewModel))]
+[Export]
internal sealed partial class MainWindowViewModel : ObservableRecipient
{
private readonly GuiToolProvider _guiToolProvider;
@@ -20,6 +19,11 @@ internal sealed partial class MainWindowViewModel : ObservableRecipient
_guiToolProvider = guiToolProvider;
}
+ /// <summary>
+ /// Raised when the <see cref="SelectedMenuItem"/> property changed.
+ /// </summary>
+ internal event EventHandler<EventArgs>? SelectedMenuItemChanged;
+
/// <summary>
/// Gets a hierarchical list containing all the tools available, ordered, to display in the top and body menu.
/// This includes "All tools" menu item, recents and favorites.
@@ -52,9 +56,12 @@ internal sealed partial class MainWindowViewModel : ObservableRecipient
{
SetProperty(ref _selectedMenuItem, value);
}
+
OnPropertyChanged(nameof(HeaderText));
OnPropertyChanged(nameof(IsSelectedMenuItemSupportFavorite));
OnPropertyChanged(nameof(IsSelectedMenuItemAFavoriteTool));
+ OnPropertyChanged(nameof(IsSelectedMenuItemATool));
+ SelectedMenuItemChanged?.Invoke(this, EventArgs.Empty);
}
}
@@ -88,6 +95,11 @@ internal sealed partial class MainWindowViewModel : ObservableRecipient
/// </summary>
internal bool IsSelectedMenuItemAFavoriteTool => SelectedMenuItem is GuiToolViewItem guiToolViewItem && _guiToolProvider.GetToolIsFavorite(guiToolViewItem.ToolInstance);
+ /// <summary>
+ /// Indicates whether the <see cref="SelectedMenuItem"/> is a tool or not.
+ /// </summary>
+ internal bool IsSelectedMenuItemATool => SelectedMenuItem is GuiToolViewItem;
+
/// <summary>
/// Toggles the favorite status of the <see cref="SelectedMenuItem"/>.
/// </summary>
diff --git a/src/app/dev/DevToys.UI/ViewModels/ToolGroupPageViewModel.cs b/src/app/dev/DevToys.UI/ViewModels/ToolGroupPageViewModel.cs
new file mode 100644
index 000000000..53dccb728
--- /dev/null
+++ b/src/app/dev/DevToys.UI/ViewModels/ToolGroupPageViewModel.cs
@@ -0,0 +1,148 @@
+using CommunityToolkit.Mvvm.Collections;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using DevToys.Core.Tools;
+using DevToys.Core.Tools.Metadata;
+using DevToys.Localization.Strings.MainMenu;
+using Microsoft.UI.Xaml.Controls;
+
+namespace DevToys.UI.ViewModels;
+
+[Export]
+[PartCreationPolicy(CreationPolicy.NonShared)]
+internal sealed partial class ToolGroupPageViewModel : ObservableRecipient
+{
+#pragma warning disable IDE0044 // Add readonly modifier
+ [Import]
+ private GuiToolProvider _guiToolProvider = null!;
+#pragma warning restore IDE0044 // Add readonly modifier
+
+ [ObservableProperty]
+ private ObservableGroupedCollection<string, GuiToolInstance>? _tools = null;
+
+ internal void Load(string groupName)
+ {
+ Guard.IsNotNullOrWhiteSpace(groupName);
+
+ if (string.Equals(groupName, ReservedGuiToolGroupNames.AllTools, StringComparison.OrdinalIgnoreCase))
+ {
+ Tools = LoadAllTools();
+ }
+ else if (string.Equals(groupName, ReservedGuiToolGroupNames.FavoriteTools, StringComparison.OrdinalIgnoreCase))
+ {
+ Tools = LoadFavoriteTools();
+ }
+ else
+ {
+ Tools = LoadToolsGroup(groupName);
+ }
+ }
+
+ [RelayCommand]
+ private static void ToolSelected(ItemClickEventArgs args)
+ {
+ if (args.ClickedItem is not null && args.ClickedItem is GuiToolInstance tool)
+ {
+ //WeakReferenceMessenger.Default.Send(
+ // new TrainingWindowNavigateToPageMessage(
+ // typeof(AppDetailPageViewModel),
+ // app.Model,
+ // NavigationTransition.Entrance,
+ // referenceConnectedAnimationObject: app));
+ }
+ }
+
+ private ObservableGroupedCollection<string, GuiToolInstance> LoadAllTools()
+ {
+ var results = new ObservableGroupedCollection<string, GuiToolInstance>();
+
+ // Recent tools group.
+ ObservableGroup<string, GuiToolInstance> recentToolsGroup
+ = new(MainMenu.RecentToolsDisplayTitle, _guiToolProvider.GetMostRecentUsedTools());
+ if (recentToolsGroup.Count > 0)
+ {
+ results.Add(recentToolsGroup);
+ }
+
+ // Favorite tools group & every other tools group.
+ var favoriteToolsGroup = new List<GuiToolInstance>();
+ var everyOtherToolsGroup = new List<GuiToolInstance>();
+ for (int i = 0; i < _guiToolProvider.AllTools.Count; i++)
+ {
+ GuiToolInstance tool = _guiToolProvider.AllTools[i];
+ bool isFavorite = _guiToolProvider.GetToolIsFavorite(tool);
+ if (isFavorite)
+ {
+ favoriteToolsGroup.Add(tool);
+ }
+ else
+ {
+ everyOtherToolsGroup.Add(tool);
+ }
+ }
+
+ if (favoriteToolsGroup.Count > 0)
+ {
+ string title;
+ if (recentToolsGroup.Count == 0 && everyOtherToolsGroup.Count == 0)
+ {
+ title = string.Empty;
+ }
+ else
+ {
+ title = MainMenu.FavoriteToolsDisplayTitle;
+ }
+
+ results.Add(new(title, favoriteToolsGroup));
+ }
+
+ if (everyOtherToolsGroup.Count > 0)
+ {
+ string title;
+ if (recentToolsGroup.Count == 0 && favoriteToolsGroup.Count == 0)
+ {
+ title = string.Empty;
+ }
+ else
+ {
+ title = MainMenu.AllToolsDisplayTitle;
+ }
+ results.Add(new(title, everyOtherToolsGroup));
+ }
+
+ return results;
+ }
+
+ private ObservableGroupedCollection<string, GuiToolInstance> LoadFavoriteTools()
+ {
+ var favoriteTools = new List<GuiToolInstance>();
+ for (int i = 0; i < _guiToolProvider.AllTools.Count; i++)
+ {
+ GuiToolInstance tool = _guiToolProvider.AllTools[i];
+ bool isFavorite = _guiToolProvider.GetToolIsFavorite(tool);
+ if (isFavorite)
+ {
+ favoriteTools.Add(tool);
+ }
+ }
+
+ return new ObservableGroupedCollection<string, GuiToolInstance>(
+ favoriteTools.GroupBy(static tool => string.Empty /* Group display name */));
+ }
+
+ private ObservableGroupedCollection<string, GuiToolInstance> LoadToolsGroup(string groupName)
+ {
+ var tools = new List<GuiToolInstance>();
+ for (int i = 0; i < _guiToolProvider.AllTools.Count; i++)
+ {
+ GuiToolInstance tool = _guiToolProvider.AllTools[i];
+ if (string.Equals(tool.GroupName, groupName, StringComparison.Ordinal))
+ {
+ tools.Add(tool);
+ }
+ }
+
+ return new ObservableGroupedCollection<string, GuiToolInstance>(
+ tools.GroupBy(static tool => string.Empty /* Group display name */));
+ }
+}
diff --git a/src/app/dev/DevToys.UI/Views/MainWindow.xaml b/src/app/dev/DevToys.UI/Views/MainWindow.xaml
index 2ca0e4a25..d099e24a4 100644
--- a/src/app/dev/DevToys.UI/Views/MainWindow.xaml
+++ b/src/app/dev/DevToys.UI/Views/MainWindow.xaml
@@ -94,6 +94,7 @@
Height="30"
Padding="0"
Visibility="{x:Bind IsCompactOverlayModeSupported, Converter={StaticResource BooleanToVisibilityConverter}}"
+ IsEnabled="{x:Bind ViewModel.IsSelectedMenuItemATool, Mode=OneWay}"
ToolTipService.ToolTip="{x:Bind strings:MainWindow.ToggleCompactOverlayTooltip}"
AutomationProperties.Name="{x:Bind strings:MainWindow.ToggleCompactOverlayTooltip}"
Click="CompactOverlayModeButton_Click">
@@ -220,7 +221,7 @@
Command="{Binding OpenToolInNewWindowCommand}"
CommandParameter="{x:Bind Metadata}">
<MenuFlyoutItem.Icon>
- <FontIcon Glyph="&#xF8B5;" />
+ <FontIcon Glyph="&#xEE7A;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
diff --git a/src/app/dev/DevToys.UI/Views/MainWindow.xaml.cs b/src/app/dev/DevToys.UI/Views/MainWindow.xaml.cs
index 1475f7b11..f98d6f045 100644
--- a/src/app/dev/DevToys.UI/Views/MainWindow.xaml.cs
+++ b/src/app/dev/DevToys.UI/Views/MainWindow.xaml.cs
@@ -1,18 +1,19 @@
using DevToys.Api;
using DevToys.Api.Core.Theme;
+using DevToys.Core.Tools;
using DevToys.Core.Tools.ViewItems;
using DevToys.UI.Framework.Controls;
+using DevToys.UI.Models;
using DevToys.UI.ViewModels;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
-using Microsoft.UI.Xaml.Navigation;
-using Windows.UI.ViewManagement;
+using Microsoft.UI.Xaml.Media.Animation;
namespace DevToys.UI.Views;
/// <summary>
-/// An empty page that can be used on its own or navigated to within a Frame.
+/// Main UI of the app
/// </summary>
public sealed partial class MainWindow : BackdropPage
{
@@ -21,11 +22,16 @@ public sealed partial class MainWindow : BackdropPage
private const string NavigationViewCompactStateName = "NavigationViewCompact";
private const string NavigationViewMinimalStateName = "NavigationViewMinimal";
+ private readonly IMefProvider _mefProvider;
+
private NavigationViewDisplayMode _navigationViewDisplayMode;
public MainWindow(BackdropWindow backdropWindow, IThemeListener themeListener, IMefProvider mefProvider)
: base(backdropWindow, themeListener)
{
+ Guard.IsNotNull(mefProvider);
+ _mefProvider = mefProvider;
+
InitializeComponent();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
Resize(1200, 800);
@@ -37,24 +43,14 @@ public sealed partial class MainWindow : BackdropPage
SizeChanged += MainWindow_SizeChanged;
CompactOverlayModeChanged += MainWindow_CompactOverlayModeChanged;
- ViewModel = mefProvider.Import<MainWindowViewModel>();
+ DataContext = mefProvider.Import<MainWindowViewModel>();
+ ViewModel.SelectedMenuItemChanged += ViewModel_SelectedMenuItemChanged;
}
- public static readonly DependencyProperty ViewModelProperty =
- DependencyProperty.Register(
- nameof(ViewModel),
- typeof(MainWindowViewModel),
- typeof(MainWindow),
- new PropertyMetadata(null));
-
/// <summary>
/// Gets the page's view model.
/// </summary>
- internal MainWindowViewModel ViewModel
- {
- get => (MainWindowViewModel)GetValue(ViewModelProperty);
- set => SetValue(ViewModelProperty, value);
- }
+ internal MainWindowViewModel ViewModel => (MainWindowViewModel)DataContext;
public static readonly DependencyProperty IsInCompactOverlayProperty =
DependencyProperty.Register(
@@ -83,15 +79,17 @@ public sealed partial class MainWindow : BackdropPage
// Workaround for a bug where opening the window in compact display mode will misalign the content layout.
MenuNavigationView.PaneDisplayMode = NavigationViewPaneDisplayMode.Auto;
-
// Binding "IsExpanded" to IsExpandedByDefault in the XAML doesn't work on UI load, likely because the item has no children yet when the UI is composed.
// So we manually expand the items that should be expanded on load.
- foreach (var item in ViewModel.HeaderAndBodyToolViewItems.Where(item => item is GroupViewItem groupViewItem && groupViewItem.IsExpandedByDefault))
+ foreach (INotifyPropertyChanged? item in ViewModel.HeaderAndBodyToolViewItems)
{
- var menuItem = MenuNavigationView.ContainerFromMenuItem(item) as NavigationViewItem;
- if (menuItem is not null)
+ if (item is GroupViewItem groupViewItem && groupViewItem.IsExpandedByDefault)
{
- menuItem.IsExpanded = true;
+ var menuItem = MenuNavigationView.ContainerFromMenuItem(item) as NavigationViewItem;
+ if (menuItem is not null)
+ {
+ menuItem.IsExpanded = true;
+ }
}
}
@@ -138,6 +136,31 @@ public sealed partial class MainWindow : BackdropPage
UpdateVisualState();
}
+ private void ViewModel_SelectedMenuItemChanged(object? sender, EventArgs e)
+ {
+ if (ViewModel.SelectedMenuItem is not null)
+ {
+ if (ViewModel.SelectedMenuItem is GroupViewItem groupViewItem)
+ {
+ ContentFrame.Navigate(
+ typeof(ToolGroupPage),
+ new NavigationParameters<string>(_mefProvider, groupViewItem.InternalName),
+ new EntranceNavigationTransitionInfo());
+ }
+ else if (ViewModel.SelectedMenuItem is GuiToolViewItem guiToolViewItem)
+ {
+ ContentFrame.Navigate(
+ typeof(ToolPage),
+ new NavigationParameters<GuiToolInstance>(_mefProvider, guiToolViewItem.ToolInstance),
+ new EntranceNavigationTransitionInfo());
+ }
+ else
+ {
+ ThrowHelper.ThrowNotSupportedException();
+ }
+ }
+ }
+
private void CompactOverlayModeButton_Click(object sender, RoutedEventArgs e)
{
TryToggleCompactOverlayMode();
diff --git a/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml b/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml
new file mode 100644
index 000000000..a6c022c04
--- /dev/null
+++ b/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml
@@ -0,0 +1,193 @@
+<Page
+ x:Class="DevToys.UI.Views.ToolGroupPage"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="using:DevToys.UI.Views"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:collections="using:CommunityToolkit.Mvvm.Collections"
+ xmlns:ix="using:Microsoft.Xaml.Interactions.Core"
+ xmlns:i="using:Microsoft.Xaml.Interactivity"
+ xmlns:tools="using:DevToys.Core.Tools"
+ mc:Ignorable="d">
+ <Page.Resources>
+ <Thickness x:Key="GridViewItemMargin">12,12,0,0</Thickness>
+ </Page.Resources>
+
+ <GridView
+ x:Name="GridView"
+ TabIndex="0"
+ Padding="-12,0,0,0"
+ SelectionMode="None"
+ IsSwipeEnabled="False"
+ IsItemClickEnabled="True"
+ ItemsSource="{x:Bind ToolGroups.View, Mode=OneWay}"
+ SizeChanged="GridView_SizeChanged">
+ <i:Interaction.Behaviors>
+ <ix:EventTriggerBehavior EventName="ItemClick">
+ <ix:InvokeCommandAction Command="{x:Bind ViewModel.ToolSelectedCommand}"/>
+ </ix:EventTriggerBehavior>
+ </i:Interaction.Behaviors>
+ <CollectionViewSource
+ x:Name="ToolGroups"
+ Source="{x:Bind ViewModel.Tools, Mode=OneWay}"
+ IsSourceGrouped="True"/>
+ <GridView.ItemsPanel>
+ <ItemsPanelTemplate>
+ <ItemsWrapGrid
+ Orientation="Horizontal"
+ HorizontalAlignment="Stretch">
+ <ItemsWrapGrid.ChildrenTransitions>
+ <TransitionCollection>
+ <EntranceThemeTransition IsStaggeringEnabled="False" FromVerticalOffset="150"/>
+ </TransitionCollection>
+ </ItemsWrapGrid.ChildrenTransitions>
+ </ItemsWrapGrid>
+ </ItemsPanelTemplate>
+ </GridView.ItemsPanel>
+ <GridView.ItemContainerStyle>
+ <Style TargetType="GridViewItem" BasedOn="{StaticResource DefaultGridViewItemStyle}">
+ <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
+ <Setter Property="VerticalContentAlignment" Value="Stretch"/>
+ <Setter Property="Margin" Value="{StaticResource GridViewItemMargin}" />
+ </Style>
+ </GridView.ItemContainerStyle>
+ <GridView.GroupStyle>
+ <GroupStyle>
+ <GroupStyle.HeaderTemplate>
+ <DataTemplate x:DataType="collections:IReadOnlyObservableGroup">
+ <TextBlock
+ Style="{ThemeResource SubtitleTextBlockStyle}"
+ FontWeight="Normal"
+ Text="{x:Bind Key}"/>
+ </DataTemplate>
+ </GroupStyle.HeaderTemplate>
+ </GroupStyle>
+ </GridView.GroupStyle>
+ <GridView.ItemTemplate>
+ <DataTemplate x:DataType="tools:GuiToolInstance">
+ <Grid
+ Height="134"
+ MaxHeight="134"
+ Padding="16"
+ Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
+ BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
+ BorderThickness="1"
+ CornerRadius="{StaticResource ControlCornerRadius}">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto"/>
+ <ColumnDefinition Width="*"/>
+ <ColumnDefinition Width="Auto"/>
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto"/>
+ <RowDefinition Height="*"/>
+ </Grid.RowDefinitions>
+ <Border
+ Grid.Column="0"
+ Grid.RowSpan="2"
+ Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
+ CornerRadius="{StaticResource ControlCornerRadius}"
+ Height="100"
+ Width="100"
+ Padding="12">
+ <FontIcon
+ HorizontalAlignment="Center"
+ VerticalAlignment="Center"
+ FontSize="64"
+ Foreground="{ThemeResource GridViewItemForeground}"
+ FontFamily="{x:Bind IconFontName, Converter={StaticResource StringToStaticResourceConverter}}"
+ Glyph="{x:Bind IconGlyph}"/>
+ </Border>
+ <TextBlock
+ Grid.Column="1"
+ Grid.Row="0"
+ VerticalAlignment="Top"
+ Style="{StaticResource BodyStrongTextBlockStyle}"
+ Margin="16,0,0,0"
+ MaxHeight="75"
+ Foreground="{ThemeResource GridViewItemForeground}"
+ Text="{x:Bind LongDisplayTitle}"
+ TextWrapping="Wrap"
+ TextTrimming="CharacterEllipsis" />
+ <TextBlock
+ Grid.Column="1"
+ Grid.ColumnSpan="2"
+ Grid.Row="1"
+ Style="{StaticResource CaptionTextBlockStyle}"
+ Margin="16,2,8,0"
+ Foreground="{ThemeResource TextFillColorSecondaryBrush}"
+ Text="{x:Bind Description}"
+ TextWrapping="Wrap"
+ TextTrimming="CharacterEllipsis"/>
+ <StackPanel
+ Grid.Column="2"
+ Grid.Row="0"
+ Margin="4,0,0,0"
+ VerticalAlignment="Top"
+ Orientation="Horizontal"
+ Spacing="4">
+ <Button
+ Height="24"
+ Width="24"
+ Padding="0">
+ <FontIcon
+ HorizontalAlignment="Center"
+ VerticalAlignment="Center"
+ FontFamily="{StaticResource FluentSystemIcons}"
+ FontSize="16"
+ Glyph="&#xEE7A;"/>
+ </Button>
+ </StackPanel>
+ <!--<StackPanel
+ x:Name="ToolBar"
+ Grid.Row="3"
+ Opacity="0"
+ Orientation="Horizontal"
+ HorizontalAlignment="Center">
+ <StackPanel.OpacityTransition>
+ <ScalarTransition />
+ </StackPanel.OpacityTransition>
+ --><!--<Button
+ Style="{StaticResource CommandBarFlyoutEllipsisButtonStyle}"
+ Height="32"
+ Width="32"
+ Padding="4"
+ AutomationProperties.Name="{Binding Instance.MainPage.OpenInNewWindow, Source={StaticResource LanguageManager}}"
+ ToolTipService.ToolTip="{Binding Instance.MainPage.OpenInNewWindow, Source={StaticResource LanguageManager}}"
+ Click="OpenInNewWindowButton_Click">
+ <FontIcon FontFamily="{StaticResource FluentSystemIcons}" FontSize="16" Glyph="&#xF8B5;"/>
+ </Button>
+ <Button
+ Style="{StaticResource CommandBarFlyoutEllipsisButtonStyle}"
+ Height="32"
+ Width="32"
+ Padding="4"
+ AutomationProperties.Name="{Binding Instance.MainPage.PinToolToStart, Source={StaticResource LanguageManager}}"
+ ToolTipService.ToolTip="{Binding Instance.MainPage.PinToolToStart, Source={StaticResource LanguageManager}}"
+ Click="PinToolToStartCommandButton_Click">
+ <FontIcon FontFamily="{StaticResource FluentSystemIcons}" FontSize="16" Glyph="&#xF601;"/>
+ </Button>--><!--
+ </StackPanel>-->
+ </Grid>
+ </DataTemplate>
+ </GridView.ItemTemplate>
+ <!--<GridView.Footer>
+ <Border
+ MaxWidth="{Binding ElementName=GridView, Path=ItemsPanelRoot.ActualWidth, Mode=OneWay}"
+ Padding="8,8,8,0">
+ <InfoBar
+ Severity="Informational"
+ IsClosable="False"
+ IsOpen="True"
+ IsIconVisible="True"
+ Title="{helpers:ResourceString Dictionary=AppListPage, Name=AppMissingIndication}"
+ Message="{helpers:ResourceString Dictionary=AppListPage, Name=CanVote}">
+ <InfoBar.ActionButton>
+ <HyperlinkButton Content="{helpers:ResourceString Dictionary=AppListPage, Name=VoteNow}" NavigateUri="https://www.example.com" />
+ </InfoBar.ActionButton>
+ </InfoBar>
+ </Border>
+ </GridView.Footer>-->
+ </GridView>
+</Page>
diff --git a/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml.cs b/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml.cs
new file mode 100644
index 000000000..630e76b89
--- /dev/null
+++ b/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml.cs
@@ -0,0 +1,45 @@
+using DevToys.UI.Models;
+using DevToys.UI.ViewModels;
+using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Xaml.Navigation;
+
+namespace DevToys.UI.Views;
+
+/// <summary>
+/// Page displaying a group of tools.
+/// </summary>
+public sealed partial class ToolGroupPage : Page
+{
+ private const int GridViewItemMaxWidth = 430;
+
+ public ToolGroupPage()
+ {
+ this.InitializeComponent();
+ }
+
+ /// <summary>
+ /// Gets the page's view model.
+ /// </summary>
+ internal ToolGroupPageViewModel ViewModel => (ToolGroupPageViewModel)DataContext;
+
+ protected override void OnNavigatedTo(NavigationEventArgs e)
+ {
+ base.OnNavigatedTo(e);
+
+ Guard.IsOfType(e.Parameter, typeof(NavigationParameters<string>));
+ var parameter = (NavigationParameters<string>)e.Parameter;
+
+ DataContext = parameter.MefProvider.Import<ToolGroupPageViewModel>();
+ ViewModel.Load(groupName: parameter.Parameter);
+ }
+
+ private void GridView_SizeChanged(object sender, SizeChangedEventArgs args)
+ {
+ var gridViewItemMargin = (Thickness)this.Resources["GridViewItemMargin"];
+
+ // Calculating the number of columns based on the width of the page
+ double columns = Math.Ceiling(ActualWidth / (GridViewItemMaxWidth + gridViewItemMargin.Left + gridViewItemMargin.Right));
+ ((ItemsWrapGrid)GridView.ItemsPanelRoot).ItemWidth = args.NewSize.Width / columns;
+ }
+}
diff --git a/src/app/dev/DevToys.UI/Views/ToolPage.xaml b/src/app/dev/DevToys.UI/Views/ToolPage.xaml
new file mode 100644
index 000000000..29133f2db
--- /dev/null
+++ b/src/app/dev/DevToys.UI/Views/ToolPage.xaml
@@ -0,0 +1,12 @@
+<Page
+ x:Class="DevToys.UI.Views.ToolPage"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="using:DevToys.UI.Views"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d"
+ Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
+
+ <Grid></Grid>
+</Page>
diff --git a/src/app/dev/DevToys.UI/Views/ToolPage.xaml.cs b/src/app/dev/DevToys.UI/Views/ToolPage.xaml.cs
new file mode 100644
index 000000000..e4dd5d1a9
--- /dev/null
+++ b/src/app/dev/DevToys.UI/Views/ToolPage.xaml.cs
@@ -0,0 +1,14 @@
+using Microsoft.UI.Xaml.Controls;
+
+namespace DevToys.UI.Views;
+
+/// <summary>
+/// Page displaying a tool.
+/// </summary>
+public sealed partial class ToolPage : Page
+{
+ public ToolPage()
+ {
+ this.InitializeComponent();
+ }
+}