Skip to content

A Swiss Army knife for developers.

Added most recent tools to the UI

Etienne Baudoux9c7fc8d162ac
diff --git a/src/app/dev/DevToys.Core/Tools/GuiToolInstance.cs b/src/app/dev/DevToys.Core/Tools/GuiToolInstance.cs
index 022e87c26..9e7a64d33 100644
--- a/src/app/dev/DevToys.Core/Tools/GuiToolInstance.cs
+++ b/src/app/dev/DevToys.Core/Tools/GuiToolInstance.cs
@@ -1,5 +1,6 @@
using System.Reflection;
using System.Resources;
+using CommunityToolkit.Mvvm.ComponentModel;
using DevToys.Api;
using DevToys.Core.Tools.Metadata;
using Microsoft.Extensions.Logging;
@@ -8,7 +9,7 @@ using Uno.Extensions;
namespace DevToys.Core.Tools;
[DebuggerDisplay($"InternalComponentName = {{{nameof(InternalComponentName)}}}")]
-public sealed partial class GuiToolInstance
+public sealed partial class GuiToolInstance : ObservableObject
{
private readonly ILogger _logger;
private readonly Lazy<IGuiTool, GuiToolMetadata> _guiToolDefinition;
@@ -57,6 +58,8 @@ public sealed partial class GuiToolInstance
public string LongDisplayTitle => _longDisplayTitle.Value;
+ public string LongOrShortDisplayTitle => string.IsNullOrWhiteSpace(_longDisplayTitle.Value) ? ShortDisplayTitle : _longDisplayTitle.Value;
+
public string Description => _descriptionDisplayTitle.Value;
public string AccessibleName => _accessibleNameDisplayTitle.Value;
@@ -75,6 +78,8 @@ public sealed partial class GuiToolInstance
public string GroupName => _guiToolDefinition.Metadata.GroupName;
+ public bool IsFooterTool => _guiToolDefinition.Metadata.MenuPlacement == MenuPlacement.Footer;
+
/// <summary>
/// Gets the view of the tool.
/// Calling this property is expensive the first time as it will create the instance of the tool and the instance of the view.
diff --git a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
index d598360df..1eff78556 100644
--- a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
+++ b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using System.Reflection;
+using System.Xml.Linq;
using DevToys.Api;
using DevToys.Api.Core;
using DevToys.Core.Settings;
@@ -123,9 +124,27 @@ public sealed partial class GuiToolProvider
public void SetMostRecentUsedTool(GuiToolInstance guiToolInstance)
{
Guard.IsNotNull(guiToolInstance);
- _settingsProvider.SetSetting(PredefinedSettings.RecentTool3, _settingsProvider.GetSetting(PredefinedSettings.RecentTool2));
- _settingsProvider.SetSetting(PredefinedSettings.RecentTool2, _settingsProvider.GetSetting(PredefinedSettings.RecentTool1));
- _settingsProvider.SetSetting(PredefinedSettings.RecentTool1, guiToolInstance.InternalComponentName);
+
+ string recentTool1 = _settingsProvider.GetSetting(PredefinedSettings.RecentTool1);
+ string recentTool2 = _settingsProvider.GetSetting(PredefinedSettings.RecentTool2);
+
+ if (string.Equals(guiToolInstance.InternalComponentName, recentTool1, StringComparison.Ordinal))
+ {
+ // The tool is already the most recently used one.
+ }
+ else if (string.Equals(guiToolInstance.InternalComponentName, recentTool2, StringComparison.Ordinal))
+ {
+ // Move second most recent to the most recent.
+ _settingsProvider.SetSetting(PredefinedSettings.RecentTool2, recentTool1);
+ _settingsProvider.SetSetting(PredefinedSettings.RecentTool1, guiToolInstance.InternalComponentName);
+ }
+ else
+ {
+ // Shift first and second most recent to the second and third items. Add the given item as the most recent one.
+ _settingsProvider.SetSetting(PredefinedSettings.RecentTool3, recentTool2);
+ _settingsProvider.SetSetting(PredefinedSettings.RecentTool2, recentTool1);
+ _settingsProvider.SetSetting(PredefinedSettings.RecentTool1, guiToolInstance.InternalComponentName);
+ }
LogSetMostRecentUsedTool(guiToolInstance.InternalComponentName);
}
@@ -336,7 +355,7 @@ public sealed partial class GuiToolProvider
var bodyToolInstances = new List<GuiToolInstance>();
// Order all the tools.
- guiTools = ExtensionOrderer.Order(guiTools);
+ guiTools = ExtensionOrderer.Order(guiTools.OrderBy(tool => tool.Metadata.MenuPlacement));
foreach (Lazy<IGuiTool, GuiToolMetadata> guiToolDefinition in guiTools)
{
diff --git a/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs b/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
index 7e8d71737..ec7f95dce 100644
--- a/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
+++ b/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
@@ -56,7 +56,7 @@ internal sealed class SampleCommandLineTool : ICommandLineTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -79,7 +79,7 @@ internal sealed class SampleGuiTool : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool2 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -102,7 +102,7 @@ internal sealed class SampleGuiTool2 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool3 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -125,7 +125,7 @@ internal sealed class SampleGuiTool3 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool4 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -148,7 +148,7 @@ internal sealed class SampleGuiTool4 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool5 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -171,7 +171,7 @@ internal sealed class SampleGuiTool5 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool6 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -194,7 +194,7 @@ internal sealed class SampleGuiTool6 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool7 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -217,7 +217,7 @@ internal sealed class SampleGuiTool7 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool8 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -240,7 +240,7 @@ internal sealed class SampleGuiTool8 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool9 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -263,7 +263,7 @@ internal sealed class SampleGuiTool9 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool10 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -286,7 +286,7 @@ internal sealed class SampleGuiTool10 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool11 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -309,7 +309,7 @@ internal sealed class SampleGuiTool11 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool12 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -332,7 +332,7 @@ internal sealed class SampleGuiTool12 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool13 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -355,7 +355,7 @@ internal sealed class SampleGuiTool13 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool14 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -378,7 +378,7 @@ internal sealed class SampleGuiTool14 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool15 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -401,7 +401,7 @@ internal sealed class SampleGuiTool15 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool16 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -424,7 +424,7 @@ internal sealed class SampleGuiTool16 : IGuiTool
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool17 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(GuiToolGroup))]
diff --git a/src/app/dev/DevToys.UI/ViewModels/ToolPageViewModel.cs b/src/app/dev/DevToys.UI/ViewModels/ToolPageViewModel.cs
index 04905771c..23cbc8654 100644
--- a/src/app/dev/DevToys.UI/ViewModels/ToolPageViewModel.cs
+++ b/src/app/dev/DevToys.UI/ViewModels/ToolPageViewModel.cs
@@ -34,22 +34,18 @@ internal sealed partial class ToolPageViewModel : ObservableRecipient
/// <summary>
/// Gets the UI of the tool.
/// </summary>
- internal IUIElement ToolView => _guiToolViewItem?.ToolInstance.View ?? throw new InvalidOperationException();
+ internal IUIElement? ToolView => _guiToolViewItem?.ToolInstance.View;
internal void Load(GuiToolViewItem guiToolViewItem)
{
Guard.IsNotNull(guiToolViewItem);
+ // Add the tool to most recent ones.
+ _guiToolProvider.SetMostRecentUsedTool(guiToolViewItem.ToolInstance);
+
_guiToolViewItem = guiToolViewItem;
- if (string.IsNullOrWhiteSpace(guiToolViewItem.ToolInstance.LongDisplayTitle))
- {
- HeaderText = guiToolViewItem.ToolInstance.ShortDisplayTitle;
- }
- else
- {
- HeaderText = guiToolViewItem.ToolInstance.LongDisplayTitle;
- }
+ HeaderText = guiToolViewItem.ToolInstance.LongOrShortDisplayTitle;
}
/// <summary>
diff --git a/src/app/dev/DevToys.UI/Views/MainWindow.xaml b/src/app/dev/DevToys.UI/Views/MainWindow.xaml
index 14d9ae673..38c535aae 100644
--- a/src/app/dev/DevToys.UI/Views/MainWindow.xaml
+++ b/src/app/dev/DevToys.UI/Views/MainWindow.xaml
@@ -285,7 +285,8 @@
<Frame
Grid.Row="1"
- Name="ContentFrame">
+ Name="ContentFrame"
+ IsNavigationStackEnabled="False">
</Frame>
</NavigationView>
</Grid>
diff --git a/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml b/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml
index 6c0cb58f8..b75085de5 100644
--- a/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml
+++ b/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml
@@ -15,40 +15,6 @@
mc:Ignorable="d">
<Page.Resources>
<Thickness x:Key="GridViewItemMargin">0,12,12,0</Thickness>
-
- <Style TargetType="GridViewHeaderItem">
- <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
- <Setter Property="FontSize" Value="{ThemeResource GridViewHeaderItemThemeFontSize}" />
- <Setter Property="Background" Value="{ThemeResource GridViewHeaderItemBackground}" />
- <Setter Property="Margin" Value="0,0,0,4" />
- <Setter Property="Padding" Value="0,8,12,0" />
- <Setter Property="HorizontalContentAlignment" Value="Left" />
- <Setter Property="VerticalContentAlignment" Value="Top" />
- <Setter Property="MinHeight" Value="{ThemeResource GridViewHeaderItemMinHeight}" />
- <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="GridViewHeaderItem">
- <StackPanel Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}">
- <ContentPresenter x:Name="ContentPresenter"
- Margin="{TemplateBinding Padding}"
- Content="{TemplateBinding Content}"
- ContentTemplate="{TemplateBinding ContentTemplate}"
- ContentTransitions="{TemplateBinding ContentTransitions}"
- HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
- VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
- <Rectangle Stroke="{ThemeResource GridViewHeaderItemDividerStroke}"
- StrokeThickness="0.5"
- Height="1"
- VerticalAlignment="Bottom"
- HorizontalAlignment="Stretch"
- Margin="0,8,12,0" />
- </StackPanel>
-
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
</Page.Resources>
<Grid>
@@ -91,6 +57,41 @@
x:Name="ToolGroups"
Source="{x:Bind ViewModel.Tools, Mode=OneWay}"
IsSourceGrouped="True"/>
+ <GridView.Resources>
+ <Style TargetType="GridViewHeaderItem">
+ <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
+ <Setter Property="FontSize" Value="{ThemeResource GridViewHeaderItemThemeFontSize}" />
+ <Setter Property="Background" Value="{ThemeResource GridViewHeaderItemBackground}" />
+ <Setter Property="Margin" Value="0,0,0,4" />
+ <Setter Property="Padding" Value="0,8,12,0" />
+ <Setter Property="HorizontalContentAlignment" Value="Left" />
+ <Setter Property="VerticalContentAlignment" Value="Top" />
+ <Setter Property="MinHeight" Value="{ThemeResource GridViewHeaderItemMinHeight}" />
+ <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="GridViewHeaderItem">
+ <StackPanel Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}">
+ <ContentPresenter x:Name="ContentPresenter"
+ Margin="{TemplateBinding Padding}"
+ Content="{TemplateBinding Content}"
+ ContentTemplate="{TemplateBinding ContentTemplate}"
+ ContentTransitions="{TemplateBinding ContentTransitions}"
+ HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
+ VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
+ <Rectangle Stroke="{ThemeResource GridViewHeaderItemDividerStroke}"
+ StrokeThickness="0.5"
+ Height="1"
+ VerticalAlignment="Bottom"
+ HorizontalAlignment="Stretch"
+ Margin="0,8,12,0" />
+ </StackPanel>
+
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+ </GridView.Resources>
<GridView.Header>
<Grid
x:Name="ToolHeader"
@@ -196,7 +197,7 @@
Margin="16,0,0,0"
MaxHeight="75"
Foreground="{ThemeResource GridViewItemForeground}"
- Text="{x:Bind LongDisplayTitle}"
+ Text="{x:Bind LongOrShortDisplayTitle}"
TextWrapping="Wrap"
TextTrimming="CharacterEllipsis" />
<TextBlock
diff --git a/src/app/tests/DevToys.UnitTests/Mocks/Tools/MockIGuiTool.cs b/src/app/tests/DevToys.UnitTests/Mocks/Tools/MockIGuiTool.cs
index 3e6a7e8c1..22c9ad98a 100644
--- a/src/app/tests/DevToys.UnitTests/Mocks/Tools/MockIGuiTool.cs
+++ b/src/app/tests/DevToys.UnitTests/Mocks/Tools/MockIGuiTool.cs
@@ -19,7 +19,7 @@ namespace DevToys.UnitTests.Mocks.Tools;
SearchKeywordsResourceName = nameof(MockToolResource.Title))]
internal sealed class MockIGuiTool2 : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}
[Export(typeof(IGuiTool))]
@@ -38,5 +38,5 @@ internal sealed class MockIGuiTool2 : IGuiTool
SearchKeywordsResourceName = nameof(MockToolResource.Title))]
internal sealed class MockIGuiTool : IGuiTool
{
- public IUIElement View => throw new NotImplementedException();
+ public IUIElement View => null!;
}