Table of Contents

Class EditableProperty<T>

Namespace
CADability.UserInterface
Assembly
CADability.dll

Defines a base class for editable properties shown on a property page (IPropertyPage) in the controlCenter (properties explorer). It is a single entry in the property page which may have subentries. Usually a property of type T of some object is connected with this EditableProperty, e.g. the startpoint of a line or the distance of hatch lines or some setting value. The communication with the object which hold the property is either done via delegates or via reflection. When the user clicks on the value part of the IPropertyEntry, an editBox is activated to edit the value of the property. There must be a ValueToText(T) and TextToValue(string, out T) method defined in the derived class, which convert the property value in a string and vice versa. The value of the property may be changed by the editBox (typing) or from the outside.

public abstract class EditableProperty<T> : PropertyEntryImpl, IPropertyEntry, IShowProperty, IConstructProperty

Type Parameters

T
Inheritance
EditableProperty<T>
Implements
Derived
Inherited Members

Constructors

EditableProperty(GetValueDelegate, SetValueDelegate, string, string)

Creates an editable property entry (for the control center), which communicates with the object (which holds the property) via delegates.

public EditableProperty(EditableProperty<T>.GetValueDelegate getValueDelegate, EditableProperty<T>.SetValueDelegate setValueDelegate, string resourceId = null, string contextMenuId = null)

Parameters

getValueDelegate EditableProperty<T>.GetValueDelegate

Get the value of the property from the object, which holds the property

setValueDelegate EditableProperty<T>.SetValueDelegate

Set the value of th eproperty

resourceId string

A resource id for the text of the label

contextMenuId string

Menu id (from the menu resource) of the context menu of this property, or null if there is no context menu

EditableProperty(object, string, string, string)

Creates an editable property entry (for the control center), which communicates with the object (which holds the property) via reflection. The object must have an accessible property with the provided getSetProperty name.

public EditableProperty(object objectWithProperty, string getSetProperty, string resourceId = null, string contextMenuId = null)

Parameters

objectWithProperty object

The object, which holds the property

getSetProperty string

The Name of the property

resourceId string

A resource id for the text of the label

contextMenuId string

Menu id (from the menu resource) of the context menu of this property, or null if there is no context menu

EditableProperty(string, string)

Creates an EditableProperty without specifying the communication with the object holding the property. This must be specified before using the object by setting OnGetValue and OnSetValue

public EditableProperty(string resourceId = null, string contextMenuId = null)

Parameters

resourceId string

A resource id for the text of the label

contextMenuId string

Menu id (from the menu resource) of the context menu of this property, or null if there is no context menu

Fields

LabelTextChanged

Callback invoked when the user has edited the label of the entry (see LabelIsEditable).

public EditableProperty<T>.LabelChangedDelegate LabelTextChanged

Field Value

EditableProperty<T>.LabelChangedDelegate

LockedChanged

Callback invoked when Locked changes, either by code or by the user clicking the lock button of the entry (see Lockable). The inputs of the construction actions use it to fix a value.

public EditableProperty<T>.LockedChangedDelegate LockedChanged

Field Value

EditableProperty<T>.LockedChangedDelegate

ModifyWithMouse

Callback invoked by StartModifyWithMouse() (with startModifying set to true) when the user wants to modify the value with the mouse, e.g. by clicking the mouse button of the entry or selecting its hotspot. The owner of the property typically starts an action which sets the value from the mouse position. null when the value cannot be modified with the mouse.

public ModifyWithMouseDelegate ModifyWithMouse

Field Value

ModifyWithMouseDelegate

hotspotPosition

The position of the hotspot of this property in the drawing area, if it has one (see SetHotspotPosition(GeoPoint)). Not all derived classes use it.

protected GeoPoint hotspotPosition

Field Value

GeoPoint

Properties

ContextMenu

Must be overridden, when Flags contains PropertyEntryType.ContextMenu. See ContextMenu

public override MenuWithHandler[] ContextMenu { get; }

