Skip to content

Code Quality: Merged App.ValueConverters with App.Converters #12235

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

Merged
merged 5 commits into from
May 1, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Files.App.Converters
{
internal class BoolToSelectionMode : IValueConverter
internal sealed class BoolToSelectionModeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Microsoft.UI.Xaml.Data;

namespace Files.App.ValueConverters.EnumConverters
namespace Files.App.Converters
{
internal sealed class ConflictResolveOptionToIndexConverter : IValueConverter
{
Expand Down
10 changes: 5 additions & 5 deletions src/Files.App/Converters/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Files.App.Converters
/// </summary>
/// <typeparam name="TSource">The source type.</typeparam>
/// <typeparam name="TTarget">The target type.</typeparam>
public abstract class ValueConverter<TSource, TTarget> : IValueConverter
internal abstract class ValueConverter<TSource, TTarget> : IValueConverter
{
/// <summary>
/// Converts a source value to the target type.
Expand Down Expand Up @@ -89,7 +89,7 @@ public abstract class ValueConverter<TSource, TTarget> : IValueConverter
/// <summary>
/// The base class for converting instances of type T to object and vice versa.
/// </summary>
public abstract class ToObjectConverter<T> : ValueConverter<T?, object?>
internal abstract class ToObjectConverter<T> : ValueConverter<T?, object?>
{
/// <summary>
/// Converts a source value to the target type.
Expand Down Expand Up @@ -119,7 +119,7 @@ public abstract class ToObjectConverter<T> : ValueConverter<T?, object?>
/// <summary>
/// Converts a boolean to and from a visibility value.
/// </summary>
public class InverseBooleanConverter : ValueConverter<bool, bool>
internal sealed class InverseBooleanConverter : ValueConverter<bool, bool>
{
/// <summary>
/// Converts a source value to the target type.
Expand All @@ -146,7 +146,7 @@ protected override bool ConvertBack(bool value, object? parameter, string? langu
}
}

public class NullToTrueConverter : ValueConverter<object?, bool>
internal sealed class NullToTrueConverter : ValueConverter<object?, bool>
{
/// <summary>
/// Determines whether an inverse conversion should take place.
Expand Down Expand Up @@ -179,7 +179,7 @@ protected override bool Convert(object? value, object? parameter, string? langua
}
}

public class StringNullOrWhiteSpaceToTrueConverter : ValueConverter<string, bool>
internal sealed class StringNullOrWhiteSpaceToTrueConverter : ValueConverter<string, bool>
{
/// <summary>
/// Determines whether an inverse conversion should take place.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Files.App.Converters
{
internal class DateTimeOffsetToString : IValueConverter
internal sealed class DateTimeOffsetToStringConverter : IValueConverter
{
private static readonly IDateTimeFormatter formatter = Ioc.Default.GetService<IDateTimeFormatter>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Files.App.Converters
{
internal class DoubleArrayToString : IValueConverter
internal sealed class DoubleArrayToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Files.App.Converters
{
internal class DoubleToString : IValueConverter
internal sealed class DoubleToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Microsoft.UI.Xaml.Data;

namespace Files.App.ValueConverters
namespace Files.App.Converters
{
internal sealed class GenericEnumConverter : IValueConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Microsoft.UI.Xaml.Data;

namespace Files.App.ValueConverters
namespace Files.App.Converters
{
internal sealed class ImageModelToImageConverter : IValueConverter
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Converters/MultiBooleanConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Files.App.Converters
{
internal class MultiBooleanConverter
internal sealed class MultiBooleanConverter
{
public static Boolean OrConvert(bool a, bool b)
=> (a || b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Files.App.Converters
{
internal class StorageDeleteOptionToBooleanConverter : IValueConverter
internal sealed class StorageDeleteOptionToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Files.App.Converters
{
internal class StringArrayToString : IValueConverter
internal sealed class StringArrayToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;

namespace Files.App.ValueConverters
namespace Files.App.Converters
{
internal sealed class StringToBrushConverter : IValueConverter
{
Expand All @@ -14,7 +14,7 @@ internal sealed class StringToBrushConverter : IValueConverter
if (value is not string strValue)
return null;

return new SolidColorBrush(ColorHelper.ToColor(strValue));
return new SolidColorBrush(strValue.ToColor());
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Files.App.Converters
{
internal class UInt32ToString : IValueConverter
internal sealed class UInt32ToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Converters/VisibilityInvertConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Files.App.Converters
{
public class VisibilityInvertConverter : IValueConverter
internal sealed class VisibilityInvertConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Dialogs/AddItemDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
x:Class="Files.App.Dialogs.AddItemDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:Files.App.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vc="using:Files.App.ValueConverters"
xmlns:vm="using:Files.Backend.ViewModels.Dialogs.AddItemDialog"
x:Name="AddDialog"
Title="{helpers:ResourceString Name=AddDialog/Title}"
Expand All @@ -20,7 +20,7 @@
mc:Ignorable="d">

<ContentDialog.Resources>
<vc:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
<converters:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
</ContentDialog.Resources>

<Grid RowSpacing="25">
Expand Down
12 changes: 5 additions & 7 deletions src/Files.App/Dialogs/FilesystemOperationDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
x:Class="Files.App.Dialogs.FilesystemOperationDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:Files.App.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ts="using:Files.App.TemplateSelectors"
xmlns:tvc="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:vc="using:Files.App.ValueConverters"
xmlns:vc2="using:Files.App.ValueConverters.EnumConverters"
xmlns:vc3="using:Files.App.Converters"
xmlns:vm="using:Files.Backend.ViewModels.Dialogs.FileSystemDialog"
x:Name="RootDialog"
Title="{x:Bind ViewModel.Title, Mode=OneWay}"
Expand All @@ -29,10 +27,10 @@
<ContentDialog.Resources>
<x:Double x:Key="ContentDialogMaxWidth">800</x:Double>

<vc:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
<vc:GenericEnumConverter x:Key="GenericEnumConverter" />
<vc2:ConflictResolveOptionToIndexConverter x:Key="ConflictResolveOptionToIndexConverter" />
<vc3:VisibilityInvertConverter x:Key="VisibilityInvertConverter" />
<converters:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
<converters:GenericEnumConverter x:Key="GenericEnumConverter" />
<converters:ConflictResolveOptionToIndexConverter x:Key="ConflictResolveOptionToIndexConverter" />
<converters:VisibilityInvertConverter x:Key="VisibilityInvertConverter" />
<tvc:BoolNegationConverter x:Key="BoolNegationConverter" />

<DataTemplate x:Key="ConflictItemDataTemplate" x:DataType="vm:FileSystemDialogConflictItemViewModel">
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/ResourceDictionaries/PropertiesStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
<Setter Property="FontSize" Value="14" />
</Style>

<converters:StringArrayToString x:Key="StringArrayToString" />
<converters:UInt32ToString x:Key="UInt32ToString" />
<converters:DoubleToString x:Key="DoubleToString" />
<converters:DateTimeOffsetToString x:Key="DateTimeOffsetToString" />
<converters:StringArrayToStringConverter x:Key="StringArrayToString" />
<converters:UInt32ToStringConverter x:Key="UInt32ToString" />
<converters:DoubleToStringConverter x:Key="DoubleToString" />
<converters:DateTimeOffsetToStringConverter x:Key="DateTimeOffsetToString" />

<Style x:Key="Separator" TargetType="MenuFlyoutSeparator">
<Setter Property="Grid.Column" Value="0" />
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/UserControls/SidebarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
xmlns:local="using:Files.App.UserControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mconv="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:converters="using:Files.App.Converters"
xmlns:dataitems="using:Files.App.Data.Items"
xmlns:vc="using:Files.App.ValueConverters"
HorizontalAlignment="Stretch"
Collapsed="NavigationView_Collapsed"
DisplayModeChanged="SidebarControl_DisplayModeChanged"
Expand Down Expand Up @@ -52,7 +52,7 @@

<mconv:BoolNegationConverter x:Key="BoolNegationConverter" />
<mconv:StringFormatConverter x:Key="StringFormatConverter" />
<vc:StringToBrushConverter x:Key="StringToBrushConverter" />
<converters:StringToBrushConverter x:Key="StringToBrushConverter" />
<DataTemplate x:Key="LocationNavItem" x:DataType="dataitems:LocationItem">
<NavigationViewItem
AllowDrop="True"
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/UserControls/Widgets/FileTagsWidget.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:converters="using:Files.App.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:local="using:Files.App.UserControls.Widgets"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vc="using:Files.App.ValueConverters"
xmlns:vm="using:Files.App.ViewModels.Widgets"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<UserControl.Resources>
<vc:StringToBrushConverter x:Key="StringToBrushConverter" />
<vc:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
<converters:StringToBrushConverter x:Key="StringToBrushConverter" />
<converters:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
</UserControl.Resources>

<!-- Collection of containers -->
Expand Down
10 changes: 5 additions & 5 deletions src/Files.App/ViewModels/Properties/Items/FileProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,29 @@ private IValueConverter GetConverter()
{
if (Value is uint)
{
return new UInt32ToString();
return new UInt32ToStringConverter();
}

if (Value is double)
{
return new DoubleToString();
return new DoubleToStringConverter();
}

if (Value is DateTimeOffset)
{
return new DateTimeOffsetToString();
return new DateTimeOffsetToStringConverter();
}

if (Value is not null && Value.GetType().IsArray)
{
if (Value.GetType().GetElementType().Equals(typeof(string)))
{
return new StringArrayToString();
return new StringArrayToStringConverter();
}

if (Value.GetType().GetElementType().Equals(typeof(double)))
{
return new DoubleArrayToString();
return new DoubleArrayToStringConverter();
}
}
return null;
Expand Down
5 changes: 2 additions & 3 deletions src/Files.App/Views/LayoutModes/ColumnViewBase.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
xmlns:local="using:Files.App"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="using:Files.App.UserControls"
xmlns:valueconverters="using:Files.App.ValueConverters"
xmlns:wct="using:CommunityToolkit.WinUI.UI"
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
x:Name="PageRoot"
mc:Ignorable="d">

<local:StandardViewBase.Resources>

<valueconverters:StringToBrushConverter x:Key="StringToBrushConverter" />
<converters:StringToBrushConverter x:Key="StringToBrushConverter" />
<wctconverters:BoolNegationConverter x:Key="BoolNegationConverter" />
<wctconverters:BoolToVisibilityConverter
x:Key="NegatedBoolToVisibilityConverter"
Expand All @@ -33,7 +32,7 @@
x:Key="EmptyObjectToObjectConverter"
EmptyValue="Collapsed"
NotEmptyValue="Visible" />
<converters:BoolToSelectionMode x:Key="BoolToSelectionModeConverter" />
<converters:BoolToSelectionModeConverter x:Key="BoolToSelectionModeConverter" />

<Style TargetType="ListViewHeaderItem">
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
Expand Down
5 changes: 2 additions & 3 deletions src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:uc="using:Files.App.UserControls"
xmlns:valueconverters="using:Files.App.ValueConverters"
xmlns:wct="using:CommunityToolkit.WinUI.UI"
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
x:Name="PageRoot"
Expand Down Expand Up @@ -46,8 +45,8 @@
x:Key="EmptyObjectToObjectConverter"
EmptyValue="Collapsed"
NotEmptyValue="Visible" />
<valueconverters:StringToBrushConverter x:Key="StringToBrushConverter" />
<converters:BoolToSelectionMode x:Key="BoolToSelectionModeConverter" />
<converters:StringToBrushConverter x:Key="StringToBrushConverter" />
<converters:BoolToSelectionModeConverter x:Key="BoolToSelectionModeConverter" />
<wctconverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />

<Style
Expand Down
5 changes: 2 additions & 3 deletions src/Files.App/Views/LayoutModes/GridViewBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:tui="using:CommunityToolkit.WinUI.UI"
xmlns:uc="using:Files.App.UserControls"
xmlns:vc="using:Files.App.ValueConverters"
xmlns:wctanimations="using:CommunityToolkit.WinUI.UI.Animations"
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
x:Name="PageRoot"
Expand All @@ -33,7 +32,7 @@

<root:StandardViewBase.Resources>

<vc:StringToBrushConverter x:Key="StringToBrushConverter" />
<converters:StringToBrushConverter x:Key="StringToBrushConverter" />
<wctconverters:BoolNegationConverter x:Key="BoolNegationConverter" />
<wctconverters:BoolToVisibilityConverter
x:Key="NegatedBoolToVisibilityConverter"
Expand All @@ -52,7 +51,7 @@
x:Key="BoolToVisibilityConverter"
FalseValue="Collapsed"
TrueValue="Visible" />
<converters:BoolToSelectionMode x:Key="BoolToSelectionModeConverter" />
<converters:BoolToSelectionModeConverter x:Key="BoolToSelectionModeConverter" />

<DataTemplate x:Name="GridViewBrowserTemplate" x:DataType="filesystem:ListedItem">
<UserControl>
Expand Down
Loading