/// <summary> /// Resets the property value on all selected objects.</summary> public virtual void ResetValue() { m_transactionContext.DoTransaction(delegate { PropertyUtils.ResetProperty(SelectedObjects, m_descriptor); }, string.Format("Reset: {0}".Localize(), m_descriptor.DisplayName)); }
/// <summary> /// Resets the property value on all selected objects.</summary> public virtual void ResetValue() { m_transactionContext.DoTransaction(delegate { PropertyUtils.ResetProperty(SelectedObjects, m_descriptor); }, "Reset Property".Localize()); }
/// <summary> /// Returns property descriptors for the object</summary> /// <param name="owner">Object with properties</param> /// <returns>Array of property descriptors for the object</returns> public virtual PropertyDescriptor[] GetPropertyDescriptors(object owner) { if (m_innerContext != null) { return(m_innerContext.GetPropertyDescriptors(owner)); } return(PropertyUtils.GetDefaultProperties2(owner)); }
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()); }
private void SetTextBoxFromProperty() { if (m_context != null && m_context.LastSelectedObject != null) { string propertyText = PropertyUtils.GetPropertyText(m_context.LastSelectedObject, m_descriptor); m_initialText = propertyText; m_textBox.Text = propertyText; m_textBox.Font = Font; m_textBox.ReadOnly = m_descriptor.IsReadOnly; m_textBox.ForeColor = (m_descriptor.IsReadOnly) ? SystemColors.GrayText : ForeColor; } }
private static bool[] GetEqualComponents(Array refArray, Array newArray) { bool[] result = new bool[newArray.Length]; if (refArray != null) { for (int i = 0; i < newArray.Length; i++) { result[i] = PropertyUtils.AreEqual(newArray.GetValue(i), refArray.GetValue(i)); } } return(result); }
/// <summary> /// Draws the property editing representation, in the same way that the control /// presents the property in the GUI. Use this method to draw inactive properties /// when multitasking a single PropertyEditingControl.</summary> /// <param name="descriptor">Property descriptor</param> /// <param name="context">Type descriptor context</param> /// <param name="bounds">Bounds containing graphics</param> /// <param name="font">Font to use for rendering property text</param> /// <param name="brush">Brush for rendering property text</param> /// <param name="g">Graphics object</param> public static void DrawProperty( PropertyDescriptor descriptor, ITypeDescriptorContext context, Rectangle bounds, Font font, Brush brush, Graphics g) { object owner = context.Instance; if (owner == null) { return; } UITypeEditor editor = WinFormsPropertyUtils.GetUITypeEditor(descriptor, context); if (editor != null) { if (editor.GetPaintValueSupported(context)) { object value = descriptor.GetValue(owner); Rectangle paintRect = new Rectangle( bounds.Left + 1, bounds.Top + 1, PaintRectWidth, PaintRectHeight); editor.PaintValue(new PaintValueEventArgs(context, value, g, paintRect)); bounds.X += PaintRectTextOffset; bounds.Width -= PaintRectTextOffset; g.DrawRectangle(SystemPens.ControlDark, paintRect); } } string valueString = PropertyUtils.GetPropertyText(owner, descriptor); bounds.Height = font.Height; if (s_textFormat.CustomFlags == CustomStringFormatFlags.TrimLeftWithEllipses) { valueString = TrimStringLeftWithEllipses(valueString, bounds, font, g); } g.DrawString(valueString, font, brush, bounds, s_textFormat.Format); }
/// <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)); }
/// <summary> /// Sets the property value to the new value</summary> /// <param name="owner">Object whose property is set</param> /// <param name="descriptor">Property descriptor</param> /// <param name="value">New property value</param> public static void SetProperty(object owner, PropertyDescriptor descriptor, object value) { try { TypeConverter converter = descriptor.Converter; if (converter != null && value != null && converter.CanConvertFrom(value.GetType())) { value = converter.ConvertFrom(value); } bool notifyChange = false; object oldValue = null; EventHandler <PropertyEditedEventArgs> handler = PropertyEdited; if (handler != null) { oldValue = descriptor.GetValue(owner); notifyChange = !PropertyUtils.AreEqual(oldValue, value); } descriptor.SetValue(owner, value); if (notifyChange) { PropertyEditedEventArgs eventArgs = new PropertyEditedEventArgs(owner, descriptor, oldValue, value); handler(null, eventArgs); } } catch (InvalidTransactionException) { // The transaction needs to be cancelled. throw; } catch (Exception ex) { PropertyErrorEventArgs eventArgs = new PropertyErrorEventArgs(owner, descriptor, ex); PropertyError.Raise(null, eventArgs); if (!eventArgs.Cancel) { Outputs.WriteLine(OutputMessageType.Error, ex.Message); } } }
/// <summary> /// Returns whether or not the given values are equal</summary> /// <param name="value1">First value</param> /// <param name="value2">Second value</param> /// <returns>True iff the given values are equal</returns> /// <remarks>Default is to do limited deep equality testing for array types, and /// allow small errors with floating point types. Override to customize this behavior.</remarks> public virtual bool AreEqual(object value1, object value2) { return(PropertyUtils.AreEqual(value1, value2)); }
/// <summary> /// Gets property text for this property, possibly using a TypeConverter</summary> /// <returns>Property text for this property</returns> public string GetPropertyText() { string text = PropertyUtils.GetPropertyText(LastSelectedObject, m_descriptor); return(text); }
/// <summary> /// Gets the property descriptors for the given item in the collection</summary> /// <param name="item">The item in the collection</param> /// <returns>Property descriptor array for the given item in the collection</returns> protected virtual PropertyDescriptor[] GetDescriptors(object item) { return(PropertyUtils.GetDefaultProperties2(item)); }