Property Value

MenuWithHandler[]

ErrorMessage

The text of the error which occurred when the last entered text was converted or applied (returned by GetErrorText() and shown by the property page). Empty when the last value was accepted.

public string ErrorMessage { get; set; }

Property Value

string

Flags

Override for more functionality. Only returns PropertyEntryType.ValueEditable and PropertyEntryType.LabelEditable if apropriate

public override PropertyEntryType Flags { get; }

Property Value

PropertyEntryType

Highlight

true when the entry is displayed highlighted (Highlight), e.g. the input of a construction action which currently expects a value. Setting it refreshes the entry.

public bool Highlight { get; set; }

Property Value

bool

IsLocked

Implementation of IsLocked: by default the entry is never locked, and setting it throws a NotImplementedException. An entry with Lockable in its Flags overrides it (see EditableProperty<T>).

public override bool IsLocked { get; set; }

Property Value

bool

IsSelected

Whether this entry is the selected entry of its property page. Setting it to true selects the entry, setting it to false deselects it if it is currently selected. The entry must be displayed on a property page.

public bool IsSelected { get; set; }

Property Value

bool

LabelIsEditable

true when the user may also edit the label (the left side) of the entry. After the label has been edited, LabelChanged(string) is called, which invokes LabelTextChanged.

public bool LabelIsEditable { get; set; }

Property Value

bool

Lockable

true when the entry shows a lock button (Lockable) with which the user toggles Locked. The inputs of the construction actions use it to let the user fix a value.

public bool Lockable { get; set; }

Property Value

bool

Locked

true when the value is locked: the entry is not editable (ValueEditable is missing in Flags) and construction actions keep the value fixed. Changing it invokes LockedChanged.

public bool Locked { get; set; }

Property Value

bool

OnGetValue

Sets the delegate which provides the value of the property. It replaces the reflection access to the object given to the constructor, if any, and must be set (together with OnSetValue) when the property was created without a connected object.

public EditableProperty<T>.GetValueDelegate OnGetValue { set; }

Property Value

EditableProperty<T>.GetValueDelegate

OnSetValue

Sets the delegate which receives the new value whenever the user has entered one (or an action sets it). It replaces the reflection access to the object given to the constructor, if any.

public EditableProperty<T>.SetValueDelegate OnSetValue { set; }

Property Value

EditableProperty<T>.SetValueDelegate

PrependContextMenu

additional menu items for the context menu

public MenuWithHandler[] PrependContextMenu { set; }

Property Value

MenuWithHandler[]

ShowMouseButton

Whether the entry should offer a button to modify the value with the mouse. The value is only stored; the current property page implementations do not evaluate it.

public bool ShowMouseButton { get; set; }

Property Value

bool

UserData

A container for arbitrary data which the owner of the property may attach to it (e.g. an index identifying the entry in a list); the property itself does not use it. Created on first access.

public UserData UserData { get; }

Property Value

UserData

Value

Must be overridden, when Flags contains PropertyEntryType.ValueEditable

public override string Value { get; }

Property Value

string

Methods

Added(IPropertyPage)

Implementation of Added(IPropertyPage): memorizes the page in propertyPage and reports Added. Override it to subscribe to events while the entry is displayed, and call the base implementation.

public override void Added(IPropertyPage pp)

Parameters

pp IPropertyPage

the property page the entry was added to

ButtonClicked(PropertyEntryButton)

Must be overridden, when Flags contains PropertyEntryType.HasSpinButton or CancelButton or OKButton

public override void ButtonClicked(PropertyEntryButton button)

Parameters

button PropertyEntryButton

EditTextChanged(string)

May be overridden when Flags contains PropertyEntryType.ValueEditable. See EditTextChanged(string),

public override bool EditTextChanged(string newValue)

Parameters

newValue string

Returns

bool

EndEdit(bool, bool, string)

Must be overridden when Flags contains PropertyEntryType.ValueEditable. See EndEdit(bool, bool, string)

