diff options
author | Eric Maupin <me@ermau.com> | 2018-09-01 00:45:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-01 00:45:55 +0300 |
commit | 017c948e29a0be922186a72b80a377d2f6370cf0 (patch) | |
tree | caac783d624898aca169cf69f495f92ba7c8270e | |
parent | 3a3f85446b327a39db0175a134ba63bcc67cc863 (diff) | |
parent | 537e3372ebdf61b3490d848b5c45fa4b5ed982b0 (diff) |
Merge pull request #381 from xamarin/ermau-fix-collection-editor-switch
[Core] Handle no-editors in CollectionPropertyViewModel
-rw-r--r-- | Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs | 22 | ||||
-rw-r--r-- | Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs | 9 |
2 files changed, 31 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs index 0139aad..7f87448 100644 --- a/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs +++ b/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs @@ -158,6 +158,28 @@ namespace Xamarin.PropertyEditing.Tests } [Test] + public async Task RemoveEditor () + { + TargetPlatform platform = new TargetPlatform (new MockEditorProvider ()); + + var obj = new { + Collection = new ArrayList () + }; + + var editor = new ReflectionObjectEditor (obj); + + var vm = new CollectionPropertyViewModel (platform, editor.Properties.First (), new[] { editor }); + await vm.AssignableTypes.Task; + + vm.Editors.Remove (editor); + await vm.AssignableTypes.Task; + + Assert.That (vm.AssignableTypes.Value, Is.Empty); + Assert.That (vm.SuggestedTypes, Is.Empty); + Assert.That (vm.SelectedType, Is.Null); + } + + [Test] public async Task MoveUpCommand () { TargetPlatform platform = new TargetPlatform (new MockEditorProvider()); diff --git a/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs index 641e19e..080a93a 100644 --- a/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs @@ -317,6 +317,15 @@ namespace Xamarin.PropertyEditing.ViewModels if (Property == null) return; + if (Editors.Count == 0) { + SuggestedTypes = new ObservableCollectionEx<ITypeInfo> (); + AssignableTypes = new AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> ( + Task.FromResult<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> ( + new Dictionary<IAssemblyInfo, ILookup<string, ITypeInfo>> ())); + SelectedType = 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); |