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 <ermaup@microsoft.com>2018-04-27 23:45:27 +0300
committerEric Maupin <ermaup@microsoft.com>2018-05-01 01:00:32 +0300
commit31f4af0b1babf93cfad66617a84c1b85b8a3681b (patch)
tree5407abb1b8c8b3da5e3c1827c39e9307794ba81a /Xamarin.PropertyEditing
parentce0b16d6b4ed11bf89c054a0fba1f6b81e5de441 (diff)
[Core/Win] Collection property editor
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r--Xamarin.PropertyEditing/AssignableTypesResult.cs1
-rw-r--r--Xamarin.PropertyEditing/Extensions.cs13
-rw-r--r--Xamarin.PropertyEditing/Properties/Resources.Designer.cs313
-rw-r--r--Xamarin.PropertyEditing/Properties/Resources.resx25
-rw-r--r--Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs260
-rw-r--r--Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs3
-rw-r--r--Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj1
7 files changed, 502 insertions, 114 deletions
diff --git a/Xamarin.PropertyEditing/AssignableTypesResult.cs b/Xamarin.PropertyEditing/AssignableTypesResult.cs
index 94269ac..814c8e7 100644
--- a/Xamarin.PropertyEditing/AssignableTypesResult.cs
+++ b/Xamarin.PropertyEditing/AssignableTypesResult.cs
@@ -13,6 +13,7 @@ namespace Xamarin.PropertyEditing
throw new ArgumentNullException (nameof(assignableTypes));
AssignableTypes = assignableTypes;
+ SuggestedTypes = new ITypeInfo[0];
}
public AssignableTypesResult (IReadOnlyList<ITypeInfo> suggestedTypes, IReadOnlyCollection<ITypeInfo> assignableTypes)
diff --git a/Xamarin.PropertyEditing/Extensions.cs b/Xamarin.PropertyEditing/Extensions.cs
index e789604..e3efa54 100644
--- a/Xamarin.PropertyEditing/Extensions.cs
+++ b/Xamarin.PropertyEditing/Extensions.cs
@@ -88,6 +88,19 @@ namespace Xamarin.PropertyEditing
self.Add (with);
}
+ public static void Move (this IList self, int index, int moveTo)
+ {
+ if (self == null)
+ throw new ArgumentNullException (nameof(self));
+
+ if (index < moveTo)
+ moveTo--;
+
+ object item = self[index];
+ self.RemoveAt (index);
+ self.Insert (moveTo, item);
+ }
+
public static bool TryRemove<TKey, TElement> (this IDictionary<TKey, TElement> self, TKey key, out TElement element)
{
if (!self.TryGetValue (key, out element))
diff --git a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
index 98c0e60..f065311 100644
--- a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
+++ b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
@@ -11,21 +11,21 @@
namespace Xamarin.PropertyEditing.Properties {
using System;
using System.Reflection;
-
-
+
+
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources {
-
+
private static System.Resources.ResourceManager resourceMan;
-
+
private static System.Globalization.CultureInfo resourceCulture;
-
+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
-
+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
public static System.Resources.ResourceManager ResourceManager {
get {
@@ -36,7 +36,7 @@ namespace Xamarin.PropertyEditing.Properties {
return resourceMan;
}
}
-
+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
public static System.Globalization.CultureInfo Culture {
get {
@@ -46,115 +46,157 @@ namespace Xamarin.PropertyEditing.Properties {
resourceCulture = value;
}
}
-
+
public static string Alpha {
get {
return ResourceManager.GetString("Alpha", resourceCulture);
}
}
-
+
public static string AlphaInitial {
get {
return ResourceManager.GetString("AlphaInitial", resourceCulture);
}
}
-
+
public static string Black {
get {
return ResourceManager.GetString("Black", resourceCulture);
}
}
-
+
public static string BlackInitial {
get {
return ResourceManager.GetString("BlackInitial", resourceCulture);
}
}
-
+
public static string Blue {
get {
return ResourceManager.GetString("Blue", resourceCulture);
}
}
-
+
public static string BlueInitial {
get {
return ResourceManager.GetString("BlueInitial", resourceCulture);
}
}
-
+
public static string Brightness {
get {
return ResourceManager.GetString("Brightness", resourceCulture);
}
}
-
+
public static string BrightnessInitial {
get {
return ResourceManager.GetString("BrightnessInitial", resourceCulture);
}
}
-
+
public static string CMYK {
get {
return ResourceManager.GetString("CMYK", resourceCulture);
}
}
-
+
+ /// <summary>
+ /// Looks up a localized string similar to Collection Editor: {0}.
+ /// </summary>
+ public static string CollectionEditorTitle {
+ get {
+ return ResourceManager.GetString("CollectionEditorTitle", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to (Collection).
+ /// </summary>
+ public static string CollectionValue {
+ get {
+ return ResourceManager.GetString("CollectionValue", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Editor.
+ /// </summary>
+ public static string ColorEditorTabLabel {
+ get {
+ return ResourceManager.GetString("ColorEditorTabLabel", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Color space.
+ /// </summary>
public static string ColorSpace {
get {
return ResourceManager.GetString("ColorSpace", resourceCulture);
}
}
-
+
public static string CurrentColor {
get {
return ResourceManager.GetString("CurrentColor", resourceCulture);
}
}
-
+
public static string Cyan {
get {
return ResourceManager.GetString("Cyan", resourceCulture);
}
}
-
+
public static string CyanInitial {
get {
return ResourceManager.GetString("CyanInitial", resourceCulture);
}
}
-
+
public static string CyanMagentaYellowBlack {
get {
return ResourceManager.GetString("CyanMagentaYellowBlack", resourceCulture);
}
}
-
+
public static string ConvertToLocalValue {
get {
return ResourceManager.GetString("ConvertToLocalValue", resourceCulture);
}
}
-
+
public static string CustomExpressionEllipsis {
get {
return ResourceManager.GetString("CustomExpressionEllipsis", resourceCulture);
}
}
-
+
+ /// <summary>
+ /// Looks up a localized string similar to ….
+ /// </summary>
+ public static string Ellipsis {
+ get {
+ return ResourceManager.GetString("Ellipsis", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Event handlers for the selected element.
+ /// </summary>
public static string EventHandlersSelectedElement {
get {
return ResourceManager.GetString("EventHandlersSelectedElement", resourceCulture);
}
}
-
+
public static string Events {
get {
return ResourceManager.GetString("Events", resourceCulture);
}
}
-
+
/// <summary>
/// Looks up a localized string similar to Go to Source.
/// </summary>
@@ -163,7 +205,7 @@ namespace Xamarin.PropertyEditing.Properties {
return ResourceManager.GetString("GoToSource", resourceCulture);
}
}
-
+
/// <summary>
/// Looks up a localized string similar to Green.
/// </summary>
@@ -172,481 +214,526 @@ namespace Xamarin.PropertyEditing.Properties {
return ResourceManager.GetString("Green", resourceCulture);
}
}
-
+
public static string GreenInitial {
get {
return ResourceManager.GetString("GreenInitial", resourceCulture);
}
}
-
+
public static string HexValue {
get {
return ResourceManager.GetString("HexValue", resourceCulture);
}
}
-
+
public static string HLS {
get {
return ResourceManager.GetString("HLS", resourceCulture);
}
}
-
+
public static string HSB {
get {
return ResourceManager.GetString("HSB", resourceCulture);
}
}
-
+
public static string Hue {
get {
return ResourceManager.GetString("Hue", resourceCulture);
}
}
-
+
public static string HueInitial {
get {
return ResourceManager.GetString("HueInitial", resourceCulture);
}
}
-
+
public static string HueLightnessSaturation {
get {
return ResourceManager.GetString("HueLightnessSaturation", resourceCulture);
}
}
-
+
public static string HueSaturationBrightness {
get {
return ResourceManager.GetString("HueSaturationBrightness", resourceCulture);
}
}
-
+
public static string InitialColor {
get {
return ResourceManager.GetString("InitialColor", resourceCulture);
}
}
-
+
+ /// <summary>
+ /// Looks up a localized string similar to {0} is an Invalid Value.
+ /// </summary>
+ public static string InvalidValue {
+ get {
+ return ResourceManager.GetString("InvalidValue", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Items.
+ /// </summary>
+ public static string Items {
+ get {
+ return ResourceManager.GetString("Items", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Last color.
+ /// </summary>
public static string LastColor {
get {
return ResourceManager.GetString("LastColor", resourceCulture);
}
}
-
+
public static string Lightness {
get {
return ResourceManager.GetString("Lightness", resourceCulture);
}
}
-
+
public static string LightnessInitial {
get {
return ResourceManager.GetString("LightnessInitial", resourceCulture);
}
}
-
+
public static string Magenta {
get {
return ResourceManager.GetString("Magenta", resourceCulture);
}
}
-
+
public static string MagentaInitial {
get {
return ResourceManager.GetString("MagentaInitial", resourceCulture);
}
}
-
+
public static string MultipleObjectsSelected {
get {
return ResourceManager.GetString("MultipleObjectsSelected", resourceCulture);
}
}
-
+
public static string MultipleTypesSelected {
get {
return ResourceManager.GetString("MultipleTypesSelected", resourceCulture);
}
}
-
+
public static string Name {
get {
return ResourceManager.GetString("Name", resourceCulture);
}
}
-
+
public static string NoName {
get {
return ResourceManager.GetString("NoName", resourceCulture);
}
}
-
+
public static string Properties {
get {
return ResourceManager.GetString("Properties", resourceCulture);
}
}
-
+
public static string PropertiesSelectedElement {
get {
return ResourceManager.GetString("PropertiesSelectedElement", resourceCulture);
}
}
-
+
public static string Red {
get {
return ResourceManager.GetString("Red", resourceCulture);
}
}
-
+
public static string RedGreenBlue {
get {
return ResourceManager.GetString("RedGreenBlue", resourceCulture);
}
}
-
+
public static string RedInitial {
get {
return ResourceManager.GetString("RedInitial", resourceCulture);
}
}
-
+
public static string RGB {
get {
return ResourceManager.GetString("RGB", resourceCulture);
}
}
-
+
public static string Saturation {
get {
return ResourceManager.GetString("Saturation", resourceCulture);
}
}
-
+
public static string SaturationInitial {
get {
return ResourceManager.GetString("SaturationInitial", resourceCulture);
}
}
-
+
public static string Reset {
get {
return ResourceManager.GetString("Reset", resourceCulture);
}
}
-
+
public static string Type {
get {
return ResourceManager.GetString("Type", resourceCulture);
}
}
-
+
public static string ViewPropertiesOrEvents {
get {
return ResourceManager.GetString("ViewPropertiesOrEvents", resourceCulture);
}
}
-
+
public static string Yellow {
get {
return ResourceManager.GetString("Yellow", resourceCulture);
}
}
-
+
public static string YellowInitial {
get {
return ResourceManager.GetString("YellowInitial", resourceCulture);
}
}
-
+
public static string NoBrush {
get {
return ResourceManager.GetString("NoBrush", resourceCulture);
}
}
-
+
public static string SolidBrush {
get {
return ResourceManager.GetString("SolidBrush", resourceCulture);
}
}
-
+
public static string ResourceBrush {
get {
return ResourceManager.GetString("ResourceBrush", resourceCulture);
}
}
-
+
public static string Opacity {
get {
return ResourceManager.GetString("Opacity", resourceCulture);
}
}
-
+
+ /// <summary>
+ /// Looks up a localized string similar to Move item down.
+ /// </summary>
+ public static string MoveItemDown {
+ get {
+ return ResourceManager.GetString("MoveItemDown", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Move item up.
+ /// </summary>
+ public static string MoveItemUp {
+ get {
+ return ResourceManager.GetString("MoveItemUp", resourceCulture);
+ }
+ }
+
public static string ShowAdvancedProperties {
get {
return ResourceManager.GetString("ShowAdvancedProperties", resourceCulture);
}
}
-
+
public static string Cancel {
get {
return ResourceManager.GetString("Cancel", resourceCulture);
}
}
-
+
public static string OK {
get {
return ResourceManager.GetString("OK", resourceCulture);
}
}
-
+
public static string ShowAllAssemblies {
get {
return ResourceManager.GetString("ShowAllAssemblies", resourceCulture);
}
}
-
+
public static string SearchProperties {
get {
return ResourceManager.GetString("SearchProperties", resourceCulture);
}
}
-
+
public static string New {
get {
return ResourceManager.GetString("New", resourceCulture);
}
}
-
+
public static string SearchObjectsTitle {
get {
return ResourceManager.GetString("SearchObjectsTitle", resourceCulture);
}
}
-
+
public static string SelectObjectTitle {
get {
return ResourceManager.GetString("SelectObjectTitle", resourceCulture);
}
}
-
+
public static string CustomExpression {
get {
return ResourceManager.GetString("CustomExpression", resourceCulture);
}
}
-
- public static string ColorEditorTabLabel {
+
+ public static string SearchResourcesTitle {
get {
- return ResourceManager.GetString("ColorEditorTabLabel", resourceCulture);
+ return ResourceManager.GetString("SearchResourcesTitle", resourceCulture);
}
}
-
- public static string SearchResourcesTitle {
+
+ /// <summary>
+ /// Looks up a localized string similar to &lt;Other type…&gt;.
+ /// </summary>
+ public static string OtherTypeAction {
get {
- return ResourceManager.GetString("SearchResourcesTitle", resourceCulture);
+ return ResourceManager.GetString("OtherTypeAction", resourceCulture);
}
}
-
+
public static string SelectResourceTitle {
get {
return ResourceManager.GetString("SelectResourceTitle", resourceCulture);
}
}
-
+
public static string ShowSystemResources {
get {
return ResourceManager.GetString("ShowSystemResources", resourceCulture);
}
}
-
+
public static string ResourceEllipsis {
get {
return ResourceManager.GetString("ResourceEllipsis", resourceCulture);
}
}
-
+
public static string Default {
get {
return ResourceManager.GetString("Default", resourceCulture);
}
}
-
+
public static string Inherited {
get {
return ResourceManager.GetString("Inherited", resourceCulture);
}
}
-
- public static string InvalidValue {
+
+ /// <summary>
+ /// Looks up a localized string similar to Remove item.
+ /// </summary>
+ public static string RemoveItem {
get {
- return ResourceManager.GetString("InvalidValue", resourceCulture);
+ return ResourceManager.GetString("RemoveItem", resourceCulture);
}
}
-
+
public static string Local {
get {
return ResourceManager.GetString("Local", resourceCulture);
}
}
-
+
public static string Unset {
get {
return ResourceManager.GetString("Unset", resourceCulture);
}
}
-
+
public static string MaterialColorRed {
get {
return ResourceManager.GetString("MaterialColorRed", resourceCulture);
}
}
-
+
public static string MaterialColorPink {
get {
return ResourceManager.GetString("MaterialColorPink", resourceCulture);
}
}
-
+
public static string MaterialColorPurple {
get {
return ResourceManager.GetString("MaterialColorPurple", resourceCulture);
}
}
-
+
public static string MaterialColorDeepPurple {
get {
return ResourceManager.GetString("MaterialColorDeepPurple", resourceCulture);
}
}
-
+
public static string MaterialColorIndigo {
get {
return ResourceManager.GetString("MaterialColorIndigo", resourceCulture);
}
}
-
+
public static string MaterialColorBlue {
get {
return ResourceManager.GetString("MaterialColorBlue", resourceCulture);
}
}
-
+
public static string MaterialColorLightBlue {
get {
return ResourceManager.GetString("MaterialColorLightBlue", resourceCulture);
}
}
-
+
public static string MaterialColorCyan {
get {
return ResourceManager.GetString("MaterialColorCyan", resourceCulture);
}
}
-
+
public static string MaterialColorTeal {
get {
return ResourceManager.GetString("MaterialColorTeal", resourceCulture);
}
}
-
+
public static string MaterialColorGreen {
get {
return ResourceManager.GetString("MaterialColorGreen", resourceCulture);
}
}
-
+
public static string MaterialColorLightGreen {
get {
return ResourceManager.GetString("MaterialColorLightGreen", resourceCulture);
}
}
-
+
public static string MaterialColorLime {
get {
return ResourceManager.GetString("MaterialColorLime", resourceCulture);
}
}
-
+
public static string MaterialColorYellow {
get {
return ResourceManager.GetString("MaterialColorYellow", resourceCulture);
}
}
-
+
public static string MaterialColorAmber {
get {
return ResourceManager.GetString("MaterialColorAmber", resourceCulture);
}
}
-
+
public static string MaterialColorOrange {
get {
return ResourceManager.GetString("MaterialColorOrange", resourceCulture);
}
}
-
+
public static string MaterialColorDeepOrange {
get {
return ResourceManager.GetString("MaterialColorDeepOrange", resourceCulture);
}
}
-
+
public static string MaterialColorBrown {
get {
return ResourceManager.GetString("MaterialColorBrown", resourceCulture);
}
}
-
+
public static string MaterialColorGrey {
get {
return ResourceManager.GetString("MaterialColorGrey", resourceCulture);
}
}
-
+
public static string MaterialColorBlueGrey {
get {
return ResourceManager.GetString("MaterialColorBlueGrey", resourceCulture);
}
}
-
+
public static string MaterialDesignColorBrush {
get {
return ResourceManager.GetString("MaterialDesignColorBrush", resourceCulture);
}
}
-
+
public static string MaterialColorBlackAndWhite {
get {
return ResourceManager.GetString("MaterialColorBlackAndWhite", resourceCulture);
}
}
-
+
public static string White {
get {
return ResourceManager.GetString("White", resourceCulture);
}
}
-
+
public static string NoPreviewAvailable {
get {
return ResourceManager.GetString("NoPreviewAvailable", resourceCulture);
}
}
-
+
public static string Resource {
get {
return ResourceManager.GetString("Resource", resourceCulture);
}
}
-
+
public static string ResourceWithName {
get {
return ResourceManager.GetString("ResourceWithName", resourceCulture);
}
}
-
+
public static string Binding {
get {
return ResourceManager.GetString("Binding", resourceCulture);
diff --git a/Xamarin.PropertyEditing/Properties/Resources.resx b/Xamarin.PropertyEditing/Properties/Resources.resx
index fb3e6b1..15ed5c0 100644
--- a/Xamarin.PropertyEditing/Properties/Resources.resx
+++ b/Xamarin.PropertyEditing/Properties/Resources.resx
@@ -461,4 +461,29 @@
<data name="GoToSource" xml:space="preserve">
<value>Go to Source</value>
</data>
+ <data name="CollectionValue" xml:space="preserve">
+ <value>(Collection)</value>
+ <comment>Indicates that a collection is the value of the property</comment>
+ </data>
+ <data name="Ellipsis" xml:space="preserve">
+ <value>…</value>
+ </data>
+ <data name="OtherTypeAction" xml:space="preserve">
+ <value>&lt;Other type…&gt;</value>
+ </data>
+ <data name="Items" xml:space="preserve">
+ <value>Items</value>
+ </data>
+ <data name="CollectionEditorTitle" xml:space="preserve">
+ <value>Collection Editor: {0}</value>
+ </data>
+ <data name="MoveItemDown" xml:space="preserve">
+ <value>Move item down</value>
+ </data>
+ <data name="MoveItemUp" xml:space="preserve">
+ <value>Move item up</value>
+ </data>
+ <data name="RemoveItem" xml:space="preserve">
+ <value>Remove item</value>
+ </data>
</root> \ No newline at end of file
diff --git a/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs
new file mode 100644
index 0000000..94f68a5
--- /dev/null
+++ b/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs
@@ -0,0 +1,260 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using Xamarin.PropertyEditing.Properties;
+
+namespace Xamarin.PropertyEditing.ViewModels
+{
+ internal class CollectionPropertyViewModel
+ : PropertyViewModel<IList>
+ {
+ public CollectionPropertyViewModel (TargetPlatform platform, IPropertyInfo property, IEnumerable<IObjectEditor> editors)
+ : base (platform, property, editors)
+ {
+ RequestTypes ();
+
+ Panel = new PanelViewModel (platform) {
+ ArrangeMode = PropertyArrangeMode.Category,
+ AutoExpand = true
+ };
+
+ AddTargetCommand = new RelayCommand (OnAddTarget);
+ RemoveTargetCommand = new RelayCommand (OnRemoveTarget, CanAffectTarget);
+ MoveUpCommand = new RelayCommand (() => MoveTarget (up: true), () => CanMoveTarget (up: true));
+ MoveDownCommand = new RelayCommand (() => MoveTarget (up: false), () => CanMoveTarget (up: false));
+ CommitCommand = new RelayCommand (OnCommitCommand);
+
+ this.collectionView.CollectionChanged += OnCollectionViewContentsChanged;
+ }
+
+ public event EventHandler<TypeRequestedEventArgs> TypeRequested;
+
+ public IReadOnlyList<object> Targets => this.collectionView;
+
+ public IReadOnlyList<ITypeInfo> SuggestedTypes
+ {
+ get { return this.suggestedTypes; }
+ private set
+ {
+ if (this.suggestedTypes == value)
+ return;
+
+ this.suggestedTypes = (ObservableCollectionEx<ITypeInfo>)value;
+ OnPropertyChanged();
+ }
+ }
+
+ public AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> AssignableTypes
+ {
+ get { return this.assignableTypes; }
+ private set
+ {
+ if (this.assignableTypes == value)
+ return;
+
+ this.assignableTypes = value;
+ OnPropertyChanged();
+ }
+ }
+
+ public object SelectedTarget
+ {
+ get { return this.selectedTarget; }
+ set
+ {
+ if (this.selectedTarget == value)
+ return;
+
+ object old = this.selectedTarget;
+ this.selectedTarget = value;
+
+ if (value != null)
+ Panel.SelectedObjects.ReplaceOrAdd (old, value);
+ else
+ Panel.SelectedObjects.Clear();
+
+ OnPropertyChanged();
+ UpdateTargetCommands ();
+ }
+ }
+
+ public PanelViewModel Panel
+ {
+ get;
+ }
+
+ public ITypeInfo SelectedType
+ {
+ get { return this.selectedType; }
+ set
+ {
+ if (this.selectedType == value)
+ return;
+
+ this.selectedType = value;
+ OnPropertyChanged();
+
+ if (value == OtherType)
+ RequestOtherType ();
+ }
+ }
+
+ public ICommand MoveUpCommand
+ {
+ get;
+ }
+
+ public ICommand MoveDownCommand
+ {
+ get;
+ }
+
+ public ICommand AddTargetCommand
+ {
+ get;
+ }
+
+ public ICommand RemoveTargetCommand
+ {
+ get;
+ }
+
+ public ICommand CommitCommand
+ {
+ get;
+ }
+
+ protected override async Task UpdateCurrentValueAsync ()
+ {
+ await base.UpdateCurrentValueAsync ();
+
+ if (Value != null)
+ this.collectionView.Reset (Value.Cast<object>());
+ else
+ this.collectionView.Clear();
+ }
+
+ protected override void OnEditorsChanged (object sender, NotifyCollectionChangedEventArgs e)
+ {
+ base.OnEditorsChanged (sender, e);
+ RequestTypes ();
+ }
+
+ private object selectedTarget;
+ private ITypeInfo selectedType;
+ private AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> assignableTypes;
+ private ObservableCollectionEx<ITypeInfo> suggestedTypes;
+ private readonly ObservableCollectionEx<object> collectionView = new ObservableCollectionEx<object> ();
+
+ private static readonly ITypeInfo OtherType = new OtherTypeFake();
+
+ private class OtherTypeFake
+ : ITypeInfo
+ {
+ public IAssemblyInfo Assembly => null;
+ public string NameSpace => null;
+ public string Name => Resources.OtherTypeAction;
+ }
+
+ private async void RequestTypes ()
+ {
+ if (Property == null)
+ return;
+
+ var types = Editors.GetCommonAssignableTypes (Property, childTypes: true);
+ var assignableTypesTask = types.ContinueWith (t => t.Result.GetTypeTree (), TaskScheduler.Default);
+ AssignableTypes = new AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> (assignableTypesTask);
+
+ var results = await types;
+ var suggested = new ObservableCollectionEx<ITypeInfo> (results.SuggestedTypes);
+ if (results.AssignableTypes.Count > suggested.Count)
+ suggested.Add (OtherType);
+
+ SuggestedTypes = suggested;
+ SelectedType = (results.SuggestedTypes.Count > 0) ? results.SuggestedTypes[0] : null;
+ }
+
+ private Task PushValueAsync ()
+ {
+ object[] snapshot = this.collectionView.ToArray ();
+ return SetValueAsync (new ValueInfo<IList> {
+ Value = snapshot,
+ Source = ValueSource.Local
+ });
+ }
+
+ private async void OnCommitCommand ()
+ {
+ await PushValueAsync ();
+ }
+
+ private void RequestOtherType ()
+ {
+ var args = new TypeRequestedEventArgs();
+ TypeRequested?.Invoke (this, args);
+
+ if (args.SelectedType == null) {
+ // We know we have OtherType because we're in this method, and we know its at the bottom
+ SelectedType = SuggestedTypes.Count > 1 ? SuggestedTypes[0] : null;
+ return;
+ }
+
+ if (!this.suggestedTypes.Contains (args.SelectedType)) {
+ this.suggestedTypes.Insert (0, args.SelectedType);
+ }
+
+ SelectedType = args.SelectedType;
+ }
+
+ private void OnCollectionViewContentsChanged (object sender, NotifyCollectionChangedEventArgs e)
+ {
+ UpdateTargetCommands ();
+ }
+
+ private bool CanAffectTarget ()
+ {
+ return (SelectedTarget != null);
+ }
+
+ private bool CanMoveTarget (bool up)
+ {
+ int index = this.collectionView.IndexOf (SelectedTarget);
+ if (index == -1)
+ return false;
+
+ return (up) ? (index > 0) : (index < this.collectionView.Count - 1);
+ }
+
+ private void MoveTarget (bool up)
+ {
+ int index = this.collectionView.IndexOf (SelectedTarget);
+ this.collectionView.Move (index, index + ((up) ? -1 : 1));
+ }
+
+ private async void OnAddTarget ()
+ {
+ object target = await TargetPlatform.EditorProvider.CreateObjectAsync (SelectedType);
+ this.collectionView.Add (target);
+ SelectedTarget = target;
+ }
+
+ private void OnRemoveTarget ()
+ {
+ int index = Math.Max (0, this.collectionView.IndexOf (SelectedTarget) - 1);
+ this.collectionView.Remove (SelectedTarget);
+
+ SelectedTarget = (this.collectionView.Count > 0) ? this.collectionView[index] : null;
+ }
+
+ private void UpdateTargetCommands ()
+ {
+ ((RelayCommand)RemoveTargetCommand).ChangeCanExecute();
+ ((RelayCommand)MoveUpCommand).ChangeCanExecute();
+ ((RelayCommand)MoveDownCommand).ChangeCanExecute();
+ }
+ }
+}
diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
index 51e0d27..4318b1e 100644
--- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
@@ -466,7 +466,8 @@ namespace Xamarin.PropertyEditing.ViewModels
{ typeof(CommonPoint), (tp,p,e) => new PointPropertyViewModel (tp, p, e) },
{ typeof(CommonSize), (tp,p,e) => new SizePropertyViewModel (tp, p, e) },
{ typeof(CommonRectangle), (tp,p,e) => new RectanglePropertyViewModel (tp, p, e) },
- { typeof(CommonThickness), (tp,p, e) => new ThicknessPropertyViewModel (tp, p, e) },
+ { typeof(CommonThickness), (tp,p,e) => new ThicknessPropertyViewModel (tp, p, e) },
+ { typeof(IList), (tp,p,e) => new CollectionPropertyViewModel (tp,p,e) },
{ typeof(object), (tp,p,e) => new ObjectPropertyViewModel (tp,p,e) },
};
}
diff --git a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
index bd72844..5de9788 100644
--- a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
+++ b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
@@ -113,6 +113,7 @@
<Compile Include="ValueSource.cs" />
<Compile Include="ViewModels\ArrangeModeViewModel.cs" />
<Compile Include="ViewModels\BrushPropertyViewModel.cs" />
+ <Compile Include="ViewModels\CollectionPropertyViewModel.cs" />
<Compile Include="ViewModels\MaterialColorScale.cs" />
<Compile Include="ViewModels\MaterialDesignColorViewModel.cs" />
<Compile Include="ViewModels\CombinablePropertyViewModel.cs" />