Browse Source

Renamed ISetter as SetterBase.

Allows us to hide the mechanics of initializing a setter.
pull/11436/head
Steven Kirk 3 years ago
parent
commit
34a83e26d1
  1. 24
      src/Avalonia.Base/Styling/ISetter.cs
  2. 2
      src/Avalonia.Base/Styling/ISetterInstance.cs
  3. 4
      src/Avalonia.Base/Styling/ISetterValue.cs
  4. 4
      src/Avalonia.Base/Styling/Setter.cs
  5. 12
      src/Avalonia.Base/Styling/SetterBase.cs
  6. 6
      src/Avalonia.Base/Styling/StyleBase.cs
  7. 2
      src/Avalonia.Controls/ContextMenu.cs
  8. 2
      src/Avalonia.Controls/Control.cs
  9. 2
      src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs
  10. 4
      src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs
  11. 2
      src/Markup/Avalonia.Markup/Data/TemplateBinding.cs

24
src/Avalonia.Base/Styling/ISetter.cs

@ -1,24 +0,0 @@
using System;
using Avalonia.Metadata;
namespace Avalonia.Styling
{
/// <summary>
/// Represents a setter for a <see cref="Style"/>.
/// </summary>
[NotClientImplementable]
public interface ISetter
{
/// <summary>
/// Instances a setter on a control.
/// </summary>
/// <param name="styleInstance">The style which contains the setter.</param>
/// <param name="target">The control.</param>
/// <returns>An <see cref="ISetterInstance"/>.</returns>
/// <remarks>
/// This method should return an <see cref="ISetterInstance"/> which can be used to apply
/// the setter to the specified control.
/// </remarks>
ISetterInstance Instance(IStyleInstance styleInstance, StyledElement target);
}
}

2
src/Avalonia.Base/Styling/ISetterInstance.cs

@ -3,7 +3,7 @@
namespace Avalonia.Styling namespace Avalonia.Styling
{ {
/// <summary> /// <summary>
/// Represents an <see cref="ISetter"/> that has been instanced on a control. /// Represents a <see cref="Setter"/> that has been instanced on a control.
/// </summary> /// </summary>
[Unstable] [Unstable]
public interface ISetterInstance public interface ISetterInstance

4
src/Avalonia.Base/Styling/ISetterValue.cs

@ -3,13 +3,13 @@
namespace Avalonia.Styling namespace Avalonia.Styling
{ {
/// <summary> /// <summary>
/// Customizes the behavior of a class when added as a value to an <see cref="ISetter"/>. /// Customizes the behavior of a class when added as a value to a <see cref="SetterBase"/>.
/// </summary> /// </summary>
public interface ISetterValue public interface ISetterValue
{ {
/// <summary> /// <summary>
/// Notifies that the object has been added as a setter value. /// Notifies that the object has been added as a setter value.
/// </summary> /// </summary>
void Initialize(ISetter setter); void Initialize(SetterBase setter);
} }
} }

4
src/Avalonia.Base/Styling/Setter.cs

@ -14,7 +14,7 @@ namespace Avalonia.Styling
/// A <see cref="Setter"/> is used to set a <see cref="AvaloniaProperty"/> value on a /// A <see cref="Setter"/> is used to set a <see cref="AvaloniaProperty"/> value on a
/// <see cref="AvaloniaObject"/> depending on a condition. /// <see cref="AvaloniaObject"/> depending on a condition.
/// </remarks> /// </remarks>
public class Setter : ISetter, IValueEntry, ISetterInstance, IAnimationSetter public class Setter : SetterBase, IValueEntry, ISetterInstance, IAnimationSetter
{ {
private object? _value; private object? _value;
private DirectPropertySetterInstance? _direct; private DirectPropertySetterInstance? _direct;
@ -66,7 +66,7 @@ namespace Avalonia.Styling
void IValueEntry.Unsubscribe() { } void IValueEntry.Unsubscribe() { }
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = TrimmingMessages.ImplicitTypeConvertionSupressWarningMessage)] [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = TrimmingMessages.ImplicitTypeConvertionSupressWarningMessage)]
ISetterInstance ISetter.Instance(IStyleInstance instance, StyledElement target) internal override ISetterInstance Instance(IStyleInstance instance, StyledElement target)
{ {
if (target is not AvaloniaObject ao) if (target is not AvaloniaObject ao)
throw new InvalidOperationException("Don't know how to instance a style on this type."); throw new InvalidOperationException("Don't know how to instance a style on this type.");

12
src/Avalonia.Base/Styling/SetterBase.cs

@ -0,0 +1,12 @@
namespace Avalonia.Styling
{
/// <summary>
/// Represents the base class for value setters.
/// </summary>
public abstract class SetterBase
{
internal abstract ISetterInstance Instance(
IStyleInstance styleInstance,
StyledElement target);
}
}

6
src/Avalonia.Base/Styling/StyleBase.cs

@ -16,7 +16,7 @@ namespace Avalonia.Styling
private IResourceHost? _owner; private IResourceHost? _owner;
private StyleChildren? _children; private StyleChildren? _children;
private IResourceDictionary? _resources; private IResourceDictionary? _resources;
private List<ISetter>? _setters; private List<SetterBase>? _setters;
private List<IAnimation>? _animations; private List<IAnimation>? _animations;
private StyleInstance? _sharedInstance; private StyleInstance? _sharedInstance;
@ -60,7 +60,7 @@ namespace Avalonia.Styling
} }
} }
public IList<ISetter> Setters => _setters ??= new List<ISetter>(); public IList<SetterBase> Setters => _setters ??= new();
public IList<IAnimation> Animations => _animations ??= new List<IAnimation>(); public IList<IAnimation> Animations => _animations ??= new List<IAnimation>();
bool IResourceNode.HasResources => _resources?.Count > 0; bool IResourceNode.HasResources => _resources?.Count > 0;
@ -69,7 +69,7 @@ namespace Avalonia.Styling
internal bool HasChildren => _children?.Count > 0; internal bool HasChildren => _children?.Count > 0;
internal bool HasSettersOrAnimations => _setters?.Count > 0 || _animations?.Count > 0; internal bool HasSettersOrAnimations => _setters?.Count > 0 || _animations?.Count > 0;
public void Add(ISetter setter) => Setters.Add(setter); public void Add(SetterBase setter) => Setters.Add(setter);
public void Add(IStyle style) => Children.Add(style); public void Add(IStyle style) => Children.Add(style);
public event EventHandler? OwnerChanged; public event EventHandler? OwnerChanged;

