/// <summary> /// Sets the specified array as the items of the collection. /// </summary> /// <param name="editValue">The collection to edit.</param> /// <param name="value">An array of objects to set as the collection items.</param> /// <returns> /// The newly created collection object or, otherwise, the collection indicated by the <paramref name="editValue"/> parameter. /// </returns> protected override object SetItems(object editValue, object[] value) { object result = base.SetItems(editValue, value); IComponentChangeService svc = _context.GetService(typeof(IComponentChangeService)) as IComponentChangeService; INameController controller = editValue as INameController; if (controller != null && svc != null && (editValue is ChartAreaCollection || editValue is LegendCollection)) { IList newList = (IList)result; bool elementsRemoved = false; foreach (ChartNamedElement element in controller.Snapshot) { if (newList.IndexOf(element) < 0) { elementsRemoved = true; } } if (elementsRemoved) { svc.OnComponentChanging(this._chart, null); ChartNamedElement defaultElement = (ChartNamedElement)(newList.Count > 0 ? newList[0] : null); foreach (ChartNamedElement element in controller.Snapshot) { if (newList.IndexOf(element) < 0) { controller.OnNameReferenceChanged(new NameReferenceChangedEventArgs(element, defaultElement)); } } svc.OnComponentChanged(this._chart, null, null, null); } } return(result); }
private void Awake() { _nameController = new NameController(); _nameController.Initialize(new NameData(), _nameView); _nameController.SetName("user"); _nameController.ActivateInput += OnActivateInput; _inputNameController = new InputNameController(); _inputNameController.Initialize(new InputNameData(), _inputNameView); _inputNameController.TextInput += OnTextInput; }
/// <summary> /// Edit object's value. /// </summary> /// <param name="context">Descriptor context.</param> /// <param name="provider">Service provider.</param> /// <param name="value">Value to edit.</param> /// <returns>The new value of the object.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { _context = context; if (context != null && context.Instance != null) { // Save current control type descriptor context _chart = context.Instance as Chart; } INameController controller = value as INameController; bool isReferenceCollection = controller != null && (value is ChartAreaCollection || value is LegendCollection); try { if (isReferenceCollection) { controller.DoSnapshot(true, new EventHandler <NameReferenceChangedEventArgs>(OnNameReferenceChanging), new EventHandler <NameReferenceChangedEventArgs>(OnNameReferenceChanged) ); controller.IsColectionEditing = true; } return(base.EditValue(context, provider, value));; } finally { if (isReferenceCollection) { controller.IsColectionEditing = false; controller.DoSnapshot(false, new EventHandler <NameReferenceChangedEventArgs>(OnNameReferenceChanging), new EventHandler <NameReferenceChangedEventArgs>(OnNameReferenceChanged) ); } } }