public override void EndEdit(bool aborted, bool modified, string newValue)

Parameters

aborted bool
modified bool
newValue string

FireModifyWithMouse(bool)

Forwards the start or the end of a mouse modification to the connected IGeoObject by calling ModifyWithMouse(object, string, bool) with the name of the connected property. Called by the general actions (e.g. GeneralLengthAction) which modify a value with the mouse. Does nothing when the connected object is not an IGeoObject.

public void FireModifyWithMouse(bool start)

Parameters

start bool

true when the modification starts, false when it ends

GetConnectedObject()

Returns the object whose property is edited: the object given to the constructor, or else the target object of the OnSetValue delegate.

public object GetConnectedObject()

Returns

object

The connected object, or null when there is none

GetConnectedPropertyName()

Returns the name of the edited property: the property name given to the constructor, or else the name of the method behind the OnSetValue delegate. It is passed to ModifyWithMouse(object, string, bool) to identify the property.

public string GetConnectedPropertyName()

Returns

string

The property name, or null when there is no connected object

GetContextMenuId()

Returns the id of the context menu in the menu resource, as given to the constructor or to SetContextMenu(string, ICommandHandler).

protected string GetContextMenuId()

Returns

string

The menu id, or null when there is no context menu

GetErrorText()

Implementation of GetErrorText(): returns an empty string. Override it together with EditTextChanged(string) to explain why a text was rejected.

public override string GetErrorText()

Returns

string

the error text, empty by default

GetHotspotPosition()

Returns the position of the hotspot of this property, as set by SetHotspotPosition(GeoPoint) (implements GetHotspotPosition()).

public GeoPoint GetHotspotPosition()

Returns

GeoPoint

The position in world coordinates

GetValue()

Tries to get the value of the property being handled from the object

protected T GetValue()

Returns

T

LabelChanged(string)

Called when the user has finished editing the label of the entry (see LabelIsEditable). Invokes LabelTextChanged; override it to react in a derived class.

protected virtual void LabelChanged(string newText)

Parameters

newText string

The text entered by the user

SetContextMenu(string, ICommandHandler)

Replaces the context menu of the entry: contextMenuId names a menu definition in the menu resource and contextMenuHandler executes its commands. Pass null as menu id to remove the context menu.

public void SetContextMenu(string contextMenuId, ICommandHandler contextMenuHandler)

Parameters

contextMenuId string

Id of the menu definition in the menu resource, or null

contextMenuHandler ICommandHandler

Handles the commands of that menu

SetFocus()

Selects this entry on its property page so that it receives the focus (implements SetFocus()). The entry must be displayed on a property page.

public void SetFocus()

SetHotspotPosition(GeoPoint)

Sets the position of the hotspot which represents this property in the drawing area (implements SetHotspotPosition(GeoPoint)). The owner of the property updates it when the object changes.

public void SetHotspotPosition(GeoPoint Here)

Parameters

Here GeoPoint

The position in world coordinates

SetValue(T, bool)

Called, when the editbox or some other mechanism has a new value for the property. Transfers this value to the object holding the property.

protected void SetValue(T val, bool notify)

Parameters

val T
notify bool

StartEdit(bool)

Only handles value editing. If the label may also be edited, override this method and call this base implementation;

public override void StartEdit(bool editValue)

Parameters

editValue bool

StartModifyWithMouse()

Starts the modification of the value with the mouse by invoking ModifyWithMouse with startModifying set to true (implements StartModifyWithMouse()). Called when the user clicks the mouse button of the entry or selects its hotspot.

public void StartModifyWithMouse()

TextToValue(string, out T)

Converts the text to a value. Returns true if possible, false otherwise (maybe invalid characters or outside the limit)

protected abstract bool TextToValue(string text, out T val)

Parameters

text string
val T

Returns

bool

ValueToText(T)

Returns the text representation of the value.

protected abstract string ValueToText(T val)

Parameters

val T

Returns

string