From 81b0707e4f26d14c8c3cd4ce15148ead0fff8dfd Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 25 Oct 2013 15:13:36 +0000 Subject: [PATCH] Refactored WatchHistory to use a generic type, and renamed to UndoHistory, can be used for any list of objects now --- .../tools/Watch/RamSearchEngine.cs | 6 +++--- .../Watch/{WatchHistory.cs => UndoHistory.cs} | 21 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) rename BizHawk.MultiClient/tools/Watch/{WatchHistory.cs => UndoHistory.cs} (61%) diff --git a/BizHawk.MultiClient/tools/Watch/RamSearchEngine.cs b/BizHawk.MultiClient/tools/Watch/RamSearchEngine.cs index 1b5b9a4898..2a7deec794 100644 --- a/BizHawk.MultiClient/tools/Watch/RamSearchEngine.cs +++ b/BizHawk.MultiClient/tools/Watch/RamSearchEngine.cs @@ -59,7 +59,7 @@ namespace BizHawk.MultiClient private List _watchList = new List(); private Settings _settings = new Settings(); - private WatchHistory _history = new WatchHistory(true); + private UndoHistory _history = new UndoHistory(true); private bool _keepHistory = true; public RamSearchEngine(Settings settings) @@ -497,7 +497,7 @@ namespace BizHawk.MultiClient { if (_keepHistory) { - _watchList = _history.Undo(); + _watchList = _history.Undo().ToList(); } } @@ -505,7 +505,7 @@ namespace BizHawk.MultiClient { if (_keepHistory) { - _watchList = _history.Redo(); + _watchList = _history.Redo().ToList(); } } diff --git a/BizHawk.MultiClient/tools/Watch/WatchHistory.cs b/BizHawk.MultiClient/tools/Watch/UndoHistory.cs similarity index 61% rename from BizHawk.MultiClient/tools/Watch/WatchHistory.cs rename to BizHawk.MultiClient/tools/Watch/UndoHistory.cs index 83b64d9740..23b41a8b64 100644 --- a/BizHawk.MultiClient/tools/Watch/WatchHistory.cs +++ b/BizHawk.MultiClient/tools/Watch/UndoHistory.cs @@ -1,20 +1,21 @@ using System.Collections.Generic; using System.Linq; -namespace BizHawk.MultiClient +namespace BizHawk.Client.Common { - public class WatchHistory + public class UndoHistory { - private List> _history = new List>(); + private List> _history = new List>(); private int curPos; //1-based + public bool Enabled { get; private set; } - public WatchHistory(bool enabled) + public UndoHistory(bool enabled) { Enabled = enabled; } - public WatchHistory(List newState, bool enabled) + public UndoHistory(IEnumerable newState, bool enabled) { AddState(newState); Enabled = enabled; @@ -22,7 +23,7 @@ namespace BizHawk.MultiClient public void Clear() { - _history = new List>(); + _history = new List>(); curPos = 0; } @@ -41,7 +42,7 @@ namespace BizHawk.MultiClient get { return Enabled && _history.Any(); } } - public void AddState(List newState) + public void AddState(IEnumerable newState) { if (Enabled) { @@ -53,12 +54,12 @@ namespace BizHawk.MultiClient } } - _history.Add(newState); + _history.Add(newState.ToList()); curPos = _history.Count; } } - public List Undo() + public IEnumerable Undo() { if (CanUndo && Enabled) { @@ -71,7 +72,7 @@ namespace BizHawk.MultiClient } } - public List Redo() + public IEnumerable Redo() { if (CanRedo && Enabled) {