/// <summary> /// Adds a new child element to <see cref="ElementCollectionModel"/>. /// </summary> /// <param name="parameter"> /// Data used by the command. If the command does not require data to be passed, this object can be set to null. /// </param> /// <remarks> /// Adds a new element to the collection through <see cref="ElementCollectionViewModel.AddNewCollectionElement"/> /// and makes the new element the selected element. /// </remarks> protected override void InnerExecute(object parameter) { addedElementViewModel = ElementCollectionModel.AddNewCollectionElement(ConfigurationElementType); addedElementViewModel.PropertiesShown = true; addedElementViewModel.Select(); applicationModel.SetDirty(); }
/// <summary> /// Sets properties on the newly minted <see cref="ElementViewModel"/>. /// </summary> /// <param name="createdElement">The element created.</param> /// <param name="selectedType">The element type created.</param> /// <remarks> /// By default, this sets the <see cref="ElementViewModel.NameProperty"/>'s value, if present. /// The command also updates the <see cref="Property.Value"/> of the property specified by <see cref="TypePickingCommandAttribute.Property"/> to /// the assembly qualified name of the selected type. /// </remarks> protected virtual void SetProperties(ElementViewModel createdElement, Type selectedType) { if (createdElement.NameProperty != null) { createdElement.NameProperty.Value = ElementCollectionModel.FindUniqueNewName(selectedType.Name); } createdElement.Property(propertyToSet).Value = selectedType.AssemblyQualifiedName; }
/// <summary> /// Adds a new child element to <see cref="DefaultCollectionElementAddCommand.ElementCollectionModel"/>. /// </summary> /// <param name="parameter">Not used. </param> /// <remarks> /// Collects the type from the user with the <see cref="TypeBrowser"/>. /// <br/> /// After collecting the type, inheritors of <see cref="TypePickingCollectionElementAddCommand"/> have /// an opportunity to take action if the override <see cref="AfterSelectType"/>. /// <br/> /// Then, a new element of the collected type is added through <see cref="ElementCollectionViewModel.AddNewCollectionElement"/>. /// </remarks> protected override void InnerExecute(object parameter) { var selectedType = GetSelectedType(); if (selectedType != null && AfterSelectType(selectedType)) { var createdElement = ElementCollectionModel.AddNewCollectionElement(CreatedElementType); createdElement.PropertiesShown = true; SetProperties(createdElement, selectedType); } }