Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TargetPlatform.cs « Xamarin.PropertyEditing - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: be136d62219d67b9b4b35e6127ac43580fcc17cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;

namespace Xamarin.PropertyEditing
{
	/// <summary>
	/// Represents a target platform by defining top level feature support and presentation preferences 
	/// </summary>
	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;
		}

		/// <summary>
		/// Gets the <see cref="IEditorProvider"/> associated with this platform.
		/// </summary>
		public IEditorProvider EditorProvider
		{
			get;
		}

		public IResourceProvider ResourceProvider
		{
			get;
			private set;
		}

		public IBindingProvider BindingProvider
		{
			get;
			private set;
		}

		public IIconProvider IconProvider
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets whether the platform supports custom expressions (default false).
		/// </summary>
		public bool SupportsCustomExpressions
		{
			get;
			set;
		}

		/// <summary>
		/// Specifies whether Material Design is relevant to theplatform.
		/// </summary>
		public bool SupportsMaterialDesign
		{
			get;
			set;
		}

		public bool SupportsBrushOpacity
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a dictionary defining the property types will be grouped into a single editor and their groups key.
		/// </summary>
		public IReadOnlyDictionary<Type, string> GroupedTypes
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a collection of group keys that should be automatically expanded in grouped mode at first load.
		/// </summary>
		public IReadOnlyCollection<string> AutoExpandGroups
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a list of the allowed arrange modes.
		/// </summary>
		public IReadOnlyList<PropertyArrangeMode> ArrangeModes
		{
			get;
			set;
		} = new[] { PropertyArrangeMode.Name, PropertyArrangeMode.Category };

		/// <summary>
		/// 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.
		/// </summary>
		/// <remarks>
		/// The string parameter contains a message that typically prefixes an exception message with context (ex. "Error creating variant: [exception message]")
		/// </remarks>
		public Action<string, Exception> 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
			};
		}
	}
}