2
src/Avalonia.Controls/ContextMenu.cs

@ -285,7 +285,7 @@ namespace Avalonia.Controls
} }
} }
void ISetterValue.Initialize(ISetter setter) void ISetterValue.Initialize(SetterBase setter)
{ {
// ContextMenu can be assigned to the ContextMenu property in a setter. This overrides // ContextMenu can be assigned to the ContextMenu property in a setter. This overrides
// the behavior defined in Control which requires controls to be wrapped in a <template>. // the behavior defined in Control which requires controls to be wrapped in a <template>.

2
src/Avalonia.Controls/Control.cs

@ -213,7 +213,7 @@ namespace Avalonia.Controls
bool IDataTemplateHost.IsDataTemplatesInitialized => _dataTemplates != null; bool IDataTemplateHost.IsDataTemplatesInitialized => _dataTemplates != null;
/// <inheritdoc/> /// <inheritdoc/>
void ISetterValue.Initialize(ISetter setter) void ISetterValue.Initialize(SetterBase setter)
{ {
if (setter is Setter s && s.Property == ContextFlyoutProperty) if (setter is Setter s && s.Property == ContextFlyoutProperty)
{ {

2
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs

@ -125,7 +125,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
var selfType = context.ParentNodes().OfType<XamlAstConstructableObjectNode>().First().Type.GetClrType(); var selfType = context.ParentNodes().OfType<XamlAstConstructableObjectNode>().First().Type.GetClrType();
// When using self bindings with setters we need to change target type to resolved selector type. // When using self bindings with setters we need to change target type to resolved selector type.
if (context.GetAvaloniaTypes().ISetter.IsAssignableFrom(selfType)) if (context.GetAvaloniaTypes().SetterBase.IsAssignableFrom(selfType))
{ {
selfType = context.ParentNodes().OfType<AvaloniaXamlIlTargetTypeMetadataNode>().First().TargetType.GetClrType(); selfType = context.ParentNodes().OfType<AvaloniaXamlIlTargetTypeMetadataNode>().First().TargetType.GetClrType();
} }

4
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs

@ -104,7 +104,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
public IXamlType TextDecorationCollection { get; } public IXamlType TextDecorationCollection { get; }
public IXamlType TextDecorations { get; } public IXamlType TextDecorations { get; }
public IXamlType TextTrimming { get; } public IXamlType TextTrimming { get; }
public IXamlType ISetter { get; } public IXamlType SetterBase { get; }
public IXamlType IStyle { get; } public IXamlType IStyle { get; }
public IXamlType StyleInclude { get; } public IXamlType StyleInclude { get; }
public IXamlType ResourceInclude { get; } public IXamlType ResourceInclude { get; }
@ -244,7 +244,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
TextDecorationCollection = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorationCollection"); TextDecorationCollection = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorationCollection");
TextDecorations = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorations"); TextDecorations = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorations");
TextTrimming = cfg.TypeSystem.GetType("Avalonia.Media.TextTrimming"); TextTrimming = cfg.TypeSystem.GetType("Avalonia.Media.TextTrimming");
ISetter = cfg.TypeSystem.GetType("Avalonia.Styling.ISetter"); SetterBase = cfg.TypeSystem.GetType("Avalonia.Styling.SetterBase");
IStyle = cfg.TypeSystem.GetType("Avalonia.Styling.IStyle"); IStyle = cfg.TypeSystem.GetType("Avalonia.Styling.IStyle");
StyleInclude = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Styling.StyleInclude"); StyleInclude = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Styling.StyleInclude");
ResourceInclude = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Styling.ResourceInclude"); ResourceInclude = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Styling.ResourceInclude");

2
src/Markup/Avalonia.Markup/Data/TemplateBinding.cs

@ -109,7 +109,7 @@ namespace Avalonia.Data
} }
/// <inheritdoc/> /// <inheritdoc/>
void ISetterValue.Initialize(ISetter setter) => _isSetterValue = true; void ISetterValue.Initialize(SetterBase setter) => _isSetterValue = true;
protected override void Subscribed() protected override void Subscribed()
{ {

Loading…
Cancel
Save