/** * Places the provided SnapShot on top * of the stack. * * parameter snapShot: The one to put on top of the stack */ public static void PushToStack(SnapShot snapShot) { if (snapShot != null) { redoStack.Push(snapShot); } }
/** * A newer TextStorage is loaded using a memento object. */ public void Redo() { SnapShot backup = RedoStack.PopFromStack(); if (backup != null) { textStorage.RestoreStorage(backup.text); } }
/** * 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); } }
/** * Places the provided SnapShot on top * of the stack. * * parameter snapShot: The one to put on top of the stack */ public static void PushToStack(SnapShot snapShot) { undoStack.Push(snapShot); }
/** * Makes a backup by creating a snapshot * of the provided TextStorage. * * parameter storage: The TextStorage object to create a backup of */ public void MakeBackup(TextStorage storage) { backup = storage.CreateSnapshot(); UndoStack.PushToStack(backup); }