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

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <me@ermau.com>2019-02-21 18:39:46 +0300
committerGitHub <noreply@github.com>2019-02-21 18:39:46 +0300
commit188bdd4e8d3f200b5506ae473743cdf8a0aa0872 (patch)
tree339db39469d3148a37476603af97d4081e368e88 /Xamarin.PropertyEditing
parent74cd11cc4e3972b8ca00eacd5c5015e796eac375 (diff)
parentaf9ca3b7b44d4a9d00ec76e9116a2c9d204ae501 (diff)
Merge pull request #541 from xamarin/ermau-type-selector-editor
Type selector editor
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r--Xamarin.PropertyEditing/Properties/Resources.Designer.cs18
-rw-r--r--Xamarin.PropertyEditing/Properties/Resources.resx7
-rw-r--r--Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs3
-rw-r--r--Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs1
-rw-r--r--Xamarin.PropertyEditing/ViewModels/TypePropertyViewModel.cs69
-rw-r--r--Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj1
6 files changed, 98 insertions, 1 deletions
diff --git a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
index 7a52edb..1249b10 100644
--- a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
+++ b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
@@ -1141,6 +1141,15 @@ namespace Xamarin.PropertyEditing.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Select.
+ /// </summary>
+ public static string Select {
+ get {
+ return ResourceManager.GetString("Select", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Select Object.
/// </summary>
public static string SelectObjectTitle {
@@ -1159,6 +1168,15 @@ namespace Xamarin.PropertyEditing.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Select {0} type.
+ /// </summary>
+ public static string SelectTypeForProperty {
+ get {
+ return ResourceManager.GetString("SelectTypeForProperty", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Shared.
/// </summary>
public static string Shared {
diff --git a/Xamarin.PropertyEditing/Properties/Resources.resx b/Xamarin.PropertyEditing/Properties/Resources.resx
index 168c1eb..9e44bbd 100644
--- a/Xamarin.PropertyEditing/Properties/Resources.resx
+++ b/Xamarin.PropertyEditing/Properties/Resources.resx
@@ -570,4 +570,11 @@
<value>New {0}</value>
<comment>New {PropertyName}</comment>
</data>
+ <data name="Select" xml:space="preserve">
+ <value>Select</value>
+ </data>
+ <data name="SelectTypeForProperty" xml:space="preserve">
+ <value>Select {0} type</value>
+ <comment>Select {property} type</comment>
+ </data>
</root> \ No newline at end of file
diff --git a/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs b/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
index 3ea7209..a7fbbc5 100644
--- a/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
+++ b/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
@@ -159,7 +159,8 @@ namespace Xamarin.PropertyEditing.Reflection
}
}
- types = types.Where (t => realType.IsAssignableFrom (t));
+ if (realType != typeof(Type))
+ types = types.Where (t => realType.IsAssignableFrom (t));
return new AssignableTypesResult (types.Select (t => {
string asmName = t.Assembly.GetName ().Name;
diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
index 0ee785b..7ddae70 100644
--- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
@@ -614,6 +614,7 @@ namespace Xamarin.PropertyEditing.ViewModels
{ typeof(BindingSource), (tp,p,e,v) => new PropertyViewModel<BindingSource> (tp, p, e, v) },
{ typeof(Resource), (tp,p,e,v) => new PropertyViewModel<Resource> (tp, p, e, v) },
{ typeof(object), (tp,p,e,v) => new ObjectPropertyViewModel (tp, p, e, v) },
+ { typeof(ITypeInfo), (tp,p,e,v) => new TypePropertyViewModel (tp, p, e, v) },
{ typeof(CommonRatio), (tp, p, e, v) => new RatioViewModel (tp, p, e, v) },
};
}
diff --git a/Xamarin.PropertyEditing/ViewModels/TypePropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/TypePropertyViewModel.cs
new file mode 100644
index 0000000..fe192d9
--- /dev/null
+++ b/Xamarin.PropertyEditing/ViewModels/TypePropertyViewModel.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+
+namespace Xamarin.PropertyEditing.ViewModels
+{
+ internal class TypePropertyViewModel
+ : PropertyViewModel<ITypeInfo>
+ {
+ public TypePropertyViewModel (TargetPlatform platform, IPropertyInfo propertyInfo, IEnumerable<IObjectEditor> editors, PropertyVariation variation = null)
+ : base (platform, propertyInfo, editors, variation)
+ {
+ SelectTypeCommand = new RelayCommand (SetType, () => Property.CanWrite);
+ }
+
+ public event EventHandler<TypeRequestedEventArgs> TypeRequested;
+
+ public ICommand SelectTypeCommand
+ {
+ get;
+ }
+
+ public AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> AssignableTypes
+ {
+ get
+ {
+ if (this.assignableTypes == null)
+ this.assignableTypes = new AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> (GetAssignableTypesAsync ());
+
+ return this.assignableTypes;
+ }
+ }
+
+ private AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> assignableTypes;
+
+ private async Task<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> GetAssignableTypesAsync ()
+ {
+ AssignableTypesResult result = await Editors.GetCommonAssignableTypes (Property, childTypes: false).ConfigureAwait (false);
+ return result.GetTypeTree ();
+ }
+
+ private async void SetType ()
+ {
+ using (await AsyncWork.RequestAsyncWork (this)) {
+ ITypeInfo selectedType = null;
+ var args = new TypeRequestedEventArgs ();
+ TypeRequested?.Invoke (this, args);
+ if (args.SelectedType == null)
+ return;
+
+ try {
+ selectedType = await args.SelectedType;
+ if (selectedType == null)
+ return;
+ } catch (OperationCanceledException) {
+ return;
+ }
+
+ await SetValueAsync (new ValueInfo<ITypeInfo> {
+ Value = selectedType,
+ Source = ValueSource.Local
+ });
+ }
+ }
+ }
+}
diff --git a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
index 35df7c9..b638f30 100644
--- a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
+++ b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
@@ -165,6 +165,7 @@
<Compile Include="ViewModels\RectanglePropertyViewModel.cs" />
<Compile Include="ViewModels\ThicknessPropertyViewModel.cs" />
<Compile Include="ViewModels\ObjectTreeElement.cs" />
+ <Compile Include="ViewModels\TypePropertyViewModel.cs" />
<Compile Include="ViewModels\TypeSelectorViewModel.cs" />
<Compile Include="ViewModels\RatioViewModel.cs" />
<Compile Include="Drawing\CommonRatio.cs" />