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

Code Quality: Code cleanup and formatting #11156

Merged
merged 16 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
151 changes: 117 additions & 34 deletions src/Files.App/BaseLayout.cs

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions src/Files.App/Behaviors/StickyHeaderBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

yaira2 marked this conversation as resolved.
Show resolved Hide resolved
using CommunityToolkit.WinUI.UI;
using CommunityToolkit.WinUI.UI.Animations.Expressions;
using CommunityToolkit.WinUI.UI.Behaviors;
Expand Down Expand Up @@ -54,8 +50,12 @@ protected override bool Uninitialize()
/// <summary>
/// The UIElement that will be faded.
/// </summary>
public static readonly DependencyProperty HeaderElementProperty = DependencyProperty.Register(
nameof(HeaderElement), typeof(UIElement), typeof(StickyHeaderBehavior), new PropertyMetadata(null, PropertyChangedCallback));
public static readonly DependencyProperty HeaderElementProperty =
DependencyProperty.Register(
nameof(HeaderElement),
typeof(UIElement),
typeof(StickyHeaderBehavior),
new PropertyMetadata(null, PropertyChangedCallback));

private ScrollViewer _scrollViewer;
private CompositionPropertySet _scrollProperties;
Expand All @@ -71,8 +71,8 @@ protected override bool Uninitialize()
/// </remarks>
public UIElement HeaderElement
{
get { return (UIElement)GetValue(HeaderElementProperty); }
set { SetValue(HeaderElementProperty, value); }
get => (UIElement)GetValue(HeaderElementProperty);
set => SetValue(HeaderElementProperty, value);
}

/// <summary>
Expand Down Expand Up @@ -119,7 +119,7 @@ private bool AssignAnimation()
if (HeaderElement is null && listView is not null)
HeaderElement = listView.Header as UIElement;

var headerElement = HeaderElement as FrameworkElement;
FrameworkElement? headerElement = HeaderElement as FrameworkElement;

if (headerElement is null || headerElement.RenderSize.Height == 0)
return false;
Expand Down Expand Up @@ -212,6 +212,7 @@ private void ScrollViewer_GotFocus(object sender, RoutedEventArgs e)
var scroller = (ScrollViewer)sender;

object focusedElement;

if (IsXamlRootAvailable && scroller.XamlRoot is not null)
{
focusedElement = FocusManager.GetFocusedElement(scroller.XamlRoot);
Expand Down Expand Up @@ -239,4 +240,4 @@ private void ScrollViewer_GotFocus(object sender, RoutedEventArgs e)
}
}
}
}
}
14 changes: 10 additions & 4 deletions src/Files.App/CommandLine/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private static ParsedCommands ParseSplitArguments(List<KeyValuePair<string, stri
Debug.WriteLine($"Exception in CommandLineParser.cs\\ParseUntrustedCommands with message: {ex.Message}");
command.Type = ParsedCommandType.Unknown;
}

break;
}

Expand Down Expand Up @@ -149,16 +150,21 @@ private static KeyValuePair<string, string[]> ParseData(string[] args, int index
{
string? key = null;
var val = new List<string>();

if (args[index].StartsWith('-') || args[index].StartsWith('/'))
{
if (args[index].Contains(':', StringComparison.Ordinal))
{
string argument = args[index];
int endIndex = argument.IndexOf(':');
key = argument.Substring(1, endIndex - 1); // trim the '/' and the ':'.

// Trim the '/' and the ':'
key = argument.Substring(1, endIndex - 1);

int valueStart = endIndex + 1;
val.Add(valueStart < argument.Length ? argument.Substring(
valueStart, argument.Length - valueStart) : null);
val.Add(valueStart < argument.Length
? argument.Substring(valueStart, argument.Length - valueStart)
: null);
}
else
{
Expand All @@ -175,4 +181,4 @@ private static KeyValuePair<string, string[]> ParseData(string[] args, int index
return key is not null ? new KeyValuePair<string, string[]>(key, val.ToArray()) : default;
}
}
}
}
5 changes: 3 additions & 2 deletions src/Files.App/CommandLine/ParsedCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ internal class ParsedCommand
{
public ParsedCommandType Type { get; set; }

public string Payload => Args.FirstOrDefault();
public string Payload
=> Args.FirstOrDefault();

public List<string> Args { get; set; }

public ParsedCommand() =>
Args = new List<string>();
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/CommandLine/ParsedCommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ internal enum ParsedCommandType
SelectItem,
TagFiles
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/CommandLine/ParsedCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ namespace Files.App.CommandLine
internal class ParsedCommands : List<ParsedCommand>
{
}
}
}
24 changes: 17 additions & 7 deletions src/Files.App/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,20 @@ public static class UI

public const double MaximumSidebarWidth = 500;

public const double ContextMenuMaxHeight = 480; // For contextmenu hacks, must match WinUI style
public const double ContextMenuSecondaryItemsHeight = 32; // For contextmenu hacks, must match WinUI style
public const double ContextMenuPrimaryItemsHeight = 48; // For contextmenu hacks, must match WinUI style
public const double ContextMenuLabelMargin = 10; // For contextmenu hacks
public const double ContextMenuItemsMaxWidth = 250; // For contextmenu hacks
// For contextmenu hacks, must match WinUI style
public const double ContextMenuMaxHeight = 480;

