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

Feature: Added tooltips to Layout Picker #14852

Merged
merged 16 commits into from
Feb 27, 2024
37 changes: 37 additions & 0 deletions src/Files.App/Converters/EnumToHumanizedConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml.Data;

namespace Files.App.Converters
{
internal sealed class EnumToHumanizedConverter : IValueConverter
{
public string EnumTypeName { get; set; } = string.Empty;

public object Convert(object value, Type targetType, object parameter, string language)
{
var stringValue = value.ToString() ?? string.Empty;

return EnumTypeName switch
{
"DetailsViewSizeKind"
=> LocalizedEnumDescriptionFactory.Get(Enum.Parse<DetailsViewSizeKind>(stringValue)),
"ListViewSizeKind"
=> LocalizedEnumDescriptionFactory.Get(Enum.Parse<ListViewSizeKind>(stringValue)),
"TilesViewSizeKind"
=> LocalizedEnumDescriptionFactory.Get(Enum.Parse<TilesViewSizeKind>(stringValue)),
"GridViewSizeKind"
=> LocalizedEnumDescriptionFactory.Get(Enum.Parse<GridViewSizeKind>(stringValue)),
"ColumnsViewSizeKind"
=> LocalizedEnumDescriptionFactory.Get(Enum.Parse<ColumnsViewSizeKind>(stringValue)),
_ => string.Empty,
};
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
95 changes: 95 additions & 0 deletions src/Files.App/Data/Factories/LocalizedEnumDescriptionFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.Factories
{
/// <summary>
/// Generates localization description for an enum value.
/// </summary>
internal static class LocalizedEnumDescriptionFactory
{
private static Dictionary<DetailsViewSizeKind, string> DetailsViewSizeKinds { get; } = [];
private static Dictionary<ListViewSizeKind, string> ListViewSizeKinds { get; } = [];
private static Dictionary<TilesViewSizeKind, string> TilesViewSizeKinds { get; } = [];
private static Dictionary<GridViewSizeKind, string> GridViewSizeKinds { get; } = [];
private static Dictionary<ColumnsViewSizeKind, string> ColumnsViewSizeKinds { get; } = [];

public static string Get(DetailsViewSizeKind value)
{
if (DetailsViewSizeKinds.Count == 0)
{
DetailsViewSizeKinds.Add(DetailsViewSizeKind.Compact, "Compact".GetLocalizedResource());
DetailsViewSizeKinds.Add(DetailsViewSizeKind.Small, "Small".GetLocalizedResource());
DetailsViewSizeKinds.Add(DetailsViewSizeKind.Medium, "Medium".GetLocalizedResource());
DetailsViewSizeKinds.Add(DetailsViewSizeKind.Large, "Large".GetLocalizedResource());
DetailsViewSizeKinds.Add(DetailsViewSizeKind.ExtraLarge, "ExtraLarge".GetLocalizedResource());
}

var stringValue = DetailsViewSizeKinds.GetValueOrDefault(value)!;
return stringValue;
}

public static string Get(ListViewSizeKind value)
{
if (ListViewSizeKinds.Count == 0)
{
ListViewSizeKinds.Add(ListViewSizeKind.Compact, "Compact".GetLocalizedResource());
ListViewSizeKinds.Add(ListViewSizeKind.Small, "Small".GetLocalizedResource());
ListViewSizeKinds.Add(ListViewSizeKind.Medium, "Medium".GetLocalizedResource());
ListViewSizeKinds.Add(ListViewSizeKind.Large, "Large".GetLocalizedResource());
ListViewSizeKinds.Add(ListViewSizeKind.ExtraLarge, "ExtraLarge".GetLocalizedResource());
}

var stringValue = ListViewSizeKinds.GetValueOrDefault(value)!;
return stringValue;
}

public static string Get(TilesViewSizeKind value)
{
if (TilesViewSizeKinds.Count == 0)
{
TilesViewSizeKinds.Add(TilesViewSizeKind.Small, "Small".GetLocalizedResource());
}

var stringValue = TilesViewSizeKinds.GetValueOrDefault(value)!;
return stringValue;
}

public static string Get(GridViewSizeKind value)
{
if (GridViewSizeKinds.Count == 0)
{
GridViewSizeKinds.Add(GridViewSizeKind.Small, "Small".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Medium, "Medium".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Three, "Medium+".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Four, "Medium++".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Five, "Medium+++".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Six, "Medium++++".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Seven, "Medium+++++".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Large, "Large".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Nine, "Large+".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Ten, "Large++".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.Eleven, "Large+++".GetLocalizedResource());
GridViewSizeKinds.Add(GridViewSizeKind.ExtraLarge, "ExtraLarge".GetLocalizedResource());
}

var stringValue = GridViewSizeKinds.GetValueOrDefault(value)!;
return stringValue;
}

public static string Get(ColumnsViewSizeKind value)
{
if (ColumnsViewSizeKinds.Count == 0)
{
ColumnsViewSizeKinds.Add(ColumnsViewSizeKind.Compact, "Compact".GetLocalizedResource());
ColumnsViewSizeKinds.Add(ColumnsViewSizeKind.Small, "Small".GetLocalizedResource());
ColumnsViewSizeKinds.Add(ColumnsViewSizeKind.Medium, "Medium".GetLocalizedResource());
ColumnsViewSizeKinds.Add(ColumnsViewSizeKind.Large, "Large".GetLocalizedResource());
ColumnsViewSizeKinds.Add(ColumnsViewSizeKind.ExtraLarge, "ExtraLarge".GetLocalizedResource());
}

var stringValue = ColumnsViewSizeKinds.GetValueOrDefault(value)!;
return stringValue;
}
}
}
52 changes: 52 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3673,4 +3673,56 @@
<data name="TilesViewSizeInfo" xml:space="preserve">
<value>Additional sizes are not yet available for the Tiles View.</value>
</data>
<data name="Compact" xml:space="preserve">
<value>Compact</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Small" xml:space="preserve">
<value>Small</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Medium" xml:space="preserve">
<value>Medium</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Medium+" xml:space="preserve">
<value>Medium +</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Medium++" xml:space="preserve">
<value>Medium ++</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Medium+++" xml:space="preserve">
<value>Medium +++</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Medium++++" xml:space="preserve">
<value>Medium ++++</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Medium+++++" xml:space="preserve">
<value>Medium +++++</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Large" xml:space="preserve">
<value>Large</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Large+" xml:space="preserve">
<value>Large +</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Large++" xml:space="preserve">
<value>Large ++</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="Large+++" xml:space="preserve">
<value>Large +++</value>
<comment>Used to describe layout sizes</comment>
</data>
<data name="ExtraLarge" xml:space="preserve">
<value>Extra large</value>
<comment>Used to describe layout sizes</comment>
</data>
</root>
14 changes: 10 additions & 4 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<SolidColorBrush x:Key="CommandBarBorderBrushOpen" Color="Transparent" />

<converters:GenericEnumConverter x:Key="GenericEnumConverter" />
<converters:EnumToHumanizedConverter x:Key="DetailsViewSizeKindEnumToHumanizedConverter" EnumTypeName="DetailsViewSizeKind" />
<converters:EnumToHumanizedConverter x:Key="ListViewSizeKindEnumToHumanizedConverter" EnumTypeName="ListViewSizeKind" />
<converters:EnumToHumanizedConverter x:Key="TilesViewSizeKindEnumToHumanizedConverter" EnumTypeName="TilesViewSizeKind" />
<converters:EnumToHumanizedConverter x:Key="GridViewSizeKindEnumToHumanizedConverter" EnumTypeName="GridViewSizeKind" />
<converters:EnumToHumanizedConverter x:Key="ColumnsViewSizeKindEnumToHumanizedConverter" EnumTypeName="ColumnsViewSizeKind" />
<wctconverters:BoolNegationConverter x:Key="BoolNegationConverter" />
<wctconverters:BoolToVisibilityConverter
x:Key="NegatedBoolToVisibilityConverter"
Expand Down Expand Up @@ -770,6 +775,7 @@
<!-- Sizes -->
<TextBlock FontWeight="Medium" Text="{helpers:ResourceString Name=Size}" />
<Grid>

<!-- Details -->
<StackPanel
x:Name="DetailsView"
Expand All @@ -778,10 +784,10 @@
<Slider
x:Name="DetailsViewSlider"
Padding="4,0,4,0"
IsThumbToolTipEnabled="False"
Maximum="5"
Minimum="1"
SnapsTo="Ticks"
ThumbToolTipValueConverter="{StaticResource DetailsViewSizeKindEnumToHumanizedConverter}"
TickFrequency="1"
TickPlacement="BottomRight"
Value="{x:Bind UserSettingsService.LayoutSettingsService.DetailsViewSize, Mode=TwoWay, Converter={StaticResource GenericEnumConverter}, ConverterParameter='1-1,2-2,3-3,4-4,5-5'}" />
Expand Down Expand Up @@ -844,10 +850,10 @@
<Slider
x:Name="ListViewSlider"
Padding="4,0,4,0"
IsThumbToolTipEnabled="False"
Maximum="5"
Minimum="1"
SnapsTo="Ticks"
ThumbToolTipValueConverter="{StaticResource ListViewSizeKindEnumToHumanizedConverter}"
TickFrequency="1"
TickPlacement="BottomRight"
Value="{x:Bind UserSettingsService.LayoutSettingsService.ListViewSize, Mode=TwoWay, Converter={StaticResource GenericEnumConverter}, ConverterParameter='1-1,2-2,3-3,4-4,5-5'}" />
Expand Down Expand Up @@ -927,10 +933,10 @@
<Slider
x:Name="GridViewSlider"
Padding="4,0,4,0"
IsThumbToolTipEnabled="False"
Maximum="12"
Minimum="1"
SnapsTo="Ticks"
ThumbToolTipValueConverter="{StaticResource GridViewSizeKindEnumToHumanizedConverter}"
TickFrequency="1"
TickPlacement="BottomRight"
Value="{x:Bind UserSettingsService.LayoutSettingsService.GridViewSize, Mode=TwoWay, Converter={StaticResource GenericEnumConverter}, ConverterParameter='1-1,2-2,3-3,4-4,5-5,6-6,7-7,8-8,9-9,10-10,11-11,12-12'}" />
Expand Down Expand Up @@ -1000,10 +1006,10 @@
<Slider
x:Name="ColumnViewSlider"
Padding="4,0,4,0"
IsThumbToolTipEnabled="False"
Maximum="5"
Minimum="1"
SnapsTo="Ticks"
ThumbToolTipValueConverter="{StaticResource ColumnsViewSizeKindEnumToHumanizedConverter}"
TickFrequency="1"
TickPlacement="BottomRight"
Value="{x:Bind UserSettingsService.LayoutSettingsService.ColumnsViewSize, Mode=TwoWay, Converter={StaticResource GenericEnumConverter}, ConverterParameter='1-1,2-2,3-3,4-4,5-5'}" />
Expand Down
22 changes: 22 additions & 0 deletions src/Files.Core/Data/Enums/ColumnsViewSizeKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@

namespace Files.Core.Data.Enums
{
/// <summary>
/// Defines constants that specify the size in the Columns View layout.
/// </summary>
public enum ColumnsViewSizeKind
{
/// <summary>
/// The size is compact.
/// </summary>
Compact = 1,

/// <summary>
/// The size is small.
/// </summary>
Small = 2,

/// <summary>
/// The size is medium.
/// </summary>
Medium = 3,

/// <summary>
/// The size is large.
/// </summary>
Large = 4,

/// <summary>
/// The size is extra large.
/// </summary>
ExtraLarge = 5,
}
}
22 changes: 22 additions & 0 deletions src/Files.Core/Data/Enums/DetailsViewSizeKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@

namespace Files.Core.Data.Enums
{
/// <summary>
/// Defines constants that specify the size in the Details View layout.
/// </summary>
public enum DetailsViewSizeKind
{
/// <summary>
/// The size is compact.
/// </summary>
Compact = 1,

/// <summary>
/// The size is small.
/// </summary>
Small = 2,

/// <summary>
/// The size is medium.
/// </summary>
Medium = 3,

/// <summary>
/// The size is large.
/// </summary>
Large = 4,

/// <summary>
/// The size is extra large.
/// </summary>
ExtraLarge = 5,
}
}
50 changes: 50 additions & 0 deletions src/Files.Core/Data/Enums/GridViewSizeKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,69 @@

namespace Files.Core.Data.Enums
{
/// <summary>
/// Defines constants that specify the size in the Grid View layout.
/// </summary>
public enum GridViewSizeKind
{
/// <summary>
/// The size is small.
/// </summary>
Small = 1,

/// <summary>
/// The size is medium.
/// </summary>
Medium = 2,

/// <summary>
/// The size is medium+.
/// </summary>
Three = 3,

/// <summary>
/// The size is medium++.
/// </summary>
Four = 4,

/// <summary>
/// The size is medium+++.
/// </summary>
Five = 5,

/// <summary>
/// The size is medium++++.
/// </summary>
Six = 6,

/// <summary>
/// The size is medium+++++.
/// </summary>
Seven = 7,

/// <summary>
/// The size is large.
/// </summary>
Large = 8,

/// <summary>
/// The size is large+.
/// </summary>
Nine = 9,

/// <summary>
/// The size is large++.
/// </summary>
Ten = 10,

/// <summary>
/// The size is large+++.
/// </summary>
Eleven = 11,

/// <summary>
/// The size is extra large.
/// </summary>
ExtraLarge = 12,
}
}
Loading
Loading