public override bool Add(IUndoableEdit other) { if (other == null) { return(false); } var compoundUndoableEdit = other as CompoundUndoableEdit; if (compoundUndoableEdit != null) { var co = compoundUndoableEdit; for (var index = 0; index < co.edits.Count; index++) { var edit = co.edits[index]; edits.Add(edit); AddNotify(edit); } } else { edits.Add(other); AddNotify(other); } return(true); }
public virtual void AddEdit(IUndoableEdit edit) { if (!this.IsComplete) { this.myEdits.Add(edit); } }
/** * If inProgress, inserts anEdit at indexOfNextAdd, and removes * any old edits that were at indexOfNextAdd or later. The die * method is called on each edit that is removed is sent, in the * reverse of the order the edits were added. Updates * indexOfNextAdd. * * <p>If not <code>inProgress</code>, acts as a * <code>CompoundEdit</code>. * * @param anEdit the edit to be added * @see CompoundEdit#end * @see CompoundEdit#addEdit */ public override bool AddEdit(IUndoableEdit anEdit) { bool retVal; // Trim from the indexOfNextAdd to the end, as we'll // never reach these edits once the new one is added. int sizeEdits = edits.Count; TrimEdits(indexOfNextAdd, sizeEdits - 1); if (anEdit is CompoundEdit) { ((CompoundEdit)anEdit).EndAllEdits(); } retVal = base.AddEdit(anEdit); if (inProgress) { retVal = true; } // Maybe super added this edit, maybe it didn't (perhaps // an in progress compound edit took it instead. Or perhaps // this LimitQueueEdit is no longer in progress). So make sure // the indexOfNextAdd is pointed at the right place. indexOfNextAdd = edits.Count; // Enforce the limit TrimForLimit(); return(retVal); }
/// <summary> /// Restore the state of some models to after the current <see cref="IUndoableEdit"/>. /// </summary> /// <remarks> /// This calls <see cref="IUndoableEdit.Redo"/> on the current <see cref="EditToRedo"/>. /// This will raise a <see cref="IDiagramModel.Changed"/> event with a hint of /// <see cref="ModelChange.StartingRedo"/> before actually performing the redo, and will raise a /// Changed event with a hint of <see cref="ModelChange.FinishedRedo"/> afterwards. /// The <see cref="ModelChangedEventArgs.Data"/> /// is the <see cref="UndoManager.CompoundEdit"/> that was the value of /// <see cref="EditToRedo"/> before calling Redo. /// </remarks> /// <seealso cref="CanRedo"/> public virtual void Redo() { if (!CanRedo()) { return; } IUndoableEdit edit = this.EditToRedo; try { foreach (IDiagramModel model in this.ModelsList) { RaiseChanged(model, ModelChange.StartingRedo, edit, null, null); } this.IsUndoingRedoing = true; this.UndoEditIndex++; edit.Redo(); } catch (Exception ex) { ModelHelper.Trace("Redo: " + ex.ToString()); throw; } finally { this.IsUndoingRedoing = false; foreach (IDiagramModel model in this.ModelsList) { RaiseChanged(model, ModelChange.FinishedRedo, edit, null, null); } } }
public virtual void AddEdit(IUndoableEdit edit) { if (!this.IsComplete) { this.myEdits.Add(edit); } }
public virtual void Undo() { if (this.CanUndo()) { try { this.myIsUndoing = true; IUndoableEdit edit1 = this.EditToUndo; this.myCurrentEditIndex--; edit1.Undo(); foreach (DiagramDocument document1 in this.Documents) { document1.InvalidateViews(); } } catch (Exception exception1) { Shapes.DiagramShape.Trace("Undo: " + exception1.ToString()); throw exception1; } finally { this.myIsUndoing = false; } } }
public virtual void Clear() { for (int num1 = this.myEdits.Count - 1; num1 >= 0; num1--) { IUndoableEdit edit1 = (IUndoableEdit)this.myEdits[num1]; edit1.Clear(); } this.myEdits.Clear(); }
protected override void AddNotify(IUndoableEdit edit) { if (edit is IElementEdit) { var elementEdit = (IElementEdit)edit; editsByNode[elementEdit.NewElement] = elementEdit; editsByNode[elementEdit.OldElement] = elementEdit; } }
protected void _postEdit(IUndoableEdit e) { UndoableEditEvent ev = new UndoableEditEvent(source, e); IUndoableEditListener[] l = GetUndoableEditListeners(); foreach (IUndoableEditListener el in l) { el.UndoableEditHappened(ev); } }
public virtual void Undo() { if (this.CanUndo()) { for (int num1 = this.myEdits.Count - 1; num1 >= 0; num1--) { IUndoableEdit edit1 = (IUndoableEdit)this.myEdits[num1]; edit1.Undo(); } } }
/** * Redoes all changes from indexOfNextAdd to edit. Updates indexOfNextAdd accordingly. */ protected void RedoTo(IUndoableEdit edit) { bool done = false; while (!done) { IUndoableEdit next = edits[indexOfNextAdd++]; next.Redo(); done = next == edit; } }
public virtual void Redo() { if (this.CanRedo()) { for (int num1 = 0; num1 <= (this.myEdits.Count - 1); num1++) { IUndoableEdit edit1 = (IUndoableEdit)this.myEdits[num1]; edit1.Redo(); } } }
/** * Overridden to preserve usual semantics: returns true if a redo * operation would be successful now, false otherwise */ public override bool CanRedo() { if (inProgress) { IUndoableEdit edit = EditToBeRedone(); return(edit != null && edit.CanRedo()); } else { return(base.CanRedo()); } }
// partial undo, to implement rollback for nested RollbackTransaction() calls internal /*?? public */ void RollbackTo(int start) { for (int i = this.Edits.Count - 1; i >= start; i--) { IUndoableEdit edit = this.Edits[i]; if (edit != null) { edit.Undo(); } this.Edits.RemoveAt(i); } }
protected void UndoTo(IUndoableEdit e) { while (true) { IUndoableEdit edit = edits[--index]; edit.Undo(); if (edit == e) { return; } } }
protected void RedoTo(IUndoableEdit e) { while (true) { IUndoableEdit edit = edits[index++]; edit.Redo(); if (edit == e) { return; } } }
/// <summary> /// Clear all of the <see cref="IUndoableEdit"/>s and forget all references to them. /// </summary> public void Clear() { for (int i = this.Edits.Count - 1; i >= 0; i--) { IUndoableEdit edit = this.Edits[i]; if (edit != null) { edit.Clear(); } } this.Edits.Clear(); }
public virtual void PostEdit(IUndoableEdit e) { lock (this) { if (updateLevel == 0) { _postEdit(e); } else { compoundEdit.AddEdit(e); } } }
public override string GetRedoPresentationName() { IUndoableEdit last = LastEdit(); if (last == null) { return(base.GetUndoPresentationName()); } else { return(last.GetUndoPresentationName()); } }
/// <summary> /// Redo all of the <see cref="IUndoableEdit"/>s, in forwards order. /// </summary> public void Redo() { if (CanRedo()) { for (int i = 0; i <= this.Edits.Count - 1; i++) { IUndoableEdit edit = this.Edits[i]; if (edit != null) { edit.Redo(); } } } }
/// <summary> /// Undo all of the <see cref="IUndoableEdit"/>s, in reverse order. /// </summary> public void Undo() { if (CanUndo()) { for (int i = this.Edits.Count - 1; i >= 0; i--) { IUndoableEdit edit = this.Edits[i]; if (edit != null) { edit.Undo(); } } } }
public virtual void Clear() { for (int num1 = this.myCompEdits.Count - 1; num1 >= 0; num1--) { IUndoableEdit edit1 = (IUndoableEdit)this.myCompEdits[num1]; edit1.Clear(); } this.myCompEdits.Clear(); this.myCurrentEditIndex = -1; this.myIncompleteEdit = null; this.myLevel = 0; this.myIsUndoing = false; this.myIsRedoing = false; }
public override bool CanRedo() { lock (this) { if (IsInProgress()) { IUndoableEdit e = EditToBeUndone(); return(e != null && e.CanRedo()); } else { return(base.CanRedo()); } } }
protected IUndoableEdit EditToBeUndone() { int count = edits.Count; for (int i = index; i < count; i++) { IUndoableEdit e = edits[i]; if (e.IsSignificant()) { return(e); } } return(null); }
/// <summary> /// This predicate is true when one can call <see cref="Redo"/>. /// </summary> /// <returns></returns> /// <remarks> /// In order to be able to perform a redo, a transaction must not /// be in progress, nor an undo or a redo. /// Furthermore there must be an <see cref="EditToRedo"/> that itself /// is ready to be redone, because its <see cref="IUndoableEdit.CanRedo"/> /// predicate is true. /// </remarks> /// <seealso cref="Redo"/> public virtual bool CanRedo() { if (this.TransactionLevel > 0) { return(false); } if (this.IsUndoingRedoing) { return(false); } IUndoableEdit curr = this.EditToRedo; return(curr != null && curr.CanRedo()); }
public override bool AddEdit(IUndoableEdit anEdit) { lock (this) { bool result; TrimEdits(index, edits.Count - 1); result = base.AddEdit(anEdit); if (IsInProgress()) { result = true; } index = edits.Count; TrimForLimit(); return(result); } }
/** * Returns the the next significant edit to be undone if undo is * called. May return null */ protected IUndoableEdit EditToBeUndone() { int i = indexOfNextAdd; while (i > 0) { IUndoableEdit edit = edits[--i]; if (edit.isSignificant()) { return(edit); } } return(null); }
/** * If this <code>LimitQueueEdit</code> is <code>inProgress</code>, * redoes the last significant <code>UndoableEdit</code> at * <code>indexOfNextAdd</code> or after, and all insignificant * edits up to it. Updates <code>indexOfNextAdd</code> accordingly. * * <p>If not <code>inProgress</code>, <code>indexOfNextAdd</code> * is ignored and super's routine is called.</p> * * @see CompoundEdit#end */ public override void Redo() { if (inProgress) { IUndoableEdit edit = EditToBeRedone(); if (edit == null) { throw new CannotRedoException(); } RedoTo(edit); } else { base.Redo(); } }
public void ApplyRiskLevelToChildrenTest() { effect1 = new Effect(structure); StateObjectManager rlm = new StateObjectManager(effect1); eq11.AddEffect(effect1); IUndoableEdit edit = rlm.ChangeState(State.FAULTY); Assert.AreEqual(State.FAULTY, eq11.CurrentState); Assert.IsFalse(dep.Combinations.Contains(combi1)); ((CompoundEdit)edit).EndAllEdits(); edit.Undo(); Assert.AreNotEqual(State.FAULTY, eq11.CurrentState); Assert.IsTrue(dep.Combinations.Contains(combi1)); edit.Redo(); }
public override void Undo() { lock (this) { if (IsInProgress()) { IUndoableEdit e = EditToBeUndone(); if (e == null) { throw new CannotUndoException(); } UndoTo(e); } else { base.Undo(); } } }
public virtual bool EndTransaction(bool commit, string pname) { if (this.myLevel > 0) { this.myLevel--; } UndoManagerCompoundEdit edit1 = this.CurrentEdit; if ((this.myLevel == 0) && (edit1 != null)) { if (commit) { edit1.IsComplete = true; if (edit1.AllEdits.Count > 0) { if (pname != null) { edit1.PresentationName = pname; } for (int num1 = this.myCompEdits.Count - 1; num1 > this.myCurrentEditIndex; num1--) { IUndoableEdit edit2 = (IUndoableEdit)this.myCompEdits[num1]; edit2.Clear(); this.myCompEdits.RemoveAt(num1); } if ((this.MaximumEditCount > 0) && (this.myCompEdits.Count >= this.MaximumEditCount)) { IUndoableEdit edit3 = (IUndoableEdit)this.myCompEdits[0]; edit3.Clear(); this.myCompEdits.RemoveAt(0); this.myCurrentEditIndex--; } this.myCompEdits.Add(edit1); this.myCurrentEditIndex++; } this.CurrentEdit = null; return(true); } edit1.Clear(); this.CurrentEdit = null; } return(false); }
/// <summary> /// Given an <see cref="IUndoableEdit"/> return an edited object /// that represents what was modified. /// </summary> /// <param name="edit"> /// an <see cref="IUndoableEdit"/>, /// usually either a <see cref="ModelChangedEventArgs"/> or a <see cref="CompoundEdit"/> /// </param> /// <returns> /// typically a <see cref="Node"/> or a <see cref="Link"/>, /// but this may be null if there is no such object, /// perhaps because a model property was modified, /// or because there were no real edits in the argument <paramref name="edit"/>. /// </returns> public virtual Object FindPrimaryObject(IUndoableEdit edit) { ModelChangedEventArgs ea = edit as ModelChangedEventArgs; if (ea != null) return ea.Data; CompoundEdit ce = edit as CompoundEdit; if (ce != null) { foreach (IUndoableEdit e in ce.Edits) { Object data = FindPrimaryObject(e); if (data != null) return data; } } return null; }