using System;
using System.Collections.Generic;
namespace Xamarin.PropertyEditing
{
///
/// Represents a target platform by defining top level feature support and presentation preferences
///
public sealed class TargetPlatform
{
public TargetPlatform (IEditorProvider editorProvider)
{
if (editorProvider == null)
throw new ArgumentNullException (nameof(editorProvider));
EditorProvider = editorProvider;
}
public TargetPlatform (IEditorProvider editorProvider, IResourceProvider resourceProvider)
: this (editorProvider)
{
if (resourceProvider == null)
throw new ArgumentNullException (nameof(resourceProvider));
ResourceProvider = resourceProvider;
}
public TargetPlatform (IEditorProvider editorProvider, IBindingProvider bindingProvider)
: this (editorProvider)
{
if (bindingProvider == null)
throw new ArgumentNullException (nameof (bindingProvider));
BindingProvider = bindingProvider;
}
public TargetPlatform (IEditorProvider editorProvider, IResourceProvider resourceProvider, IBindingProvider bindingProvider)
: this (editorProvider, resourceProvider)
{
if (bindingProvider == null)
throw new ArgumentNullException (nameof(bindingProvider));
BindingProvider = bindingProvider;
}
///
/// Gets the associated with this platform.
///
public IEditorProvider EditorProvider
{
get;
}
public IResourceProvider ResourceProvider
{
get;
private set;
}
public IBindingProvider BindingProvider
{
get;
private set;
}
public IIconProvider IconProvider
{
get;
set;
}
///
/// Gets or sets whether the platform supports custom expressions (default false).
///
public bool SupportsCustomExpressions
{
get;
set;
}
///
/// Specifies whether Material Design is relevant to theplatform.
///
public bool SupportsMaterialDesign
{
get;
set;
}
public bool SupportsBrushOpacity
{
get;
set;
}
///
/// Gets or sets a dictionary defining the property types will be grouped into a single editor and their groups key.
///
public IReadOnlyDictionary GroupedTypes
{
get;
set;
}
///
/// Gets or sets a collection of group keys that should be automatically expanded in grouped mode at first load.
///
public IReadOnlyCollection AutoExpandGroups
{
get;
set;
}
///
/// Gets or sets whether all groups should be expanded automatically.
///
/// This takes precedence over .
public bool AutoExpandAll
{
get;
set;
}
///
/// Gets or sets a list of the allowed arrange modes.
///
public IReadOnlyList ArrangeModes
{
get;
set;
} = new[] { PropertyArrangeMode.Name, PropertyArrangeMode.Category };
///
/// Gets or sets a callback for errors that should be edge cases and/or don't have a defined way of displaying in the UI.
///
///
/// The string parameter contains a message that typically prefixes an exception message with context (ex. "Error creating variant: [exception message]")
///
public Action ErrorHandler
{
get;
set;
}
internal void ReportError (string message, Exception exception)
{
if (ErrorHandler != null)
ErrorHandler (message, exception);
else
throw new Exception (message, exception);
}
internal TargetPlatform WithProvider (IEditorProvider provider)
{
if (provider == null)
throw new ArgumentNullException (nameof(provider));
return new TargetPlatform (provider) {
ResourceProvider = ResourceProvider,
BindingProvider = BindingProvider,
IconProvider = IconProvider,
SupportsMaterialDesign = SupportsMaterialDesign,
SupportsCustomExpressions = SupportsCustomExpressions,
SupportsBrushOpacity = SupportsBrushOpacity,
GroupedTypes = GroupedTypes,
AutoExpandGroups = AutoExpandGroups,
ArrangeModes = ArrangeModes,
ErrorHandler = ErrorHandler
};
}
}
}