RamSearch - infinite undo/redo levels

This commit is contained in:
adelikat 2013-02-25 01:23:03 +00:00
parent 84bc032656
commit c316fba5ff
4 changed files with 159 additions and 76 deletions

View File

@ -255,6 +255,7 @@
</Compile>
<Compile Include="Global.cs" />
<Compile Include="HawkFile.cs" />
<Compile Include="HistoryCollection.cs" />
<Compile Include="Input\ControllerBinding.cs" />
<Compile Include="Input\GamePad.cs" Condition=" '$(OS)' == 'Windows_NT' " />
<Compile Include="Input\GamePad360.cs" />

View File

@ -788,6 +788,6 @@ namespace BizHawk.MultiClient
SwappableDisplaySurfaceSet nativeDisplaySurfaceSet = new SwappableDisplaySurfaceSet();
Thread displayThread;
//Thread displayThread;
}
}

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.MultiClient
{
public class HistoryCollection
{
public List<List<Watch>> History = new List<List<Watch>>();
private int curPos = 0; //1-based
public HistoryCollection(List<Watch> newState)
{
AddState(newState);
}
public bool CanUndo
{
get
{
return curPos > 1;
}
}
public bool CanRedo
{
get
{
return curPos < History.Count;
}
}
public void AddState(List<Watch> newState)
{
if (curPos < History.Count)
{
for (int i = curPos + 1; i <= History.Count; i++)
{
History.Remove(History[i - 1]);
}
}
History.Add(newState);
curPos = History.Count;
}
public List<Watch> Undo()
{
if (CanUndo)
{
curPos--;
return History[curPos - 1];
}
else
{
return null;
}
}
public List<Watch> Redo()
{
if (CanRedo)
{
curPos++;
return History[curPos - 1];
}
else
{
return null;
}
}
}
}

View File

