private void OpenDropDownEditor() { if (m_isEditing) { return; } try { m_isEditing = true; object oldValue, value; var oldContext = m_context; // Alan Beckus: save references to all the required objects to perform the transaction. // Because EditValue(...) enters modal loop using Application.DonEvent() // consequently selectedObjects, transaction and event m_context itself can change // before returning from EditValue(...). // note: previous attempt to solve this issue was to cache selected objects inside // m_context but it failed to solve the issue because the cache was cleared // by PropertyView before it can be used. List <object> selection = new List <object>(m_context.SelectedObjects); var transactionContext = m_context.TransactionContext; var descriptor = m_context.Descriptor; oldValue = m_context.GetValue(); UITypeEditor editor = WinFormsPropertyUtils.GetUITypeEditor(m_descriptor, this); // Bring up the editor which can cause Bind() to be called, so make sure that we use the // correct context and selection after this EditValue call. value = editor.EditValue(this, this, oldValue); transactionContext.DoTransaction(delegate { foreach (object selectedObject in selection) { PropertyUtils.SetProperty(selectedObject, descriptor, value); } }, string.Format("Edit: {0}".Localize(), descriptor.DisplayName)); // notify that we just changed a value NotifyPropertyEdit(oldValue, value); // Refresh text box, paint rect if (oldContext == m_context) { SetTextBoxFromProperty(); EnableTextBox(); } Invalidate(); } finally { m_isEditing = false; } }
/// <summary> /// Sets the property value on all selected objects</summary> /// <param name="newValue">New property value</param> public virtual void SetValue(object newValue) { m_transactionContext.DoTransaction(delegate { foreach (object selectedObject in SelectedObjects) { PropertyUtils.SetProperty(selectedObject, m_descriptor, newValue); } }, string.Format("Edit: {0}".Localize(), m_descriptor.DisplayName)); }
/// <summary> /// Sets the property value on all selected objects</summary> /// <param name="newValue">New property value</param> public virtual void SetValue(object newValue) { m_transactionContext.DoTransaction(delegate { foreach (object selectedObject in SelectedObjects) { PropertyUtils.SetProperty(selectedObject, m_descriptor, newValue); } }, "Edit Property".Localize()); }
/// <summary> /// Sets the Array property value on all selected objects</summary> /// <param name="refArray">Reference array that the user sees as the old value</param> /// <param name="newArray">New array that the user edited</param> public void SetValue(Array refArray, Array newArray) { bool[] equalComponents = GetEqualComponents(refArray, newArray); m_transactionContext.DoTransaction(delegate { foreach (object selectedObject in SelectedObjects) { Array oldArray = (Array)m_descriptor.GetValue(selectedObject); Array mergedArray = GetMergedArray(selectedObject, oldArray, newArray, equalComponents); //if (!PropertyUtils.AreEqual(oldArray, mergedArray)) TODO make command combining more sophisticated { PropertyUtils.SetProperty(selectedObject, m_descriptor, mergedArray); } } }, string.Format("Edit: {0}".Localize(), m_descriptor.DisplayName)); }