/** * A newer TextStorage is loaded using a memento object. */ public void Redo() { SnapShot backup = RedoStack.PopFromStack(); if (backup != null) { textStorage.RestoreStorage(backup.text); } }
/** * If there exists a backup, it will be used to obtain * newer text written by the user. */ public void Redo() { if (!RedoStack.IsEmpty()) { if (backup != null) { backup.Redo(); } } else { Console.WriteLine("There is nothing to redo...\n"); } }
/** * An older TextStorage is loaded using a memento object. * Allows Redo functionality by saving this SnapShot * to another stack. * Makes sure that text is empty if a backup doesn't exist. */ public void Undo() { if (UndoStack.PeekAtStack() != null) { RedoStack.PushToStack(UndoStack.PeekAtStack()); } SnapShot backup = UndoStack.PopFromStack(); if (backup == null) { textStorage.RestoreStorage(""); } else { textStorage.RestoreStorage(backup.text); } }