public ObjectTreeElement(IEditorProvider provider, IObjectEditor editor) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } if (editor == null) { throw new ArgumentNullException(nameof(editor)); } Editor = editor; Children = new AsyncValue <IReadOnlyList <ObjectTreeElement> > (QueryChildrenAsync(provider)); string typeName = $"[{Editor.TargetType.Name}]"; Task <string> nameTask; INameableObject nameable = Editor as INameableObject; if (nameable != null) { nameTask = nameable.GetNameAsync().ContinueWith(t => (!String.IsNullOrWhiteSpace(t.Result)) ? $"{typeName} \"{t.Result}\"" : typeName, TaskScheduler.Default); } else { nameTask = Task.FromResult(typeName); } Name = new AsyncValue <string> (nameTask, typeName); }
private void UpdateMembers(IObjectEditor[] removedEditors = null, IObjectEditor[] newEditors = null) { if (this.objEditors.Count == 0) { ClearMembers(); return; } Task <string> nameQuery = null; INameableObject firstNameable = this.objEditors[0] as INameableObject; if (this.objEditors.Count == 1) { nameQuery = firstNameable?.GetNameAsync(); } IObjectEventEditor events = this.objEditors[0] as IObjectEventEditor; var newEventSet = new HashSet <IEventInfo> (events?.Events ?? Enumerable.Empty <IEventInfo> ()); string newTypeName = this.objEditors[0]?.TypeName; var newPropertySet = new HashSet <IPropertyInfo> (this.objEditors[0]?.Properties ?? Enumerable.Empty <IPropertyInfo>()); for (int i = 1; i < this.objEditors.Count; i++) { IObjectEditor editor = this.objEditors[i]; newPropertySet.IntersectWith(editor.Properties); if (editor is IObjectEventEditor) { events = (IObjectEventEditor)editor; newEventSet.IntersectWith(events.Events); } if (firstNameable == null) { firstNameable = editor as INameableObject; } if (newTypeName != editor.TypeName) { newTypeName = String.Format(PropertyEditing.Properties.Resources.MultipleTypesSelected, this.objEditors.Count); } } TypeName = newTypeName; UpdateProperties(newPropertySet, removedEditors, newEditors); EventsEnabled = events != null; UpdateEvents(newEventSet, removedEditors, newEditors); string name = (this.objEditors.Count > 1) ? String.Format(PropertyEditing.Properties.Resources.MultipleObjectsSelected, this.objEditors.Count) : PropertyEditing.Properties.Resources.NoName; if (this.objEditors.Count == 1) { string tname = nameQuery?.Result; if (tname != null) { name = tname; } } SetNameable(firstNameable); SetCurrentObjectName(name, this.objEditors.Count > 1); }
private async Task UpdateMembersAsync(IObjectEditor[] removedEditors = null, IObjectEditor[] newEditors = null) { if (this.objEditors.Count == 0) { ClearMembers(); return; } IObjectEditor editor = this.objEditors[0]; Task <string> nameQuery = null; INameableObject firstNameable = editor as INameableObject; if (this.objEditors.Count == 1) { nameQuery = firstNameable?.GetNameAsync(); } IObjectEventEditor events = editor as IObjectEventEditor; var newEventSet = new HashSet <IEventInfo> (events?.Events ?? Enumerable.Empty <IEventInfo> ()); bool knownProperties = (editor?.KnownProperties?.Count ?? 0) > 0; string newTypeName = editor?.TargetType.Name; var newPropertySet = new HashSet <IPropertyInfo> (editor?.Properties ?? Enumerable.Empty <IPropertyInfo>()); for (int i = 1; i < this.objEditors.Count; i++) { editor = this.objEditors[i]; if (editor == null) { continue; } newPropertySet.IntersectWith(editor.Properties); if (editor is IObjectEventEditor) { events = (IObjectEventEditor)editor; newEventSet.IntersectWith(events.Events); } if (firstNameable == null) { firstNameable = editor as INameableObject; } if (newTypeName != editor.TargetType.Name) { newTypeName = String.Format(PropertyEditing.Properties.Resources.MultipleTypesSelected, this.objEditors.Count); } if (!knownProperties) { knownProperties = (editor.KnownProperties?.Count ?? 0) > 0; } } TypeName = newTypeName; if (knownProperties && this.knownEditors == null) { this.knownEditors = new BidirectionalDictionary <KnownProperty, EditorViewModel> (); } await UpdatePropertiesAsync(newPropertySet, removedEditors, newEditors); EventsEnabled = events != null; UpdateEvents(newEventSet, removedEditors, newEditors); string name = (this.objEditors.Count > 1) ? String.Format(PropertyEditing.Properties.Resources.MultipleObjectsSelected, this.objEditors.Count) : PropertyEditing.Properties.Resources.NoName; if (this.objEditors.Count == 1) { string tname = nameQuery?.Result; if (tname != null) { name = tname; } } SetNameable(firstNameable); SetCurrentObjectName(name, this.objEditors.Count > 1); }