// For contextmenu hacks, must match WinUI style
public const double ContextMenuSecondaryItemsHeight = 32;

// For contextmenu hacks, must match WinUI style
public const double ContextMenuPrimaryItemsHeight = 48;

// For contextmenu hacks
public const double ContextMenuLabelMargin = 10;

// For contextmenu hacks
public const double ContextMenuItemsMaxWidth = 250;
}

public static class Browser
Expand All @@ -105,7 +114,8 @@ public static class GridViewBrowser
{
public const int GridViewIncrement = 20;

public const int GridViewSizeMax = 300; // Max achievable ctrl + scroll, not a default layout size.
// Max achievable ctrl + scroll, not a default layout size
public const int GridViewSizeMax = 300;

public const int GridViewSizeLarge = 220;

Expand Down Expand Up @@ -208,4 +218,4 @@ public static class GitHub
public const string SupportUsUrl = @"https://github.com/sponsors/yaira2";
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Controllers/IJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ internal interface IJson

void SaveModel();
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/BoolToSelectionMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
return ((value as ListViewSelectionMode?) ?? ListViewSelectionMode.Extended) == ListViewSelectionMode.Multiple;
}
}
}
}
17 changes: 6 additions & 11 deletions src/Files.App/Converters/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,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
public abstract class ValueConverter<TSource, TTarget> : IValueConverter
{
/// <summary>
/// Converts a source value to the target type.
Expand Down Expand Up @@ -88,8 +87,7 @@ public abstract class ValueConverter<TSource, TTarget>
/// <summary>
/// The base class for converting instances of type T to object and vice versa.
/// </summary>
public abstract class ToObjectConverter<T>
: ValueConverter<T?, object?>
public abstract class ToObjectConverter<T> : ValueConverter<T?, object?>
{
/// <summary>
/// Converts a source value to the target type.
Expand Down Expand Up @@ -119,8 +117,7 @@ public abstract class ToObjectConverter<T>
/// <summary>
/// Converts a boolean to and from a visibility value.
/// </summary>
public class InverseBooleanConverter
: ValueConverter<bool, bool>
public class InverseBooleanConverter : ValueConverter<bool, bool>
{
/// <summary>
/// Converts a source value to the target type.
Expand All @@ -147,8 +144,7 @@ protected override bool ConvertBack(bool value, object? parameter, string? langu
}
}

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

public class StringNullOrWhiteSpaceToTrueConverter
: ValueConverter<string, bool>
public class StringNullOrWhiteSpaceToTrueConverter : ValueConverter<string, bool>
{
/// <summary>
/// Determines whether an inverse conversion should take place.
Expand Down Expand Up @@ -214,4 +209,4 @@ protected override string ConvertBack(bool value, object? parameter, string? lan
return string.Empty;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/DateTimeOffsetToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/Files.App/Converters/DoubleArrayToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
{
var strArray = (value as string).Split("; ");
var array = new double[strArray.Length];

for (int i = 0; i < strArray.Length; i++)
{
try
Expand All @@ -40,4 +41,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
return array;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/DoubleToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/IntToGroupOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/IntToSortDirection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/IntToSortOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/MiddleTextEllipsisConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
throw new NotImplementedException();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/MultiBooleanConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public static Visibility OrConvertToVisibility(bool a, bool b)
public static Visibility OrNotConvertToVisibility(bool a, bool b)
=> OrConvertToVisibility(a, !b);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
return (value is bool bl && bl) ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Converters/StringArrayToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
return (value as string).Split("; ");
}
}
}
}
4 changes: 2 additions & 2 deletions src/Files.App/Converters/UInt32ToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
{
try
{
return UInt32.Parse(value as string);
return uint.Parse(value as string);
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
}
catch (FormatException)
{
return null;
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/Files.App/Converters/VisibilityInvertConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public object Convert(object value, Type targetType, object parameter, string la
{
return isVisible ? Visibility.Collapsed : Visibility.Visible;
}

return (Visibility)value == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}

Expand All @@ -20,4 +21,4 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
throw new NotImplementedException();
}
}
}
}
8 changes: 4 additions & 4 deletions src/Files.App/DataModels/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AppModel()
FoldersSettings.PropertyChanged += FoldersSettings_PropertyChanged; ;
Clipboard.ContentChanged += Clipboard_ContentChanged;

//todo: this doesn't belong here
// TODO: This doesn't belong here
DetectFontName();
}

Expand All @@ -40,7 +40,7 @@ private void FoldersSettings_PropertyChanged(object? sender, System.ComponentMod
}
}

//todo: refactor this method
// TODO: Refactor this method
public void Clipboard_ContentChanged(object sender, object e)
{
try
Expand Down Expand Up @@ -105,7 +105,7 @@ public FontFamily SymbolFontFamily
set => SetProperty(ref symbolFontFamily, value);
}

//todo: refactor this method
// TODO: Refactor this method
private void DetectFontName()
{
var rawVersion = ulong.Parse(AnalyticsInfo.VersionInfo.DeviceFamilyVersion);
Expand All @@ -116,4 +116,4 @@ private void DetectFontName()
SymbolFontFamily = (isWindows11) ? new FontFamily("Segoe Fluent Icons") : new FontFamily("Segoe MDL2 Assets");
}
}
}
}
Loading