diff options
Diffstat (limited to 'Xamarin.PropertyEditing')
3 files changed, 64 insertions, 7 deletions
diff --git a/Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs index 1d9e7a1..7b41e74 100644 --- a/Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/PanelViewModel.cs @@ -57,7 +57,7 @@ namespace Xamarin.PropertyEditing.ViewModels if (editor == null) throw new ArgumentNullException (nameof(editor)); - var list = GetList (editor); + var list = GetListCore (editor); if (editor is PropertyViewModel pvm && this.targetPlatform.GroupedTypes != null && this.targetPlatform.GroupedTypes.TryGetValue (pvm.Property.Type, out string groupName)) { var group = list.OfType<PropertyGroupViewModel> ().FirstOrDefault (gvm => gvm.Category == groupName); if (group != null) { @@ -99,6 +99,14 @@ namespace Xamarin.PropertyEditing.ViewModels this.isExpanded[mode] = expanded; } + public IReadOnlyList<EditorViewModel> GetList (EditorViewModel evm) + { + if (evm == null) + throw new ArgumentNullException (nameof(evm)); + + return (IReadOnlyList<EditorViewModel>)GetListCore (evm); + } + private Dictionary<PropertyArrangeMode, bool> isExpanded; private readonly ObservableCollectionEx<EditorViewModel> editors = new ObservableCollectionEx<EditorViewModel> (); private readonly ObservableCollectionEx<EditorViewModel> uncommonEditors = new ObservableCollectionEx<EditorViewModel> (); @@ -119,7 +127,7 @@ namespace Xamarin.PropertyEditing.ViewModels if (editor == null) throw new ArgumentNullException (nameof (editor)); - var list = GetList (editor); + var list = GetListCore (editor); if (editor is PropertyViewModel pvm && this.targetPlatform.GroupedTypes != null && this.targetPlatform.GroupedTypes.TryGetValue (pvm.Property.Type, out string groupName)) { var group = list.OfType<PropertyGroupViewModel> ().FirstOrDefault (gvm => gvm.Category == groupName); if (group != null) @@ -133,7 +141,7 @@ namespace Xamarin.PropertyEditing.ViewModels OnPropertyChanged (nameof(HasUncommonElements)); } - private IList<EditorViewModel> GetList (EditorViewModel evm) + private IList<EditorViewModel> GetListCore (EditorViewModel evm) { if (this.separateUncommon && evm is PropertyViewModel pvm) return pvm.Property.IsUncommon ? this.uncommonEditors : this.editors; @@ -341,6 +349,30 @@ namespace Xamarin.PropertyEditing.ViewModels ArrangedPropertiesChanged?.Invoke (this, EventArgs.Empty); } + internal override bool GetIsLastVariant (PropertyViewModel viewModel) + { + if (viewModel == null) + throw new ArgumentNullException (nameof (viewModel)); + if (!viewModel.IsVariant) + throw new ArgumentException ($"{nameof (viewModel)} is not a variant", nameof (viewModel)); + + string groupKey = GetGroup (viewModel); + PanelGroupViewModel group = this.arranged[groupKey]; + + var list = group.GetList (viewModel); + + int index = list.IndexOf (viewModel); + if (index == -1) + throw new KeyNotFoundException ($"{nameof (viewModel)} was not found"); + + if (++index == list.Count) + return true; + if (list[index] is PropertyViewModel pvm) { + return !Equals (viewModel.Property, pvm.Property); + } else + return false; + } + private readonly OrderedDictionary<string, PanelGroupViewModel> arranged = new OrderedDictionary<string, PanelGroupViewModel> (); private PropertyArrangeMode arrangeMode; diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs index 1c694d8..bc8e2e0 100644 --- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs @@ -216,6 +216,14 @@ namespace Xamarin.PropertyEditing.ViewModels { } + /// <summary> + /// Gets whether the <paramref name="viewModel"/> is the last-arranged variant property of its base property + /// </summary> + internal virtual bool GetIsLastVariant (PropertyViewModel viewModel) + { + throw new NotSupportedException(); + } + private INameableObject nameable; private bool nameReadOnly; private bool eventsEnabled; @@ -581,10 +589,10 @@ namespace Xamarin.PropertyEditing.ViewModels if (baseVm.HasVariations) { using (await AsyncWork.RequestAsyncWork (this)) { var variants = await GetVariationsAsync (property); - baseVm.HasVariantChildren = variants.Count > 0; - - foreach (PropertyVariation variant in variants) { - vms.Add (CreateViewModel (property, variant)); + if (baseVm.HasVariantChildren = variants.Count > 0) { + foreach (PropertyVariation variant in variants) { + vms.Add (CreateViewModel (property, variant)); + } } } } @@ -610,6 +618,7 @@ namespace Xamarin.PropertyEditing.ViewModels else vm = new StringPropertyViewModel (TargetPlatform, property, this.objEditors, variant); + vm.Parent = this; vm.VariantsChanged += OnVariantsChanged; return vm; } diff --git a/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs index 7d9067f..593aa51 100644 --- a/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs @@ -636,6 +636,12 @@ namespace Xamarin.PropertyEditing.ViewModels public bool IsVariant => Variation != null; + public PropertiesViewModel Parent + { + get; + internal set; + } + public abstract Resource Resource { get; @@ -724,6 +730,16 @@ namespace Xamarin.PropertyEditing.ViewModels get; } + public bool GetIsLastVariant () + { + if (Variation == null) + return false; + if (Parent == null) + throw new InvalidOperationException ($"{nameof(Parent)} must be set in order to determine last variant"); + + return Parent.GetIsLastVariant (this); + } + public override int CompareTo (EditorViewModel other) { int compare = base.CompareTo (other); |