Skip to content
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 loader = 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() => loader.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)
{
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
Loaded="SettingsBlockControl_Loaded"
mc:Ignorable="d">

<UserControl.Resources>
Expand Down
122 changes: 40 additions & 82 deletions src/Files.App/UserControls/Settings/SettingsBlockControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,134 +10,92 @@ namespace Files.App.UserControls.Settings
[ContentProperty(Name = nameof(SettingsActionableElement))]
public sealed partial class SettingsBlockControl : UserControl
{
public FrameworkElement SettingsActionableElement { get; set; }
public event EventHandler<bool>? Click;

public ICommand ButtonCommand
{
get { return (ICommand)GetValue(ButtonCommandProperty); }
set { SetValue(ButtonCommandProperty, value); }
}
public static readonly DependencyProperty ButtonCommandProperty =
DependencyProperty.Register("ButtonCommand", typeof(ICommand), typeof(SettingsBlockControl), new PropertyMetadata(null));
public static readonly DependencyProperty TitleProperty = DependencyProperty
.Register(nameof(Title), typeof(string), typeof(SettingsBlockControl), new(null));

public static readonly DependencyProperty ExpandableContentProperty = DependencyProperty.Register(
"ExpandableContent",
typeof(FrameworkElement),
typeof(SettingsBlockControl),
new PropertyMetadata(null)
);
public static readonly DependencyProperty DescriptionProperty = DependencyProperty
.Register(nameof(Description), typeof(string), typeof(SettingsBlockControl), new(null));

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

public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty.Register(
"AdditionalDescriptionContent",
typeof(FrameworkElement),
typeof(SettingsBlockControl),
new PropertyMetadata(null)
);
public static readonly DependencyProperty IconProperty = DependencyProperty
.Register(nameof(Icon), typeof(IconElement), typeof(SettingsBlockControl), new(null));

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

public static readonly DependencyProperty IsClickableProperty = DependencyProperty
.Register(nameof(IsClickable), typeof(bool), typeof(SettingsBlockControl), new(false));

public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
"Title",
typeof(string),
typeof(SettingsBlockControl),
new PropertyMetadata(null)
);
public static readonly DependencyProperty IsExpandedProperty = DependencyProperty
.Register(nameof(IsExpanded), typeof(bool), typeof(SettingsBlockControl), new(false));

public static readonly DependencyProperty ExpandableContentProperty = DependencyProperty
.Register(nameof(ExpandableContent), typeof(FrameworkElement), typeof(SettingsBlockControl), new(null));

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

public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
"Description",
typeof(string),
typeof(SettingsBlockControl),
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(SettingsBlockControl),
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 static readonly DependencyProperty IsClickableProperty = DependencyProperty.Register(
"IsClickable",
typeof(bool),
typeof(SettingsBlockControl),
new PropertyMetadata(false)
);
public ICommand ButtonCommand
{
get => (ICommand)GetValue(ButtonCommandProperty);
set => SetValue(ButtonCommandProperty, value);
}

public bool IsClickable
{
get => (bool)GetValue(IsClickableProperty);
set => SetValue(IsClickableProperty, value);
}

public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register(
"IsExpanded",
typeof(bool),
typeof(SettingsBlockControl),
new PropertyMetadata(false)
);

public bool IsExpanded
{
get => (bool)GetValue(IsExpandedProperty);
set => SetValue(IsExpandedProperty, value);
}

//
// Summary:
// Occurs when a button control is clicked.
public event EventHandler<bool> Click;

public SettingsBlockControl()
public FrameworkElement ExpandableContent
{
this.InitializeComponent();
this.Loaded += SettingsBlockControl_Loaded;
get => (FrameworkElement)GetValue(ExpandableContentProperty);
set => SetValue(ExpandableContentProperty, value);
}

private void SettingsBlockControl_Loaded(object sender, RoutedEventArgs e)
public FrameworkElement? SettingsActionableElement { get; set; }

public SettingsBlockControl() => InitializeComponent();

private void SettingsBlockControl_Loaded(object _, RoutedEventArgs e)
{
Loaded -= SettingsBlockControl_Loaded;
if (ActionableButton is not null)
{
AutomationProperties.SetName(ActionableButton, Title);
}
}

private void Expander_Expanding(Microsoft.UI.Xaml.Controls.Expander sender, Microsoft.UI.Xaml.Controls.ExpanderExpandingEventArgs args)
{
Click?.Invoke(this, true);
}

private void Expander_Collapsed(Microsoft.UI.Xaml.Controls.Expander sender, Microsoft.UI.Xaml.Controls.ExpanderCollapsedEventArgs args)
{
Click?.Invoke(this, false);
}
private void Expander_Collapsed(Expander _, ExpanderCollapsedEventArgs e) => Click?.Invoke(this, false);
private void Expander_Expanding(Expander _, ExpanderExpandingEventArgs e) => Click?.Invoke(this, true);
}
}
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; }
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