diff --git a/Directory.Packages.props b/Directory.Packages.props index a73c5be55fd6..53f4941b631f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,6 +7,7 @@ + diff --git a/src/Files.App.Controls/Files.App.Controls.csproj b/src/Files.App.Controls/Files.App.Controls.csproj index 12c0ab679abb..e2f44e087d4d 100644 --- a/src/Files.App.Controls/Files.App.Controls.csproj +++ b/src/Files.App.Controls/Files.App.Controls.csproj @@ -14,6 +14,7 @@ + diff --git a/src/Files.App.Controls/Storage/RingShape/RingShape.Properties.cs b/src/Files.App.Controls/Storage/RingShape/RingShape.Properties.cs index ddf4f311dbdd..349df99af071 100644 --- a/src/Files.App.Controls/Storage/RingShape/RingShape.Properties.cs +++ b/src/Files.App.Controls/Storage/RingShape/RingShape.Properties.cs @@ -1,6 +1,7 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Shapes; @@ -8,55 +9,77 @@ namespace Files.App.Controls.Primitives { - [DependencyProperty("StartAngle", nameof(OnStartAngleChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("EndAngle", nameof(OnEndAngleChanged), DefaultValue = "(double)90.0")] - [DependencyProperty("SweepDirection", nameof(OnSweepDirectionChanged), DefaultValue = "global::Microsoft.UI.Xaml.Media.SweepDirection.Clockwise")] - [DependencyProperty("MinAngle", nameof(OnMinAngleChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("MaxAngle", nameof(OnMaxAngleChanged), DefaultValue = "(double)360.0")] - [DependencyProperty("RadiusWidth", nameof(OnRadiusWidthChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("RadiusHeight", nameof(OnRadiusHeightChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("IsCircle", nameof(OnIsCircleChanged), DefaultValue = "(bool)false")] - [DependencyProperty("Center")] - [DependencyProperty("ActualRadiusWidth")] - [DependencyProperty("ActualRadiusHeight")] public partial class RingShape : Path { - protected virtual void OnStartAngleChanged(double oldValue, double newValue) + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double StartAngle { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 90.0d)] + public partial double EndAngle { get; set; } + + [GeneratedDependencyProperty(DefaultValue = SweepDirection.Clockwise)] + public partial SweepDirection SweepDirection { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double MinAngle { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 360.0d)] + public partial double MaxAngle { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double RadiusWidth { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double RadiusHeight { get; set; } + + [GeneratedDependencyProperty] + public partial bool IsCircle { get; set; } + + [GeneratedDependencyProperty] + public partial Point Center { get; set; } + + [GeneratedDependencyProperty] + public partial double ActualRadiusWidth { get; set; } + + [GeneratedDependencyProperty] + public partial double ActualRadiusHeight { get; set; } + + partial void OnStartAngleChanged(double newValue) { StartAngleChanged(); } - protected virtual void OnEndAngleChanged(double oldValue, double newValue) + partial void OnEndAngleChanged(double newValue) { EndAngleChanged(); } - protected virtual void OnSweepDirectionChanged(SweepDirection oldValue, SweepDirection newValue) + partial void OnSweepDirectionChanged(SweepDirection newValue) { SweepDirectionChanged(); } - protected virtual void OnMinAngleChanged(double oldValue, double newValue) + partial void OnMinAngleChanged(double newValue) { MinMaxAngleChanged(false); } - protected virtual void OnMaxAngleChanged(double oldValue, double newValue) + partial void OnMaxAngleChanged(double newValue) { MinMaxAngleChanged(true); } - protected virtual void OnRadiusWidthChanged(double oldValue, double newValue) + partial void OnRadiusWidthChanged(double newValue) { RadiusWidthChanged(); } - protected virtual void OnRadiusHeightChanged(double oldValue, double newValue) + partial void OnRadiusHeightChanged(double newValue) { RadiusHeightChanged(); } - protected virtual void OnIsCircleChanged(bool oldValue, bool newValue) + partial void OnIsCircleChanged(bool newValue) { IsCircleChanged(); } diff --git a/src/Files.App.Controls/Storage/StorageBar/StorageBar.Properties.cs b/src/Files.App.Controls/Storage/StorageBar/StorageBar.Properties.cs index 26e961321c30..95dea41d4922 100644 --- a/src/Files.App.Controls/Storage/StorageBar/StorageBar.Properties.cs +++ b/src/Files.App.Controls/Storage/StorageBar/StorageBar.Properties.cs @@ -1,34 +1,47 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Xaml; namespace Files.App.Controls { - [DependencyProperty("ValueBarHeight", nameof(OnValueBarHeightChanged), DefaultValue = "(double)4.0")] - [DependencyProperty("TrackBarHeight", nameof(OnTrackBarHeightChanged), DefaultValue = "(double)2.0")] - [DependencyProperty("BarShape", nameof(OnBarShapeChanged), DefaultValue = "BarShapes.Round")] - [DependencyProperty("Percent", nameof(OnPercentChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("PercentCaution", nameof(OnPercentCautionChanged), DefaultValue = "(double)75.1")] - [DependencyProperty("PercentCritical", nameof(OnPercentCriticalChanged), DefaultValue = "(double)89.9")] public partial class StorageBar { - private void OnValueBarHeightChanged(double oldValue, double newValue) + [GeneratedDependencyProperty(DefaultValue = 4.0d)] + public partial double ValueBarHeight { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 2.0d)] + public partial double TrackBarHeight { get; set; } + + [GeneratedDependencyProperty(DefaultValue = BarShapes.Round)] + public partial BarShapes BarShape { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double Percent { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 75.1d)] + public partial double PercentCaution { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 89.9d)] + public partial double PercentCritical { get; set; } + + partial void OnValueBarHeightChanged(double newValue) { UpdateControl(this); } - private void OnTrackBarHeightChanged(double oldValue, double newValue) + partial void OnTrackBarHeightChanged(double newValue) { UpdateControl(this); } - private void OnBarShapeChanged(BarShapes oldValue, BarShapes newValue) + partial void OnBarShapeChanged(BarShapes newValue) { UpdateControl(this); } - private void OnPercentChanged(double oldValue, double newValue) + partial void OnPercentChanged(double newValue) { return; //Read-only @@ -36,12 +49,12 @@ private void OnPercentChanged(double oldValue, double newValue) UpdateControl(this); } - private void OnPercentCautionChanged(double oldValue, double newValue) + partial void OnPercentCautionChanged(double newValue) { UpdateControl(this); } - private void OnPercentCriticalChanged(double oldValue, double newValue) + partial void OnPercentCriticalChanged(double newValue) { UpdateControl(this); } diff --git a/src/Files.App.Controls/Storage/StorageRing/StorageRing.Properties.cs b/src/Files.App.Controls/Storage/StorageRing/StorageRing.Properties.cs index 9f929f4504ef..3328e9dbe16a 100644 --- a/src/Files.App.Controls/Storage/StorageRing/StorageRing.Properties.cs +++ b/src/Files.App.Controls/Storage/StorageRing/StorageRing.Properties.cs @@ -1,49 +1,70 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Xaml; namespace Files.App.Controls { - [DependencyProperty("ValueRingThickness", nameof(OnValueRingThicknessChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("TrackRingThickness", nameof(OnTrackRingThicknessChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("MinAngle", nameof(OnMinAngleChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("MaxAngle", nameof(OnMaxAngleChanged), DefaultValue = "(double)360.0")] - [DependencyProperty("StartAngle", nameof(OnStartAngleChanged), DefaultValue = "(double)0.0")] - [DependencyProperty("Percent", nameof(OnPercentChanged))] - [DependencyProperty("PercentCaution", nameof(OnPercentCautionChanged), DefaultValue = "(double)75.01")] - [DependencyProperty("PercentCritical", nameof(OnPercentCriticalChanged), DefaultValue = "(double)90.01")] - [DependencyProperty("ValueAngle")] - [DependencyProperty("AdjustedSize", DefaultValue = "(double)16.0")] public partial class StorageRing { - private void OnValueRingThicknessChanged(double oldValue, double newValue) + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double ValueRingThickness { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double TrackRingThickness { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double MinAngle { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 360.0d)] + public partial double MaxAngle { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 0.0d)] + public partial double StartAngle { get; set; } + + [GeneratedDependencyProperty] + public partial double Percent { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 75.01d)] + public partial double PercentCaution { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 90.01d)] + public partial double PercentCritical { get; set; } + + [GeneratedDependencyProperty] + public partial double ValueAngle { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 16.0d)] + public partial double AdjustedSize { get; set; } + + partial void OnValueRingThicknessChanged(double newValue) { UpdateRingThickness(this, newValue, false); UpdateRings(this); } - private void OnTrackRingThicknessChanged(double oldValue, double newValue) + partial void OnTrackRingThicknessChanged(double newValue) { UpdateRingThickness(this, newValue, true); UpdateRings(this); } - private void OnMinAngleChanged(double oldValue, double newValue) + partial void OnMinAngleChanged(double newValue) { UpdateValues(this, Value, _oldValue, false, -1.0); CalculateAndSetNormalizedAngles(this, newValue, MaxAngle); UpdateRings(this); } - private void OnMaxAngleChanged(double oldValue, double newValue) + partial void OnMaxAngleChanged(double newValue) { UpdateValues(this, Value, _oldValue, false, -1.0); CalculateAndSetNormalizedAngles(this, MinAngle, newValue); UpdateRings(this); } - private void OnStartAngleChanged(double oldValue, double newValue) + partial void OnStartAngleChanged(double newValue) { UpdateValues(this, Value, _oldValue, false, -1.0); CalculateAndSetNormalizedAngles(this, MinAngle, newValue); @@ -51,7 +72,7 @@ private void OnStartAngleChanged(double oldValue, double newValue) UpdateRings(this); } - private void OnPercentChanged(double oldValue, double newValue) + partial void OnPercentChanged(double newValue) { return; //Read-only @@ -71,14 +92,14 @@ private void OnPercentChanged(double oldValue, double newValue) UpdateRings(this); } - private void OnPercentCautionChanged(double oldValue, double newValue) + partial void OnPercentCautionChanged(double newValue) { UpdateValues(this, Value, _oldValue, false, -1.0); UpdateVisualState(this); UpdateRings(this); } - private void OnPercentCriticalChanged(double oldValue, double newValue) + partial void OnPercentCriticalChanged(double newValue) { UpdateValues(this, Value, _oldValue, false, -1.0); UpdateVisualState(this); diff --git a/src/Files.App.Controls/ThemedIcon/ThemedIcon.Properties.cs b/src/Files.App.Controls/ThemedIcon/ThemedIcon.Properties.cs index cff1ccf9a7ec..177cf7d6390e 100644 --- a/src/Files.App.Controls/ThemedIcon/ThemedIcon.Properties.cs +++ b/src/Files.App.Controls/ThemedIcon/ThemedIcon.Properties.cs @@ -1,76 +1,99 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; namespace Files.App.Controls { - [DependencyProperty("FilledIconData", nameof(OnFilledIconPropertyChanged))] - [DependencyProperty("OutlineIconData", nameof(OnOutlineIconPropertyChanged))] - [DependencyProperty("Color", nameof(OnColorPropertyChanged))] - [DependencyProperty("IconType", nameof(OnIconTypePropertyChanged), DefaultValue = "ThemedIconTypes.Layered")] - [DependencyProperty("IconColorType", nameof(OnIconColorTypePropertyChanged), DefaultValue = "ThemedIconColorType.None")] - [DependencyProperty("IconSize", nameof(OnIconSizePropertyChanged), DefaultValue = "(double)16")] - [DependencyProperty("IsToggled", nameof(OnIsToggledPropertyChanged), DefaultValue = "false")] - [DependencyProperty("IsFilled", nameof(OnIsFilledPropertyChanged), DefaultValue = "false")] - [DependencyProperty("IsHighContrast", nameof(OnIsHighContrastPropertyChanged), DefaultValue = "false")] - [DependencyProperty("Layers", nameof(OnLayersPropertyChanged))] - [DependencyProperty("ToggleBehavior", nameof(OnToggleBehaviorPropertyChanged), DefaultValue = "ToggleBehaviors.Auto")] public partial class ThemedIcon : Control { - protected virtual void OnFilledIconPropertyChanged(string oldValue, string newValue) + [GeneratedDependencyProperty] + public partial string FilledIconData { get; set; } + + [GeneratedDependencyProperty] + public partial string OutlineIconData { get; set; } + + [GeneratedDependencyProperty] + public partial Brush Color { get; set; } + + [GeneratedDependencyProperty(DefaultValue = ThemedIconTypes.Layered)] + public partial ThemedIconTypes IconType { get; set; } + + [GeneratedDependencyProperty(DefaultValue = ThemedIconColorType.None)] + public partial ThemedIconColorType IconColorType { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 16.0d)] + public partial double IconSize { get; set; } + + [GeneratedDependencyProperty] + public partial bool IsToggled { get; set; } + + [GeneratedDependencyProperty] + public partial bool IsFilled { get; set; } + + [GeneratedDependencyProperty] + public partial bool IsHighContrast { get; set; } + + [GeneratedDependencyProperty] + public partial object Layers { get; set; } + + [GeneratedDependencyProperty(DefaultValue = ToggleBehaviors.Auto)] + public partial ToggleBehaviors ToggleBehavior { get; set; } + + partial void OnFilledIconDataChanged(string newValue) { OnFilledIconChanged(); } - protected virtual void OnOutlineIconPropertyChanged(string oldValue, string newValue) + partial void OnOutlineIconDataChanged(string newValue) { OnOutlineIconChanged(); } - protected virtual void OnColorPropertyChanged(Brush oldValue, Brush newValue) + partial void OnColorChanged(Brush newValue) { OnIconTypeChanged(); OnIconColorChanged(); } - protected virtual void OnIconTypePropertyChanged(ThemedIconTypes oldValue, ThemedIconTypes newValue) + partial void OnIconTypeChanged(ThemedIconTypes newValue) { OnIconTypeChanged(); } - protected virtual void OnIconColorTypePropertyChanged(ThemedIconColorType oldValue, ThemedIconColorType newValue) + partial void OnIconColorTypeChanged(ThemedIconColorType newValue) { OnIconColorTypeChanged(); } - protected virtual void OnIconSizePropertyChanged(double oldValue, double newValue) + partial void OnIconSizeChanged(double newValue) { UpdateVisualStates(); } - protected virtual void OnIsToggledPropertyChanged(bool oldValue, bool newValue) + partial void OnIsToggledChanged(bool newValue) { UpdateVisualStates(); } - protected virtual void OnIsFilledPropertyChanged(bool oldValue, bool newValue) + partial void OnIsFilledChanged(bool newValue) { UpdateVisualStates(); } - protected virtual void OnIsHighContrastPropertyChanged(bool oldValue, bool newValue) + partial void OnIsHighContrastChanged(bool newValue) { UpdateVisualStates(); } - protected virtual void OnLayersPropertyChanged(object oldValue, object newValue) + partial void OnLayersChanged(object newValue) { UpdateVisualStates(); } - protected virtual void OnToggleBehaviorPropertyChanged(ToggleBehaviors oldValue, ToggleBehaviors newValue) + partial void OnToggleBehaviorChanged(ToggleBehaviors newValue) { UpdateVisualStates(); } diff --git a/src/Files.App.Controls/ThemedIcon/ThemedIconLayer/ThemedIconLayer.Properties.cs b/src/Files.App.Controls/ThemedIcon/ThemedIconLayer/ThemedIconLayer.Properties.cs index 19fe98460399..0d031c627154 100644 --- a/src/Files.App.Controls/ThemedIcon/ThemedIconLayer/ThemedIconLayer.Properties.cs +++ b/src/Files.App.Controls/ThemedIcon/ThemedIconLayer/ThemedIconLayer.Properties.cs @@ -1,38 +1,49 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Xaml.Media; namespace Files.App.Controls { - [DependencyProperty("LayerType", nameof(OnLayerTypePropertyChanged), DefaultValue = "ThemedIconLayerType.Base")] - [DependencyProperty("PathData", nameof(OnLayerPathDataPropertyChanged), DefaultValue = "string.Empty")] - [DependencyProperty("LayerSize", nameof(OnLayerSizePropertyChanged), DefaultValue = "(double)16")] - [DependencyProperty("LayerColor", nameof(OnColorPropertyChanged))] - [DependencyProperty("IconColorType", nameof(OnIconColorTypePropertyChanged), DefaultValue = "ThemedIconColorType.Normal")] public partial class ThemedIconLayer { - protected virtual void OnLayerTypePropertyChanged(ThemedIconLayerType oldValue, ThemedIconLayerType newValue) + [GeneratedDependencyProperty(DefaultValue = ThemedIconLayerType.Base)] + public partial ThemedIconLayerType LayerType { get; set; } + + [GeneratedDependencyProperty(DefaultValue = "")] + public partial string PathData { get; set; } + + [GeneratedDependencyProperty(DefaultValue = 16.0d)] + public partial double LayerSize { get; set; } + + [GeneratedDependencyProperty] + public partial Brush LayerColor { get; set; } + + [GeneratedDependencyProperty(DefaultValue = ThemedIconColorType.Normal)] + public partial ThemedIconColorType IconColorType { get; set; } + + partial void OnLayerTypeChanged(ThemedIconLayerType newValue) { LayerTypeChanged(newValue); } - protected virtual void OnLayerPathDataPropertyChanged(string oldValue, string newValue) + partial void OnPathDataChanged(string newValue) { LayerPathDataChanged(newValue); } - protected virtual void OnLayerSizePropertyChanged(double oldValue, double newValue) + partial void OnLayerSizeChanged(double newValue) { LayerSizePropertyChanged(newValue); } - protected virtual void OnColorPropertyChanged(Brush oldValue, Brush newValue) + partial void OnLayerColorChanged(Brush newValue) { IconColorTypeChanged(); } - protected virtual void OnIconColorTypePropertyChanged(ThemedIconColorType oldValue, ThemedIconColorType newValue) + partial void OnIconColorTypeChanged(ThemedIconColorType newValue) { IconColorTypeChanged(); } diff --git a/src/Files.App/Files.App.csproj b/src/Files.App/Files.App.csproj index 17896e8dd5c9..4dadfd0d7103 100644 --- a/src/Files.App/Files.App.csproj +++ b/src/Files.App/Files.App.csproj @@ -65,6 +65,7 @@ + diff --git a/src/Files.App/UserControls/AddressToolbar.xaml.cs b/src/Files.App/UserControls/AddressToolbar.xaml.cs index eefef90992ad..7a30b37939b4 100644 --- a/src/Files.App/UserControls/AddressToolbar.xaml.cs +++ b/src/Files.App/UserControls/AddressToolbar.xaml.cs @@ -1,6 +1,7 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Input; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -14,20 +15,32 @@ namespace Files.App.UserControls { - [DependencyProperty("IsSidebarPaneOpenToggleButtonVisible")] - [DependencyProperty("ShowOngoingTasks")] - [DependencyProperty("ShowSettingsButton")] - [DependencyProperty("ShowSearchBox")] - [DependencyProperty("ViewModel")] public sealed partial class AddressToolbar : UserControl { - // Dependency properties + // Dependency injections private readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); private readonly MainPageViewModel MainPageViewModel = Ioc.Default.GetRequiredService(); public ICommandManager Commands = Ioc.Default.GetRequiredService(); public StatusCenterViewModel? OngoingTasksViewModel { get; set; } + // Properties + + [GeneratedDependencyProperty] + public partial bool IsSidebarPaneOpenToggleButtonVisible { get; set; } + + [GeneratedDependencyProperty] + public partial bool ShowOngoingTasks { get; set; } + + [GeneratedDependencyProperty] + public partial bool ShowSettingsButton { get; set; } + + [GeneratedDependencyProperty] + public partial bool ShowSearchBox { get; set; } + + [GeneratedDependencyProperty] + public partial AddressToolbarViewModel ViewModel { get; set; } + // Commands private readonly ICommand historyItemClickedCommand; diff --git a/src/Files.App/UserControls/DataGridHeader.xaml.cs b/src/Files.App/UserControls/DataGridHeader.xaml.cs index 669f59c8fe3c..73247be4411a 100644 --- a/src/Files.App/UserControls/DataGridHeader.xaml.cs +++ b/src/Files.App/UserControls/DataGridHeader.xaml.cs @@ -1,21 +1,28 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System.Windows.Input; namespace Files.App.UserControls { - [DependencyProperty("Header")] - [DependencyProperty("CanBeSorted", DefaultValue = "true")] - [DependencyProperty("ColumnSortOption", "OnColumnSortOptionChanged", IsNullable = true)] public sealed partial class DataGridHeader : UserControl { + [GeneratedDependencyProperty] + public partial string Header { get; set; } + + [GeneratedDependencyProperty(DefaultValue = true)] + public partial bool CanBeSorted { get; set; } + + [GeneratedDependencyProperty] + public partial SortDirection? ColumnSortOption { get; set; } + public ICommand Command { get; set; } public object CommandParameter { get; set; } - public void OnColumnSortOptionChanged(SortDirection? oldValue, SortDirection? newValue) + partial void OnColumnSortOptionChanged(SortDirection? newValue) { VisualStateManager.GoToState( this, diff --git a/src/Files.App/UserControls/FolderEmptyIndicator.xaml.cs b/src/Files.App/UserControls/FolderEmptyIndicator.xaml.cs index ce0b1f44005e..a038a7af57a1 100644 --- a/src/Files.App/UserControls/FolderEmptyIndicator.xaml.cs +++ b/src/Files.App/UserControls/FolderEmptyIndicator.xaml.cs @@ -1,13 +1,16 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Xaml.Controls; namespace Files.App.UserControls { - [DependencyProperty("EmptyTextType")] public sealed partial class FolderEmptyIndicator : UserControl { + [GeneratedDependencyProperty] + public partial EmptyTextType EmptyTextType { get; set; } + public FolderEmptyIndicator() { InitializeComponent(); diff --git a/src/Files.App/UserControls/PathBreadcrumb.xaml.cs b/src/Files.App/UserControls/PathBreadcrumb.xaml.cs index e00a0b52262c..696a7c844faf 100644 --- a/src/Files.App/UserControls/PathBreadcrumb.xaml.cs +++ b/src/Files.App/UserControls/PathBreadcrumb.xaml.cs @@ -1,15 +1,18 @@ // Copyright (c) Files Community // Licensed under the MIT License. +using CommunityToolkit.WinUI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; namespace Files.App.UserControls { - [DependencyProperty("ViewModel")] public sealed partial class PathBreadcrumb : UserControl { + [GeneratedDependencyProperty] + public partial AddressToolbarViewModel ViewModel { get; set; } + public PathBreadcrumb() { InitializeComponent(); diff --git a/src/Files.Core.SourceGenerator/Generators/DependencyPropertyGenerator.cs b/src/Files.Core.SourceGenerator/Generators/DependencyPropertyGenerator.cs deleted file mode 100644 index 1afc6c5dd96b..000000000000 --- a/src/Files.Core.SourceGenerator/Generators/DependencyPropertyGenerator.cs +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (c) Files Community -// Licensed under the MIT License. - -namespace Files.Core.SourceGenerator.Generators -{ - /// - /// Generates a set of dependency property and its backing field. - /// - [Generator(LanguageNames.CSharp)] - public sealed class DependencyPropertyGenerator : IIncrementalGenerator - { - /// - public void Initialize(IncrementalGeneratorInitializationContext context) - { - var valueProvider = - context.SyntaxProvider.ForAttributeWithMetadataName( - "Files.Shared.Attributes.DependencyPropertyAttribute`1", - (_, _) => true, - (syntaxContext, _) => syntaxContext) - .Combine(context.CompilationProvider); - - context.RegisterSourceOutput(valueProvider, (ctx, tuple) => - { - var (ga, compilation) = tuple; - - if (ga.TargetSymbol is not INamedTypeSymbol symbol) - return; - - // Generate file name to emit - var fileName = $"{symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted))}_{Guid.NewGuid()}.g.cs"; - - // Generate C# - var fullSyntaxTree = EmitSyntaxTree(symbol, ga.Attributes); - if (string.IsNullOrEmpty(fullSyntaxTree)) - return; - - // Emit - ctx.AddSource(fileName, fullSyntaxTree); - }); - } - - private string EmitSyntaxTree(INamedTypeSymbol typeSymbol, ImmutableArray attributeList) - { - var members = new List(); - - foreach (var attribute in attributeList) - { - if (attribute.AttributeClass is not { TypeArguments: [var type, ..] }) - return string.Empty; - - // Get property name and property changed method name from attribute constructor - // e.g. DependencyProperty("Property", "OnPropertyChanged") - if (attribute.ConstructorArguments is not [{ Value: string propertyName }, { Value: string callbackMethodName }, ..]) - continue; - - var fieldName = $"{propertyName}Property"; - var isSetterPrivate = false; - var defaultValue = "global::Microsoft.UI.Xaml.DependencyProperty.UnsetValue"; - var isNullable = false; - - // Get values from the attribute properties - foreach (var namedArgument in attribute.NamedArguments) - { - if (namedArgument.Value.Value is { } value) - { - switch (namedArgument.Key) - { - case "IsSetterPrivate": - isSetterPrivate = (bool)value; - break; - case "DefaultValue": - defaultValue = (string)value; - break; - case "IsNullable": - isNullable = (bool)value; - break; - } - } - } - - // Emit "new PropertyMetadata(...)" expression - var dpPropertyMetadata = EmitPMObjectCreationExpression(SyntaxFactory.ParseExpression(defaultValue)); - - // Append callback to PropertyMetadata - if (!string.IsNullOrEmpty(callbackMethodName)) - dpPropertyMetadata = dpPropertyMetadata.AddArgumentListArguments( - SyntaxFactory.Argument(EmitDPCallbackParenthesizedLambdaExpression(callbackMethodName, type, isNullable, typeSymbol))); - - // Emit "DependencyProperty.Register(...)" expression - var dpRegisteringExpression = EmitDPRegisterInvocationExpression(propertyName, type, typeSymbol, dpPropertyMetadata); - - // Emit the backing DependencyProperty field with attributes - var staticFieldDeclaration = SourceGeneratorHelper.GetStaticFieldDeclaration(fieldName, dpRegisteringExpression) - .AddAttributeLists(SourceGeneratorHelper.GetAttributeForField(nameof(DependencyPropertyGenerator))); - - // Emit getter and setter of the property - var getter = SourceGeneratorHelper.GetGetter(fieldName, isNullable, type); - var setter = SourceGeneratorHelper.GetSetter(fieldName, isSetterPrivate); - - // Emit the property with attributes - var propertyDeclaration = SourceGeneratorHelper.GetPropertyDeclaration(propertyName, isNullable, type, getter, setter) - .AddAttributeLists(SourceGeneratorHelper.GetAttributeForMethod(nameof(DependencyPropertyGenerator))); - - // Add to the class members - members.Add(staticFieldDeclaration); - members.Add(propertyDeclaration); - } - - if (members.Count is 0) - return string.Empty; - - // Generate class block - var generatedClass = SourceGeneratorHelper.GetClassDeclaration(typeSymbol, members); - - // Generate namespace block - var generatedNamespace = SourceGeneratorHelper.GetFileScopedNamespaceDeclaration(typeSymbol, generatedClass); - - // Generate complication uint - var compilationUnit = SourceGeneratorHelper.GetCompilationUnit(generatedNamespace); - - // Get full syntax tree and return as UTF8 string - return SyntaxFactory.SyntaxTree(compilationUnit, encoding: Encoding.UTF8).GetText().ToString(); - } - - private ParenthesizedLambdaExpressionSyntax EmitDPCallbackParenthesizedLambdaExpression(string callbackName, ITypeSymbol type, bool isNullable, ITypeSymbol classSymbol) - { - // (d, e) => ((class)d).callbackName((type)e.OldValue, (type)e.NewValue) - return SyntaxFactory.ParenthesizedLambdaExpression() - .AddParameterListParameters( - SyntaxFactory.Parameter(SyntaxFactory.Identifier("d")), - SyntaxFactory.Parameter(SyntaxFactory.Identifier("e"))) - .WithExpressionBody( - SyntaxFactory.InvocationExpression( - SyntaxFactory.MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - SyntaxFactory.ParenthesizedExpression( - SyntaxFactory.CastExpression( - classSymbol.GetTypeSyntax(false), - SyntaxFactory.IdentifierName("d"))), - SyntaxFactory.IdentifierName(callbackName))) - .AddArgumentListArguments( - SyntaxFactory.Argument( - SyntaxFactory.CastExpression( - type.GetTypeSyntax(isNullable), - SyntaxFactory.MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - SyntaxFactory.IdentifierName("e"), - SyntaxFactory.IdentifierName("OldValue")))), - SyntaxFactory.Argument( - SyntaxFactory.CastExpression( - type.GetTypeSyntax(isNullable), - SyntaxFactory.MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - SyntaxFactory.IdentifierName("e"), - SyntaxFactory.IdentifierName("NewValue")))))); - } - - private ObjectCreationExpressionSyntax EmitPMObjectCreationExpression(ExpressionSyntax defaultValueExpression) - { - // new PropertyMetadata(defaultValueExpression); - return SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName("global::Microsoft.UI.Xaml.PropertyMetadata")) - .AddArgumentListArguments( - SyntaxFactory.Argument(defaultValueExpression)); - } - - private InvocationExpressionSyntax EmitDPRegisterInvocationExpression(string propertyName, ITypeSymbol type, ITypeSymbol className, ExpressionSyntax propertyMetadataExpression) - { - // DependencyProperty.Register(nameof(propertyName, type, typeof(className), propertyMetadataExpression); - return SyntaxFactory.InvocationExpression( - SyntaxFactory.MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - SyntaxFactory.IdentifierName("global::Microsoft.UI.Xaml.DependencyProperty"), - SyntaxFactory.IdentifierName("Register"))) - .AddArgumentListArguments( - SyntaxFactory.Argument(SourceGeneratorHelper.NameOfExpression(SyntaxFactory.IdentifierName(propertyName))), - SyntaxFactory.Argument(SyntaxFactory.TypeOfExpression(type.GetTypeSyntax(false))), - SyntaxFactory.Argument(SyntaxFactory.TypeOfExpression(className.GetTypeSyntax(false))), - SyntaxFactory.Argument(propertyMetadataExpression)); - } - } -} diff --git a/src/Files.Shared/Attributes/DependencyPropertyAttribute.cs b/src/Files.Shared/Attributes/DependencyPropertyAttribute.cs deleted file mode 100644 index e052e71b7a05..000000000000 --- a/src/Files.Shared/Attributes/DependencyPropertyAttribute.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Files Community -// Licensed under the MIT License. - -using System; - -namespace Files.Shared.Attributes; - -[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] -public sealed class DependencyPropertyAttribute : Attribute where T : notnull -{ - public DependencyPropertyAttribute(string name, string propertyChanged = "") - { - Name = name; - PropertyChanged = propertyChanged; - } - - public string Name { get; } - - public string PropertyChanged { get; } - - public bool IsSetterPrivate { get; init; } - - public bool IsNullable { get; init; } - - // TODO: This should be able to be removed after stable .NET 9 released - public string? DefaultValue { get; init; } -}