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: Formatted code for readability #10537

Merged
merged 10 commits into from
Jan 16, 2023
12 changes: 3 additions & 9 deletions src/Files.App/Helpers/ResourceHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ namespace Files.App.Helpers
[MarkupExtensionReturnType(ReturnType = typeof(string))]
public sealed class ResourceString : MarkupExtension
{
private static ResourceLoader resourceLoader = new ResourceLoader();
private static readonly ResourceLoader resourceLoader = new();

public string Name
{
get; set;
}
public string Name { get; set; } = string.Empty;

protected override object ProvideValue()
{
return resourceLoader.GetString(this.Name);
}
protected override object ProvideValue() => resourceLoader.GetString(Name);
}
}
17 changes: 6 additions & 11 deletions src/Files.App/Serialization/BaseObservableJsonSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@ internal abstract class BaseObservableJsonSettings : BaseJsonSettings, INotifyPr
{
public event PropertyChangedEventHandler? PropertyChanged;

protected override bool Set<TValue>(TValue? value, [CallerMemberName] string propertyName = "")
where TValue : default
protected override bool Set<TValue>(TValue? value, [CallerMemberName] string propertyName = "") where TValue : default
{
if (base.Set<TValue>(value, propertyName))
{
OnPropertyChanged(propertyName);
return true;
}
if (!base.Set<TValue>(value, propertyName))
return false;

return false;
OnPropertyChanged(propertyName);
return true;
}

protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
18 changes: 5 additions & 13 deletions src/Files.App/Shell/ContextMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace Files.App.Shell
{
public class ContextMenuItem : Win32ContextMenuItem, IDisposable
{
public ContextMenuItem()
{
SubItems = new List<Win32ContextMenuItem>();
}
public ContextMenuItem() => SubItems = new List<Win32ContextMenuItem>();

public void Dispose()
{
Expand All @@ -19,17 +16,12 @@ public void Dispose()

protected virtual void Dispose(bool disposing)
{
if (disposing)
if (disposing && SubItems is not null)
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
if (SubItems is not null)
{
foreach (var si in SubItems)
{
(si as IDisposable)?.Dispose();
}
foreach (var subItem in SubItems)
(subItem as IDisposable)?.Dispose();

SubItems = null;
}
SubItems = null;
}
}
}
Expand Down
52 changes: 18 additions & 34 deletions src/Files.App/UserControls/Settings/SettingsDisplayControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,53 @@ namespace Files.App.UserControls.Settings
[ContentProperty(Name = nameof(SettingsActionableElement))]
public sealed partial class SettingsDisplayControl : UserControl
{
public FrameworkElement SettingsActionableElement { get; set; }
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
public static readonly DependencyProperty TitleProperty = DependencyProperty
.Register(nameof(Title), typeof(string), typeof(SettingsDisplayControl), new(null));

public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty.Register(
"AdditionalDescriptionContent",
typeof(FrameworkElement),
typeof(SettingsDisplayControl),
new PropertyMetadata(null)
);
public static readonly DependencyProperty DescriptionProperty = DependencyProperty
.Register(nameof(Description), typeof(string), typeof(SettingsDisplayControl), new(null));

public FrameworkElement AdditionalDescriptionContent
{
get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty);
set => SetValue(AdditionalDescriptionContentProperty, value);
}
public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty
.Register(nameof(AdditionalDescriptionContent), typeof(FrameworkElement), typeof(SettingsDisplayControl), new(null));

public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
"Title",
typeof(string),
typeof(SettingsDisplayControl),
new PropertyMetadata(null)
);
public static readonly DependencyProperty IconProperty = DependencyProperty
.Register(nameof(Icon), typeof(IconElement), typeof(SettingsDisplayControl), new(null));

public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}

public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
"Description",
typeof(string),
typeof(SettingsDisplayControl),
new PropertyMetadata(null)
);

public string Description
{
get => (string)GetValue(DescriptionProperty);
set => SetValue(DescriptionProperty, value);
}

public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
"Icon",
typeof(IconElement),
typeof(SettingsDisplayControl),
new PropertyMetadata(null)
);
public FrameworkElement AdditionalDescriptionContent
{
get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty);
set => SetValue(AdditionalDescriptionContentProperty, value);
}

public IconElement Icon
{
get => (IconElement)GetValue(IconProperty);
set => SetValue(IconProperty, value);
}

public FrameworkElement? SettingsActionableElement { get; set; }

public SettingsDisplayControl()
{
this.InitializeComponent();
InitializeComponent();
VisualStateManager.GoToState(this, "NormalState", false);
}

private void MainPanel_SizeChanged(object sender, SizeChangedEventArgs e)
private void MainPanel_SizeChanged(object _, SizeChangedEventArgs e)
{
if (e.NewSize.Width == e.PreviousSize.Width || ActionableElement is null)
if (ActionableElement is null || e.NewSize.Width == e.PreviousSize.Width)
return;

var stateToGoName = (ActionableElement.ActualWidth > e.NewSize.Width / 3) ? "CompactState" : "NormalState";
Expand Down