/// <summary> /// Handler called every time a discrete value is changed in the controller. /// </summary> /// <param name="operation">Details of the operation performed.</param> private protected virtual void OnDiscreteValueChanged(WriteableChangeDiscreteValueOperation operation) { IWriteableNodeState State = operation.State; Debug.Assert(State != null); Debug.Assert(StateViewTable.ContainsKey(State)); }
private protected virtual void UndoChangeDiscreteValue(IWriteableOperation operation) { WriteableChangeDiscreteValueOperation ChangeDiscreteValueOperation = (WriteableChangeDiscreteValueOperation)operation; ChangeDiscreteValueOperation = ChangeDiscreteValueOperation.ToInverseChange(); ExecuteChangeDiscreteValue(ChangeDiscreteValueOperation); }
/// <summary> /// Changes the value of an enum or boolean. /// If the value exceeds allowed values, it is rounded to fit. /// </summary> /// <param name="nodeIndex">Index of the state with the enum to change.</param> /// <param name="propertyName">Name of the property to change.</param> /// <param name="value">The new value.</param> public virtual void ChangeDiscreteValue(IWriteableIndex nodeIndex, string propertyName, int value) { Contract.RequireNotNull(nodeIndex, out IWriteableIndex NodeIndex); Debug.Assert(StateTable.ContainsKey(NodeIndex)); Debug.Assert(value >= 0); System.Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoChangeDiscreteValue(operation); System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeDiscreteValue(operation); IWriteableNodeState State = (IWriteableNodeState)StateTable[NodeIndex]; WriteableChangeDiscreteValueOperation Operation = CreateChangeDiscreteValueOperation(State.Node, propertyName, value, HandlerRedo, HandlerUndo, isNested: false); Operation.Redo(); SetLastOperation(Operation); CheckInvariant(); }
private protected virtual void ExecuteChangeDiscreteValue(WriteableChangeDiscreteValueOperation operation) { Node ParentNode = operation.ParentNode; string PropertyName = operation.PropertyName; int NewValue = operation.NewValue; IWriteableNodeState State = (IWriteableNodeState)GetState(ParentNode); Debug.Assert(State != null); Debug.Assert(State.ValuePropertyTypeTable.ContainsKey(PropertyName)); Debug.Assert(State.ValuePropertyTypeTable[PropertyName] == Constants.ValuePropertyType.Boolean || State.ValuePropertyTypeTable[PropertyName] == Constants.ValuePropertyType.Enum); int OldValue = NodeTreeHelper.GetEnumValue(State.Node, PropertyName); NodeTreeHelper.GetEnumRange(Type.FromGetType(State.Node), PropertyName, out int Min, out int Max); Debug.Assert(NewValue >= Min && NewValue <= Max); NodeTreeHelper.SetEnumValue(State.Node, PropertyName, NewValue); operation.Update(State, OldValue); NotifyDiscreteValueChanged(operation); }
private protected virtual void NotifyDiscreteValueChanged(WriteableChangeDiscreteValueOperation operation) { DiscreteValueChangedHandler?.Invoke(operation); }
private protected virtual void RedoChangeDiscreteValue(IWriteableOperation operation) { WriteableChangeDiscreteValueOperation ChangeDiscreteValueOperation = (WriteableChangeDiscreteValueOperation)operation; ExecuteChangeDiscreteValue(ChangeDiscreteValueOperation); }