Exemplo n.º 1
0
        protected void SetDeleted(T item)
        {
            item.ValueChanged -= item_ValueChanged;
            if (!IsInitialized || !Editable)
            {
                return;
            }
            EditedObject <T> editedObj = new EditedObject <T>()
            {
                DataObject = item,
                OldState   = item.DataState,
                NewState   = DataState.Deleted,
            };

            if (item.DataState == DataState.Created)
            {
                added.Remove(item);
            }
            else
            {
                if (item.DataState == DataState.Modified)
                {
                    modified.Remove(item);
                }
                deleted.Add(item);
                item.MarkDeleted();
            }
            AddTrack(editedObj);
            OnListChanged(new ListChangedEventArgs <T>(ListChangedType.ItemDeleted, editedObj));
        }
Exemplo n.º 2
0
 protected void AddTrack(EditedObject <T> editTrack)
 {
     if (editLevel < track.Count)
     {
         track.RemoveRange(editLevel, track.Count - editLevel);
     }
     track.Add(editTrack);
     editLevel++;
 }
Exemplo n.º 3
0
        EditedObject <T> Undo(bool suppressEvent)
        {
            isInitialized = false;
            EditedObject <T> editTrack = track[--editLevel];

            switch (editTrack.NewState)
            {
            case DataState.Modified:
                editTrack.DataObject.GetType().GetProperty(editTrack.PropertyName).SetValue(editTrack.DataObject, editTrack.OldValue, null);
                if (editTrack.OldState == DataState.None)
                {
                    editTrack.DataObject.ResetState();
                    modified.Remove(editTrack.DataObject);
                }
                editTrack.DataObject.OnPropertyChanged(editTrack.PropertyName);
                editTrack.DataObject.OnValueChanged(editTrack.PropertyName, editTrack.OldValue, editTrack.NewValue);
                break;

            case DataState.Deleted:
                switch (editTrack.OldState)
                {
                case DataState.None:
                    editTrack.DataObject.ResetState();
                    deleted.Remove(editTrack.DataObject);
                    break;

                case DataState.Created:
                    added.Add(editTrack.DataObject);
                    break;

                case DataState.Modified:
                    modified.Add(editTrack.DataObject);
                    editTrack.DataObject.MarkModified();
                    deleted.Remove(editTrack.DataObject);
                    break;
                }
                list.Add(editTrack.DataObject);
                editTrack.DataObject.ValueChanged += item_ValueChanged;
                break;

            case DataState.Created:
                added.Remove(editTrack.DataObject);
                list.Remove(editTrack.DataObject);
                editTrack.DataObject.ValueChanged -= item_ValueChanged;
                break;
            }
            isInitialized = true;
            if (!suppressEvent)
            {
                OnListChanged(new ListChangedEventArgs <T>(ListChangedType.ItemUndo, editTrack));
            }
            return(editTrack);
        }
Exemplo n.º 4
0
        protected void SetAdded(T item)
        {
            item.ValueChanged += item_ValueChanged;
            if (!IsInitialized || !Editable)
            {
                return;
            }
            EditedObject <T> editedObj = new EditedObject <T>()
            {
                DataObject = item,
                OldState   = item.DataState,
                NewState   = DataState.Created
            };

            added.Add(item);
            item.MarkCreated();
            AddTrack(editedObj);
            OnListChanged(new ListChangedEventArgs <T>(ListChangedType.ItemAdded, editedObj));
        }
Exemplo n.º 5
0
        protected void SetModified(T obj, string propertyName, object oldValue, object newValue)
        {
            if (!IsInitialized || !Editable)
            {
                return;
            }
            EditedObject <T> editedObj = new EditedObject <T>()
            {
                DataObject   = obj,
                OldState     = obj.DataState,
                NewState     = DataState.Modified,
                OldValue     = oldValue,
                NewValue     = newValue,
                PropertyName = propertyName
            };

            if (obj.DataState == DataState.None)
            {
                modified.Add(obj);
                obj.MarkModified();
            }
            AddTrack(editedObj);
            OnListChanged(new ListChangedEventArgs <T>(ListChangedType.ItemModified, editedObj));
        }
Exemplo n.º 6
0
 public ListChangedEventArgs(ListChangedType type, EditedObject <T> obj)
 {
     EditedObject    = obj;
     ListChangedType = type;
 }