Browse Source

IResourceProvider -> IResourceNode

pull/1136/head
Steven Kirk 9 years ago
parent
commit
e81b22b9d2
  1. 8
      src/Avalonia.Controls/Application.cs
  2. 6
      src/Avalonia.Controls/Control.cs
  3. 2
      src/Avalonia.Controls/IControl.cs
  4. 4
      src/Avalonia.Styling/Controls/IResourceNode.cs
  5. 6
      src/Avalonia.Styling/Controls/ResourceProviderExtensions.cs
  6. 2
      src/Avalonia.Styling/Styling/ISetStyleParent.cs
  7. 2
      src/Avalonia.Styling/Styling/IStyle.cs
  8. 8
      src/Avalonia.Styling/Styling/Style.cs
  9. 6
      src/Avalonia.Styling/Styling/Styles.cs
  10. 8
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs
  11. 4
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
  12. 8
      src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs
  13. 2
      tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs

8
src/Avalonia.Controls/Application.cs

@ -29,7 +29,7 @@ namespace Avalonia
/// method. /// method.
/// - Tracks the lifetime of the application. /// - Tracks the lifetime of the application.
/// </remarks> /// </remarks>
public class Application : IApplicationLifecycle, IGlobalDataTemplates, IGlobalStyles, IStyleRoot, IResourceProvider public class Application : IApplicationLifecycle, IGlobalDataTemplates, IGlobalStyles, IStyleRoot, IResourceNode
{ {
/// <summary> /// <summary>
/// The application-global data templates. /// The application-global data templates.
@ -126,10 +126,10 @@ namespace Avalonia
IStyleHost IStyleHost.StylingParent => null; IStyleHost IStyleHost.StylingParent => null;
/// <inheritdoc/> /// <inheritdoc/>
bool IResourceProvider.HasResources => _resources?.Count > 0; bool IResourceNode.HasResources => _resources?.Count > 0;
/// <inheritdoc/> /// <inheritdoc/>
IResourceProvider IResourceProvider.ResourceParent => null; IResourceNode IResourceNode.ResourceParent => null;
/// <summary> /// <summary>
/// Initializes the application by loading XAML etc. /// Initializes the application by loading XAML etc.
@ -159,7 +159,7 @@ namespace Avalonia
} }
/// <inheritdoc/> /// <inheritdoc/>
bool IResourceProvider.TryGetResource(string key, out object value) bool IResourceNode.TryGetResource(string key, out object value)
{ {
value = null; value = null;
return (_resources?.TryGetResource(key, out value) ?? false) || return (_resources?.TryGetResource(key, out value) ?? false) ||

6
src/Avalonia.Controls/Control.cs

@ -390,10 +390,10 @@ namespace Avalonia.Controls
IAvaloniaReadOnlyList<ILogical> ILogical.LogicalChildren => LogicalChildren; IAvaloniaReadOnlyList<ILogical> ILogical.LogicalChildren => LogicalChildren;
/// <inheritdoc/> /// <inheritdoc/>
bool IResourceProvider.HasResources => _resources?.Count > 0 || Styles.HasResources; bool IResourceNode.HasResources => _resources?.Count > 0 || Styles.HasResources;
/// <inheritdoc/> /// <inheritdoc/>
IResourceProvider IResourceProvider.ResourceParent => ((IStyleHost)this).StylingParent as IResourceProvider; IResourceNode IResourceNode.ResourceParent => ((IStyleHost)this).StylingParent as IResourceNode;
/// <inheritdoc/> /// <inheritdoc/>
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes; IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
@ -480,7 +480,7 @@ namespace Avalonia.Controls
} }
/// <inheritdoc/> /// <inheritdoc/>
bool IResourceProvider.TryGetResource(string key, out object value) bool IResourceNode.TryGetResource(string key, out object value)
{ {
value = null; value = null;
return (_resources?.TryGetResource(key, out value) ?? false) || return (_resources?.TryGetResource(key, out value) ?? false) ||

2
src/Avalonia.Controls/IControl.cs

@ -14,7 +14,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Interface for Avalonia controls. /// Interface for Avalonia controls.
/// </summary> /// </summary>
public interface IControl : IVisual, ILogical, ILayoutable, IInputElement, INamed, IResourceProvider, IStyleable, IStyleHost public interface IControl : IVisual, ILogical, ILayoutable, IInputElement, INamed, IResourceNode, IStyleable, IStyleHost
{ {
/// <summary> /// <summary>
/// Occurs when the control has finished initialization. /// Occurs when the control has finished initialization.

4
src/Avalonia.Styling/Controls/IResourceProvider.cs → src/Avalonia.Styling/Controls/IResourceNode.cs

@ -5,7 +5,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Defines an element that can be queried for resources. /// Defines an element that can be queried for resources.
/// </summary> /// </summary>
public interface IResourceProvider public interface IResourceNode
{ {
/// <summary> /// <summary>
/// Raised when resources in the element are changed. /// Raised when resources in the element are changed.
@ -20,7 +20,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets the parent resource provider, if any. /// Gets the parent resource provider, if any.
/// </summary> /// </summary>
IResourceProvider ResourceParent { get; } IResourceNode ResourceParent { get; }
/// <summary> /// <summary>
/// Tries to find a resource within the element. /// Tries to find a resource within the element.

6
src/Avalonia.Styling/Controls/ResourceProviderExtensions.cs

@ -14,7 +14,7 @@ namespace Avalonia.Controls
/// <param name="control">The control.</param> /// <param name="control">The control.</param>
/// <param name="key">The resource key.</param> /// <param name="key">The resource key.</param>
/// <returns>The resource, or <see cref="AvaloniaProperty.UnsetValue"/> if not found.</returns> /// <returns>The resource, or <see cref="AvaloniaProperty.UnsetValue"/> if not found.</returns>
public static object FindResource(this IResourceProvider control, string key) public static object FindResource(this IResourceNode control, string key)
{ {
Contract.Requires<ArgumentNullException>(control != null); Contract.Requires<ArgumentNullException>(control != null);
Contract.Requires<ArgumentNullException>(key != null); Contract.Requires<ArgumentNullException>(key != null);
@ -23,7 +23,7 @@ namespace Avalonia.Controls
while (current != null) while (current != null)
{ {
if (current is IResourceProvider host) if (current is IResourceNode host)
{ {
if (host.TryGetResource(key, out var value)) if (host.TryGetResource(key, out var value))
{ {
@ -37,7 +37,7 @@ namespace Avalonia.Controls
return AvaloniaProperty.UnsetValue; return AvaloniaProperty.UnsetValue;
} }
public static IObservable<object> GetResourceObservable(this IResourceProvider target, string key) public static IObservable<object> GetResourceObservable(this IResourceNode target, string key)
{ {
return Observable.FromEventPattern<ResourcesChangedEventArgs>( return Observable.FromEventPattern<ResourcesChangedEventArgs>(
x => target.ResourcesChanged += x, x => target.ResourcesChanged += x,

2
src/Avalonia.Styling/Styling/ISetStyleParent.cs

@ -17,7 +17,7 @@ namespace Avalonia.Styling
/// Sets the style parent. /// Sets the style parent.
/// </summary> /// </summary>
/// <param name="parent">The parent.</param> /// <param name="parent">The parent.</param>
void SetParent(IResourceProvider parent); void SetParent(IResourceNode parent);
/// <summary> /// <summary>
/// Notifies the style that a change has been made to resources that apply to it. /// Notifies the style that a change has been made to resources that apply to it.

2
src/Avalonia.Styling/Styling/IStyle.cs

@ -8,7 +8,7 @@ namespace Avalonia.Styling
/// <summary> /// <summary>
/// Defines the interface for styles. /// Defines the interface for styles.
/// </summary> /// </summary>
public interface IStyle : IResourceProvider public interface IStyle : IResourceNode
{ {
/// <summary> /// <summary>
/// Attaches the style to a control if the style's selector matches. /// Attaches the style to a control if the style's selector matches.

8
src/Avalonia.Styling/Styling/Style.cs

@ -17,7 +17,7 @@ namespace Avalonia.Styling
{ {
private static Dictionary<IStyleable, List<IDisposable>> _applied = private static Dictionary<IStyleable, List<IDisposable>> _applied =
new Dictionary<IStyleable, List<IDisposable>>(); new Dictionary<IStyleable, List<IDisposable>>();
private IResourceProvider _parent; private IResourceNode _parent;
private ResourceDictionary _resources; private ResourceDictionary _resources;
/// <summary> /// <summary>
@ -68,10 +68,10 @@ namespace Avalonia.Styling
public IList<ISetter> Setters { get; set; } = new List<ISetter>(); public IList<ISetter> Setters { get; set; } = new List<ISetter>();
/// <inheritdoc/> /// <inheritdoc/>
bool IResourceProvider.HasResources => _resources?.Count > 0; bool IResourceNode.HasResources => _resources?.Count > 0;
/// <inheritdoc/> /// <inheritdoc/>
IResourceProvider IResourceProvider.ResourceParent => _parent; IResourceNode IResourceNode.ResourceParent => _parent;
/// <summary> /// <summary>
/// Attaches the style to a control if the style's selector matches. /// Attaches the style to a control if the style's selector matches.
@ -139,7 +139,7 @@ namespace Avalonia.Styling
} }
/// <inheritdoc/> /// <inheritdoc/>
void ISetStyleParent.SetParent(IResourceProvider parent) void ISetStyleParent.SetParent(IResourceNode parent)
{ {
if (_parent != null && parent != null) if (_parent != null && parent != null)
{ {

6
src/Avalonia.Styling/Styling/Styles.cs

@ -14,7 +14,7 @@ namespace Avalonia.Styling
/// </summary> /// </summary>
public class Styles : AvaloniaList<IStyle>, IStyle, ISetStyleParent public class Styles : AvaloniaList<IStyle>, IStyle, ISetStyleParent
{ {
private IResourceProvider _parent; private IResourceNode _parent;
private ResourceDictionary _resources; private ResourceDictionary _resources;
public Styles() public Styles()
@ -78,7 +78,7 @@ namespace Avalonia.Styling
} }
/// <inheritdoc/> /// <inheritdoc/>
IResourceProvider IResourceProvider.ResourceParent => _parent; IResourceNode IResourceNode.ResourceParent => _parent;
/// <summary> /// <summary>
/// Attaches the style to a control if the style's selector matches. /// Attaches the style to a control if the style's selector matches.
@ -116,7 +116,7 @@ namespace Avalonia.Styling
} }
/// <inheritdoc/> /// <inheritdoc/>
void ISetStyleParent.SetParent(IResourceProvider parent) void ISetStyleParent.SetParent(IResourceNode parent)
{ {
if (_parent != null && parent != null) if (_parent != null && parent != null)
{ {

8
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs

@ -15,7 +15,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
{ {
public class DynamicResourceExtension : MarkupExtension, IBinding public class DynamicResourceExtension : MarkupExtension, IBinding
{ {
private IResourceProvider _anchor; private IResourceNode _anchor;
public DynamicResourceExtension() public DynamicResourceExtension()
{ {
@ -33,9 +33,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
var context = (ITypeDescriptorContext)serviceProvider; var context = (ITypeDescriptorContext)serviceProvider;
var provideTarget = context.GetService<IProvideValueTarget>(); var provideTarget = context.GetService<IProvideValueTarget>();
if (!(provideTarget.TargetObject is IResourceProvider)) if (!(provideTarget.TargetObject is IResourceNode))
{ {
_anchor = GetAnchor<IResourceProvider>(context); _anchor = GetAnchor<IResourceNode>(context);
} }
return this; return this;
@ -47,7 +47,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
object anchor, object anchor,
bool enableDataValidation) bool enableDataValidation)
{ {
var control = target as IResourceProvider ?? _anchor; var control = target as IResourceNode ?? _anchor;
if (control != null) if (control != null)
{ {

4
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs

@ -31,7 +31,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
var context = (ITypeDescriptorContext)serviceProvider; var context = (ITypeDescriptorContext)serviceProvider;
var schemaContext = context.GetService<IXamlSchemaContextProvider>()?.SchemaContext; var schemaContext = context.GetService<IXamlSchemaContextProvider>()?.SchemaContext;
var ambientProvider = context.GetService<IAmbientProvider>(); var ambientProvider = context.GetService<IAmbientProvider>();
var resourceProviderType = schemaContext.GetXamlType(typeof(IResourceProvider)); var resourceProviderType = schemaContext.GetXamlType(typeof(IResourceNode));
var ambientValues = ambientProvider.GetAllAmbientValues(resourceProviderType); var ambientValues = ambientProvider.GetAllAmbientValues(resourceProviderType);
// Look upwards though the ambient context for IResourceProviders which might be able // Look upwards though the ambient context for IResourceProviders which might be able
@ -47,7 +47,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
{ {
// We override XamlType.CanAssignTo in BindingXamlType so the results we get back // We override XamlType.CanAssignTo in BindingXamlType so the results we get back
// from GetAllAmbientValues aren't necessarily of the correct type. // from GetAllAmbientValues aren't necessarily of the correct type.
if (ambientValue is IResourceProvider resourceProvider) if (ambientValue is IResourceNode resourceProvider)
{ {
if (resourceProvider is IControl control && control.StylingParent != null) if (resourceProvider is IControl control && control.StylingParent != null)
{ {

8
src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs

@ -14,7 +14,7 @@ namespace Avalonia.Markup.Xaml.Styling
{ {
private Uri _baseUri; private Uri _baseUri;
private IStyle _loaded; private IStyle _loaded;
private IResourceProvider _parent; private IResourceNode _parent;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="StyleInclude"/> class. /// Initializes a new instance of the <see cref="StyleInclude"/> class.
@ -52,10 +52,10 @@ namespace Avalonia.Markup.Xaml.Styling
} }
/// <inheritdoc/> /// <inheritdoc/>
bool IResourceProvider.HasResources => Loaded.HasResources; bool IResourceNode.HasResources => Loaded.HasResources;
/// <inheritdoc/> /// <inheritdoc/>
IResourceProvider IResourceProvider.ResourceParent => _parent; IResourceNode IResourceNode.ResourceParent => _parent;
/// <inheritdoc/> /// <inheritdoc/>
public void Attach(IStyleable control, IStyleHost container) public void Attach(IStyleable control, IStyleHost container)
@ -76,7 +76,7 @@ namespace Avalonia.Markup.Xaml.Styling
} }
/// <inheritdoc/> /// <inheritdoc/>
void ISetStyleParent.SetParent(IResourceProvider parent) void ISetStyleParent.SetParent(IResourceNode parent)
{ {
if (_parent != null && parent != null) if (_parent != null && parent != null)
{ {

2
tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs

@ -162,7 +162,7 @@ namespace Avalonia.Layout.UnitTests
private void RegisterServices() private void RegisterServices()
{ {
var globalStyles = new Mock<IGlobalStyles>(); var globalStyles = new Mock<IGlobalStyles>();
var globalStylesResources = globalStyles.As<IResourceProvider>(); var globalStylesResources = globalStyles.As<IResourceNode>();
var outObj = (object)10; var outObj = (object)10;
globalStylesResources.Setup(x => x.TryGetResource("FontSizeNormal", out outObj)).Returns(true); globalStylesResources.Setup(x => x.TryGetResource("FontSizeNormal", out outObj)).Returns(true);

Loading…
Cancel
Save