@ -11,38 +11,37 @@ using System.Globalization;
namespace BizHawk.MultiClient
{
//TODO:
//Go To Address (Ctrl+G) feature
//Multiple undo levels (List<List<string>> UndoLists)
/// <summary>
/// A winform designed to search through ram values
/// </summary>
public partial class RamSearch : Form
{
string systemID = "NULL";
List<Watch> Searches = new List<Watch>();
List<Watch> undoList = new List<Watch>();
List<Watch> redoList = new List<Watch>();
//TODO:
//Go To Address (Ctrl+G) feature
//Multiple undo levels (List<List<string>> UndoLists)
private string systemID = "NULL";
private List<Watch> Searches = new List<Watch>();
private HistoryCollection SearchHistory;
private bool IsAWeededList = false; //For deciding whether the weeded list is relevant (0 size could mean all were removed in a legit preview
List<ToolStripMenuItem> domainMenuItems = new List<ToolStripMenuItem>();
MemoryDomain Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
private List<ToolStripMenuItem> domainMenuItems = new List<ToolStripMenuItem>();
private MemoryDomain Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
public enum SCompareTo { PREV, VALUE, ADDRESS, CHANGES };
public enum SOperator { LESS, GREATER, LESSEQUAL, GREATEREQUAL, EQUAL, NOTEQUAL, DIFFBY };
public enum SSigned { SIGNED, UNSIGNED, HEX };
//Reset window position item
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
int defaultAddressWidth;
int defaultValueWidth;
int defaultPrevWidth;
int defaultChangesWidth;
string currentFile = "";
string addressFormatStr = "{0:X4} ";
bool sortReverse;
string sortedCol;
private int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
private int defaultHeight;
private int defaultAddressWidth;
private int defaultValueWidth;
private int defaultPrevWidth;
private int defaultChangesWidth;
private string currentFile = "";
private string addressFormatStr = "{0:X4} ";
private bool sortReverse;
private string sortedCol;
public void SaveConfigSettings()
{
@ -98,11 +97,10 @@ namespace BizHawk.MultiClient
private void RamSearch_Load(object sender, EventArgs e)
{
ClearUndo();
ClearRedo();
LoadConfigSettings();
StartNewSearch();
SetMemoryDomainMenu();
SearchHistory = new HistoryCollection(Searches);
}
private void SetEndian()
@ -393,8 +391,6 @@ namespace BizHawk.MultiClient
private void StartNewSearch()
{
ClearUndo();
ClearRedo();
IsAWeededList = false;
Searches.Clear();
SetPlatformAndMemoryDomainLabel();
@ -454,6 +450,8 @@ namespace BizHawk.MultiClient
sortReverse = false;
sortedCol = "";
DisplaySearchList();
SearchHistory = new HistoryCollection(Searches);
UpdateUndoRedoToolItems();
}
private void DisplaySearchList()
@ -521,7 +519,6 @@ namespace BizHawk.MultiClient
ListView.SelectedIndexCollection indexes = SearchListView.SelectedIndices;
if (indexes.Count > 0)
{
SaveUndo();
MessageLabel.Text = MakeAddressString(indexes.Count) + " removed";
for (int x = 0; x < indexes.Count; x++)
{
@ -529,6 +526,9 @@ namespace BizHawk.MultiClient
}
indexes.Clear();
DisplaySearchList();
SearchHistory.AddState(Searches);
UpdateUndoRedoToolItems();
}
}
@ -537,54 +537,35 @@ namespace BizHawk.MultiClient
RemoveAddresses();
}
/// <summary>
/// Saves the current search list to the undo list
/// This function should be called before any destructive operation to the list!
/// </summary>
private void SaveUndo()
private void UpdateUndoRedoToolItems()
{
undoList.Clear();
undoList.AddRange(Searches);
UndotoolStripButton.Enabled = true;
UndotoolStripButton.Enabled = SearchHistory.CanUndo;
RedotoolStripButton2.Enabled = SearchHistory.CanRedo;
}
private void DoUndo()
{
if (undoList.Count > 0)
if (SearchHistory.CanUndo)
{
MessageLabel.Text = MakeAddressString(undoList.Count - Searches.Count) + " restored";
redoList = new List<Watch>(Searches);
Searches = new List<Watch>(undoList);
ClearUndo();
RedotoolStripButton2.Enabled = true;
int oldVal = Searches.Count;
Searches = SearchHistory.Undo();
int newVal = Searches.Count;
MessageLabel.Text = MakeAddressString(newVal - oldVal) + " restored";
UpdateUndoRedoToolItems();
DisplaySearchList();
}
}
private void ClearUndo()
{
undoList.Clear();
UndotoolStripButton.Enabled = false;
}
private void ClearRedo()
{
redoList.Clear();
RedotoolStripButton2.Enabled = false;
}
private void DoRedo()
{
if (redoList.Count > 0)
if (SearchHistory.CanRedo)
{
MessageLabel.Text = MakeAddressString(Searches.Count - redoList.Count) + " removed";
undoList = new List<Watch>(Searches);
Searches = new List<Watch>(redoList);
ClearRedo();
UndotoolStripButton.Enabled = true;
int oldVal = Searches.Count;
Searches = SearchHistory.Redo();
int newVal = Searches.Count;
MessageLabel.Text = MakeAddressString(newVal - oldVal) + " removed";
UpdateUndoRedoToolItems();
DisplaySearchList();
//OutputLabel.Text = "Redo: s" + searchList.Count.ToString() + " u" +
// undoList.Count.ToString() + " r" + redoList.Count.ToString();
}
}
@ -689,13 +670,15 @@ namespace BizHawk.MultiClient
private void ClearChangeCounts()
{
SaveUndo();
for (int x = 0; x < Searches.Count; x++)
{
Searches[x].Changecount = 0;
}
DisplaySearchList();
MessageLabel.Text = "Change counts cleared";
SearchHistory.AddState(Searches);
UpdateUndoRedoToolItems();
}
private void ClearChangeCountstoolStripButton_Click(object sender, EventArgs e)
@ -725,11 +708,12 @@ namespace BizHawk.MultiClient
{
if (GenerateWeedOutList())
{
SaveUndo();
MessageLabel.Text = MakeAddressString(Searches.Where(x => x.Deleted == true).Count()) + " removed";
TrimWeededList();
UpdateLastSearch();
DisplaySearchList();
SearchHistory.AddState(Searches);
UpdateUndoRedoToolItems();
}
else
{
@ -1524,11 +1508,18 @@ namespace BizHawk.MultiClient
private void ConvertListsDataType(Watch.DISPTYPE s)
{
for (int x = 0; x < Searches.Count; x++)
{
Searches[x].Signed = s;
for (int x = 0; x < undoList.Count; x++)
undoList[x].Signed = s;
for (int x = 0; x < redoList.Count; x++)
redoList[x].Signed = s;
}
foreach (List<Watch> state in SearchHistory.History)
{
foreach (Watch watch in state)
{
watch.Signed = s;
}
}
SetSpecificValueBoxMaxLength();
sortReverse = false;
sortedCol = "";
@ -1538,8 +1529,13 @@ namespace BizHawk.MultiClient
private void ConvertListsDataSize(Watch.TYPE s, bool bigendian)
{
ConvertDataSize(s, bigendian, ref Searches);
ConvertDataSize(s, bigendian, ref undoList);
ConvertDataSize(s, bigendian, ref redoList);
//TODO
//for (int i = 0; i < SearchHistory.History.Count; i++)
//{
// ConvertDataSize(s, bigendian, ref SearchHistory.History[i]);
//}
SetSpecificValueBoxMaxLength();
sortReverse = false;
sortedCol = "";
@ -1959,19 +1955,31 @@ namespace BizHawk.MultiClient
private void searchToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
if (Searches.Count == 0)
{
searchToolStripMenuItem.Enabled = false;
}
else
{
searchToolStripMenuItem.Enabled = true;
}
if (undoList.Count == 0)
undoToolStripMenuItem.Enabled = false;
else
if (SearchHistory.CanUndo)
{
undoToolStripMenuItem.Enabled = true;
if (redoList.Count == 0)
redoToolStripMenuItem.Enabled = false;
}
else
{
undoToolStripMenuItem.Enabled = false;
}
if (SearchHistory.CanRedo)
{
redoToolStripMenuItem.Enabled = true;
}
else
{
redoToolStripMenuItem.Enabled = false;
}
ListView.SelectedIndexCollection indexes = SearchListView.SelectedIndices;
@ -2133,12 +2141,12 @@ namespace BizHawk.MultiClient
private void DoTruncate()
{
SaveUndo();
MessageLabel.Text = MakeAddressString(Searches.Where(x => x.Deleted == true).Count()) + " removed";
TrimWeededList();
UpdateLastSearch();
DisplaySearchList();
SearchHistory.AddState(Searches);
UpdateUndoRedoToolItems();
}
private void TruncateFromFile()