Пример #1
0
		/// <summary>
		/// Create a ChangeSet for the specified UndoRoot.
		/// </summary>
		/// <param name="undoRoot">The UndoRoot that this ChangeSet belongs to.</param>
		/// <param name="description">A description of the change.</param>
		/// <param name="change">The Change instance that can perform the undo / redo as needed.</param>
		public ChangeSet(UndoRoot undoRoot, string description, Change change) {
			_undoRoot = undoRoot;
			_changes = new List<Change>();
			_description = description;
			if (null != change)
				AddChange(change);
		}
Пример #2
0
		/// <summary>
		/// Add a change to this ChangeSet.
		/// </summary>
		/// <param name="change"></param>
		internal void AddChange(Change change) {
			if (_undoRoot.ConsolidateChangesForSameInstance) {
				//var dupes = _Changes.Where(c => null != c.ChangeKey && c.ChangeKey.Equals(change.ChangeKey)).ToList();
				//if (null != dupes && dupes.Count > 0)
				//    dupes.ForEach(c => _Changes.Remove(c));

				var dupe = _changes.FirstOrDefault(c => null != c.ChangeKey && c.ChangeKey.Equals(change.ChangeKey));
				if (null != dupe) {
					dupe.MergeWith(change);
					// System.Diagnostics.Debug.WriteLine("AddChange: MERGED");
				} else {
					_changes.Add(change);
				}
			} else {
				_changes.Add(change);
			}
		}
Пример #3
0
		/// <summary>
		/// When consolidating events, we want to keep the original (first) "Undo"
		/// but use the most recent Redo. This will pull the Redo from the 
		/// specified Change and apply it to this instance.
		/// </summary>
		public abstract void MergeWith(Change latestChange);
Пример #4
0
		/// <summary>
		/// When consolidating events, we want to keep the original "Undo"
		/// but use the most recent Redo. This will pull the Redo from the 
		/// specified Change and apply it to this instance.
		/// </summary>
		public override void MergeWith(Change latestChange) {
			var other = latestChange as DelegateChange;
			if (null != other)
				_redoAction = other._redoAction;
		}
Пример #5
0
		/// <summary>
		/// Add a change to the Undo history. The change will be added to the existing batch, if in a batch.
		/// Otherwise, a new ChangeSet will be created.
		/// </summary>
		/// <param name="change">The change to add to the history.</param>
		/// <param name="description">The description of this change.</param>
		public void AddChange(Change change, string description) {
			// System.Diagnostics.Debug.WriteLine("Starting AddChange: " + description);

			// We don't want to add additional changes representing the operations that happen when undoing or redoing a change.
			if (_isUndoingOrRedoing)
				return;

			//  If batched, add to the current ChangeSet, otherwise add a new ChangeSet.
			if (IsInBatch) {
				_currentBatchChangeSet.AddChange(change);
				//System.Diagnostics.Debug.WriteLine("AddChange: BATCHED " + description);
			} else {
				_undoStack.Push(new ChangeSet(this, description, change));
				OnUndoStackChanged();
				//System.Diagnostics.Debug.WriteLine("AddChange: " + description);
			}

			// Prune the RedoStack
			_redoStack.Clear();
			OnRedoStackChanged();
		}