Пример #1
0
        /// <summary>
        /// Sets the value of the component to a different value.
        /// </summary>
        /// <param name="component">
        /// The component with the property value that is to be set.
        /// </param>
        /// <param name="value">The new value.</param>
        public override void SetValue(object component, object value)
        {
            UndoRedoWrapper owner = component as UndoRedoWrapper;

            if (owner == null)
            {
                parent.SetValue(component, value);
            }
            else if (!owner.CanRun)
            {
                throw new InvalidOperationException();
            }
            else
            {
                MethodInfo undoRedoSetter = UndoRedoMethodInfo;

                if (undoRedoSetter != null)
                {
                    owner.UndoRedoManager.Run(new MethodAction(owner, this, value));
                }
                else
                {
                    IAction action = owner.CreateAction(this, value);

                    if (action != null)
                    {
                        owner.UndoRedoManager.Run(action);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Creates new instance of the T object.
        /// </summary>
        /// <returns>New T instance.</returns>
        protected virtual T OnCreateNew()
        {
            AddingNewEventHandler eventHandler = AddingNew;

            if (eventHandler == null)
            {
                if (default(T) == null)
                {
                    return(Activator.CreateInstance <T>());
                }
                else
                {
                    return(default(T));
                }
            }

            AddingNewEventArgs eventArgs = new AddingNewEventArgs();

            eventHandler(this, eventArgs);

            if (eventArgs.NewObject == null)
            {
                return(Activator.CreateInstance <T>());
            }

            UndoRedoWrapper wrapper = eventArgs.NewObject as UndoRedoWrapper;

            if (wrapper != null)
            {
                return((T)wrapper.Instance);
            }

            return((T)eventArgs.NewObject);
        }
Пример #3
0
        object IBindingList.AddNew()
        {
            UndoRedoWrapper item = CreateItem();

            this.Add(item);

            return(item);
        }
Пример #4
0
        /// <summary>
        /// Converts instance of UndoRedoWrapper into instance of T.
        /// </summary>
        /// <param name="t">Instance of UndoRedoWrapper type.</param>
        /// <returns>Instance of T type.</returns>
        protected override T Convert(UndoRedoWrapper t)
        {
            if (t == null)
            {
                return(default(T));
            }

            return(((UndoRedoItem)t).Instance);
        }
Пример #5
0
 /// <summary>
 /// Creates an instance of the ActionEventArgs.
 /// </summary>
 /// <param name="undoRedoManager">
 /// An instance of undo and redo manager that runs an action.
 /// </param>
 /// <param name="type">Action type.</param>
 /// <param name="instance">Instance, which is a subject of the action.</param>
 /// <param name="value">Optional action value.</param>
 public ActionEventArgs(
     UndoRedoManager undoRedoManager,
     ActionType type,
     UndoRedoWrapper instance,
     object value)
 {
     this.undoRedoManager = undoRedoManager;
     this.type            = type;
     this.instance        = instance;
     this.value           = value;
     this.result          = true;
 }
Пример #6
0
        /// <summary>
        /// Tests if two instances are equal.
        /// </summary>
        /// <param name="obj">Instance to compare with.</param>
        /// <returns>true if instances are equal, and false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            UndoRedoWrapper that = obj as UndoRedoWrapper;

            if (that == null)
            {
                return(false);
            }

            return(Instance.Equals(that.Instance));
        }
Пример #7
0
            /// <summary>
            /// Creates an instance of the Action.
            /// </summary>
            /// <param name="owner">Owner type.</param>
            /// <param name="property">Property to change.</param>
            /// <param name="value">Value of the property.</param>
            public Action(
                UndoRedoWrapper owner,
                UndoRedoProperty property,
                object value)
            {
                if (owner == null)
                {
                    throw new ArgumentNullException("owner");
                }

                if (property == null)
                {
                    throw new ArgumentNullException("property");
                }

                this.owner    = owner;
                this.property = property;
                this.value    = value;
            }
Пример #8
0
 public MethodAction(UndoRedoWrapper owner, UndoRedoProperty property, object value)
 {
     this.owner    = owner;
     this.property = property;
     this.value    = value;
 }
Пример #9
0
        /// <summary>
        /// Enables other objects to be notified when this property changes.
        /// </summary>
        /// <param name="component">The component to remove the handler for.</param>
        /// <param name="handler">The delegate to remove as a listener.</param>
        public override void RemoveValueChanged(object component, EventHandler handler)
        {
            UndoRedoWrapper owner = component as UndoRedoWrapper;

            parent.RemoveValueChanged(owner != null ? owner.Instance : component, handler);
        }
Пример #10
0
        /// <summary>
        /// Determines a value indicating whether the value of this property needs
        /// to be persisted.
        /// </summary>
        /// <param name="component">
        /// The component with the property to be examined for persistence.
        /// </param>
        /// <returns>true if the property should be persisted and false otherwise.</returns>
        public override bool ShouldSerializeValue(object component)
        {
            UndoRedoWrapper owner = component as UndoRedoWrapper;

            return(parent.ShouldSerializeValue(owner != null ? owner.Instance : component));
        }
Пример #11
0
        /// <summary>
        /// Gets the current value of the property on a component.
        /// </summary>
        /// <param name="component">
        /// The component with the property for which to retrieve the value.
        /// </param>
        /// <returns>The value of a property for a given component.</returns>
        public override object GetValue(object component)
        {
            UndoRedoWrapper owner = component as UndoRedoWrapper;

            return(parent.GetValue(owner != null ? owner.Instance : component));
        }