public UndoRedoChange ApplyChange(ObjectWrapperUndoRedoChange first)
        {
            updating = true;

            try
            {
                ObjectWrapperUndoRedoChange change   = first;
                ObjectWrapperUndoRedoChange lastRedo = null;
                while (change != null)
                {
                    ObjectWrapperUndoRedoChange redo = ApplyDiff(change.TargetObject, change.Diff);
                    if (redo != null)
                    {
                        redo.Next = lastRedo;
                        lastRedo  = redo;
                    }
                    change = change.Next;
                }
                return(lastRedo);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
            finally
            {
                updating = false;
            }
        }
        ObjectWrapperUndoRedoChange ApplyDiff(string id, object diff)
        {
//			Console.WriteLine ("** APPLYING DIFF: uid:" + id);
//			PrintPatch (diff);

            ObjectWrapper ww = rootObject.FindObjectByUndoId(id);

            if (ww == null)
            {
                Console.WriteLine("Object with undo id '{0}' not found", id);
                return(null);
            }

            object reverseDiff = ww.ApplyUndoRedoDiff(diff);

            if (reverseDiff != null)
            {
//				Console.WriteLine ("** REVERSE DIFF:");
//				PrintPatch (reverseDiff);

                ObjectWrapperUndoRedoChange change = new ObjectWrapperUndoRedoChange(this, id, reverseDiff);
                return(change);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
 public void RestoreState(object sessionData)
 {
     object[] status = (object[])sessionData;
     gproject.LoadStatus(status [0]);
     undoQueue = (UndoQueue)status [1];
     foreach (UndoRedoChange ch in undoQueue.Changes)
     {
         ObjectWrapperUndoRedoChange och = ch as ObjectWrapperUndoRedoChange;
         if (och != null)
         {
             och.Manager = undoManager;
         }
     }
     undoManager.UndoQueue = undoQueue;
 }
        void AddChange(ObjectWrapper[] obs)
        {
            if (updating || queue == null)
            {
                return;
            }

            ObjectWrapperUndoRedoChange firstChange = null;
            ObjectWrapperUndoRedoChange lastChange  = null;

//			Console.WriteLine ("** UNDO CHECKPOINT: {0} objects", obs.Length);

            foreach (ObjectWrapper ob in obs)
            {
                // Get the diff for going from the new status to the old status
                object diff = GetDiff(ob);

                if (diff == null) // No differences
                {
                    continue;
                }

//				Console.WriteLine ("ADDCHANGE " + ob + " uid:" + ob.UndoId);
//				PrintPatch (diff);

                if (ob.UndoId == null || ob.UndoId.Length == 0)
                {
                    throw new InvalidOperationException("Object of type '" + ob.GetType() + "' does not have an undo id.");
                }

                ObjectWrapperUndoRedoChange change = new ObjectWrapperUndoRedoChange(this, ob.UndoId, diff);
                if (lastChange == null)
                {
                    lastChange = firstChange = change;
                }
                else
                {
                    lastChange.Next = change;
                    lastChange      = change;
                }
            }
            if (firstChange != null)
            {
                queue.AddChange(firstChange);
            }
        }
Example #5
0
		ObjectWrapperUndoRedoChange ApplyDiff (string id, object diff)
		{
//			Console.WriteLine ("** APPLYING DIFF: uid:" + id);
//			PrintPatch (diff);
			
			ObjectWrapper ww = rootObject.FindObjectByUndoId (id);
			if (ww == null) {
				Console.WriteLine ("Object with undo id '{0}' not found", id);
				return null;
			}
			
			object reverseDiff = ww.ApplyUndoRedoDiff (diff);
		
			if (reverseDiff != null) {
//				Console.WriteLine ("** REVERSE DIFF:");
//				PrintPatch (reverseDiff);
				
				ObjectWrapperUndoRedoChange change = new ObjectWrapperUndoRedoChange (this, id, reverseDiff);
				return change;
			} else
				return null;
		}
Example #6
0
		public UndoRedoChange ApplyChange (ObjectWrapperUndoRedoChange first)
		{
			updating = true;
			
			try {
				ObjectWrapperUndoRedoChange change = first;
				ObjectWrapperUndoRedoChange lastRedo = null;
				while (change != null) {
					ObjectWrapperUndoRedoChange redo = ApplyDiff (change.TargetObject, change.Diff);
					if (redo != null) {
						redo.Next = lastRedo;
						lastRedo = redo;
					}
					change = change.Next;
				}
				return lastRedo;
			} catch (Exception ex) {
				Console.WriteLine (ex);
				return null;
			} finally {
				updating = false;
			}
		}
Example #7
0
		void AddChange (ObjectWrapper[] obs)
		{
			if (updating || queue == null)
				return;

			ObjectWrapperUndoRedoChange firstChange = null;
			ObjectWrapperUndoRedoChange lastChange = null;
			
//			Console.WriteLine ("** UNDO CHECKPOINT: {0} objects", obs.Length);
			
			foreach (ObjectWrapper ob in obs) {
			
				// Get the diff for going from the new status to the old status
				object diff = GetDiff (ob);
				
				if (diff == null)	// No differences
					continue;
				
//				Console.WriteLine ("ADDCHANGE " + ob + " uid:" + ob.UndoId);
//				PrintPatch (diff);
				
				if (ob.UndoId == null || ob.UndoId.Length == 0)
					throw new InvalidOperationException ("Object of type '" + ob.GetType () + "' does not have an undo id.");

				ObjectWrapperUndoRedoChange change = new ObjectWrapperUndoRedoChange (this, ob.UndoId, diff);
				if (lastChange == null)
					lastChange = firstChange = change;
				else {
					lastChange.Next = change;
					lastChange = change;
				}
			}
			if (firstChange != null)
				queue.AddChange (firstChange);
		}