123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SketchAssistantWPF
- {
- public class ActionHistory
- {
-
- List<SketchAction> actionHistory;
-
- Tuple<int, SketchAction> currentAction;
- public ActionHistory()
- {
- actionHistory = new List<SketchAction>();
- currentAction = new Tuple<int, SketchAction>(-1, null);
- AddNewAction(new SketchAction(SketchAction.ActionType.Start, -1));
- }
-
-
-
-
- public String Reset()
- {
- actionHistory.Clear();
- currentAction = new Tuple<int, SketchAction>(-1, null);
- return AddNewAction(new SketchAction(SketchAction.ActionType.Start, -1));
- }
-
-
-
-
-
- public String AddNewAction(SketchAction newAction)
- {
-
- if (currentAction.Item1 < actionHistory.Count - 1)
- {
- actionHistory.RemoveRange(currentAction.Item1 + 1, actionHistory.Count - (currentAction.Item1 + 1));
- }
- actionHistory.Add(newAction);
- currentAction = new Tuple<int, SketchAction>(actionHistory.Count - 1, newAction);
- return UpdateStatusLabel();
- }
-
-
-
-
-
- public String MoveAction(bool moveBack)
- {
- if (moveBack && CanUndo())
- {
- currentAction = new Tuple<int, SketchAction>(currentAction.Item1 - 1, actionHistory[currentAction.Item1 - 1]);
- }
- if (!moveBack && CanRedo())
- {
- currentAction = new Tuple<int, SketchAction>(currentAction.Item1 + 1, actionHistory[currentAction.Item1 + 1]);
- }
- return UpdateStatusLabel();
- }
-
-
-
-
- public SketchAction GetCurrentAction()
- {
- return currentAction.Item2;
- }
-
-
-
-
- public bool CanUndo()
- {
- if (currentAction.Item1 > 0) { return true; }
- else { return false; }
- }
-
-
-
-
- public bool CanRedo()
- {
- if (currentAction.Item1 < actionHistory.Count - 1) { return true; }
- else { return false; }
- }
-
-
-
-
- public bool IsEmpty()
- {
- if (actionHistory.Count == 1) { return true; }
- else { return false; }
- }
-
-
-
-
- private String UpdateStatusLabel()
- {
- return "Last Action: " + currentAction.Item2.GetActionInformation();
- }
- }
- }
|