Column sorting (and reverse sorting) for Ram Search & Ram Watch

This commit is contained in:
andres.delikat 2011-06-19 19:10:01 +00:00
parent fc48e0e4f7
commit 5e27953db0
6 changed files with 3618 additions and 3414 deletions

View File

@ -281,6 +281,7 @@
this.SearchListView.UseCompatibleStateImageBehavior = false;
this.SearchListView.View = System.Windows.Forms.View.Details;
this.SearchListView.VirtualMode = true;
this.SearchListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.SearchListView_ColumnClick);
this.SearchListView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.SearchListView_MouseDoubleClick);
this.SearchListView.QueryItemBkColor += new BizHawk.QueryItemBkColorHandler(this.SearchListView_QueryItemBkColor);
this.SearchListView.ColumnReordered += new System.Windows.Forms.ColumnReorderedEventHandler(this.SearchListView_ColumnReordered);

View File

@ -11,6 +11,9 @@ using System.Globalization;
namespace BizHawk.MultiClient
{
//TODO:
//Sorting by Prev only does "Since prev frame", find a way to integrate the various prev options
/// <summary>
/// A winform designed to search through ram values
/// </summary>
@ -38,6 +41,9 @@ namespace BizHawk.MultiClient
int defaultChangesWidth;
string currentSearchFile = "";
bool sortReverse;
string sortedCol;
public void SaveConfigSettings()
{
ColumnPositionSet();
@ -60,6 +66,8 @@ namespace BizHawk.MultiClient
public void UpdateValues()
{
sortReverse = false;
sortedCol = "";
if (!this.IsHandleCreated || this.IsDisposed) return;
for (int x = 0; x < searchList.Count; x++)
{
@ -401,6 +409,8 @@ namespace BizHawk.MultiClient
MakePreviousList();
SetSpecificValueBoxMaxLength();
OutputLabel.Text = "New search started";
sortReverse = false;
sortedCol = "";
DisplaySearchList();
}
@ -2026,5 +2036,21 @@ namespace BizHawk.MultiClient
DisplaySearchList();
}
}
private void OrderColumn(int columnToOrder)
{
string columnName = SearchListView.Columns[columnToOrder].Text;
if (sortedCol.CompareTo(columnName) != 0)
sortReverse = false;
searchList.Sort((x, y) => x.CompareTo(y, columnName) * (sortReverse ? -1 : 1));
sortedCol = columnName;
sortReverse = !(sortReverse);
SearchListView.Refresh();
}
private void SearchListView_ColumnClick(object sender, ColumnClickEventArgs e)
{
OrderColumn(e.Column);
}
}
}

View File

@ -361,28 +361,28 @@
this.showChangeCountsToolStripMenuItem.Checked = true;
this.showChangeCountsToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.showChangeCountsToolStripMenuItem.Name = "showChangeCountsToolStripMenuItem";
this.showChangeCountsToolStripMenuItem.Size = new System.Drawing.Size(206, 22);
this.showChangeCountsToolStripMenuItem.Size = new System.Drawing.Size(203, 22);
this.showChangeCountsToolStripMenuItem.Text = "Change Counts";
this.showChangeCountsToolStripMenuItem.Click += new System.EventHandler(this.showChangeCountsToolStripMenuItem_Click);
//
// showPreviousValueToolStripMenuItem
//
this.showPreviousValueToolStripMenuItem.Name = "showPreviousValueToolStripMenuItem";
this.showPreviousValueToolStripMenuItem.Size = new System.Drawing.Size(206, 22);
this.showPreviousValueToolStripMenuItem.Size = new System.Drawing.Size(203, 22);
this.showPreviousValueToolStripMenuItem.Text = "Previous Value";
this.showPreviousValueToolStripMenuItem.Click += new System.EventHandler(this.showPreviousValueToolStripMenuItem_Click);
//
// prevValueShowsChangeAmountToolStripMenuItem
//
this.prevValueShowsChangeAmountToolStripMenuItem.Name = "prevValueShowsChangeAmountToolStripMenuItem";
this.prevValueShowsChangeAmountToolStripMenuItem.Size = new System.Drawing.Size(206, 22);
this.prevValueShowsChangeAmountToolStripMenuItem.Size = new System.Drawing.Size(203, 22);
this.prevValueShowsChangeAmountToolStripMenuItem.Text = "Prev Value as change";
this.prevValueShowsChangeAmountToolStripMenuItem.Click += new System.EventHandler(this.prevValueShowsChangeAmountToolStripMenuItem_Click);
//
// toolStripSeparator7
//
this.toolStripSeparator7.Name = "toolStripSeparator7";
this.toolStripSeparator7.Size = new System.Drawing.Size(203, 6);
this.toolStripSeparator7.Size = new System.Drawing.Size(200, 6);
//
// restoreWindowSizeToolStripMenuItem
//
@ -416,6 +416,7 @@
this.WatchListView.TabIndex = 1;
this.WatchListView.UseCompatibleStateImageBehavior = false;
this.WatchListView.View = System.Windows.Forms.View.Details;
this.WatchListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.WatchListView_ColumnClick);
this.WatchListView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.WatchListView_MouseDoubleClick);
this.WatchListView.ColumnReordered += new System.Windows.Forms.ColumnReorderedEventHandler(this.ColumnReorder);
this.WatchListView.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.WatchListView_AfterLabelEdit);

View File

@ -17,8 +17,8 @@ namespace BizHawk.MultiClient
public partial class RamWatch : Form
{
//TODO:
//Restore window size should restore column order as well
//When receiving a watch from a different domain, should something be done?
//when sorting, "Prev as Change" option not taken into account
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
@ -35,6 +35,9 @@ namespace BizHawk.MultiClient
bool changes = false;
List<ToolStripMenuItem> domainMenuItems = new List<ToolStripMenuItem>();
string sortedCol;
bool sortReverse;
public void Restart()
{
if (!this.IsHandleCreated || this.IsDisposed) return;
@ -132,6 +135,8 @@ namespace BizHawk.MultiClient
WatchListView.QueryItemBkColor += new QueryItemBkColorHandler(WatchListView_QueryItemBkColor);
WatchListView.VirtualMode = true;
Closing += (o, e) => SaveConfigSettings();
sortReverse = false;
sortedCol = "";
}
protected override void OnClosing(CancelEventArgs e)
@ -312,6 +317,8 @@ namespace BizHawk.MultiClient
currentWatchFile = "";
changes = false;
MessageLabel.Text = "";
sortReverse = false;
sortedCol = "";
}
}
@ -1376,5 +1383,21 @@ namespace BizHawk.MultiClient
i++;
} while (columnHeaders.Count() > 0);
}
private void OrderColumn(int columnToOrder)
{
string columnName = WatchListView.Columns[columnToOrder].Text;
if (sortedCol.CompareTo(columnName) != 0)
sortReverse = false;
watchList.Sort((x, y) => x.CompareTo(y, columnName));//* (sortReverse ? -1 : 1));
//sortedCol = columnName;
//sortReverse = !(sortReverse);
WatchListView.Refresh();
}
private void WatchListView_ColumnClick(object sender, ColumnClickEventArgs e)
{
OrderColumn(e.Column);
}
}
}

View File

@ -230,5 +230,158 @@ namespace BizHawk.MultiClient
break;
}
}
private int CompareAddress(Watch Other)
{
if (this.address < Other.address)
return -1;
else if (this.address > Other.address)
return 1;
else
return 0;
}
private int CompareValue(Watch Other)
{
if (this.value < Other.value)
return -1;
else if (this.value > Other.value)
return 1;
else
return 0;
}
private int ComparePrev(Watch Other)
{
if (this.prev < Other.prev)
return -1;
else if (this.prev > Other.prev)
return 1;
else
return 0;
}
private int CompareChanges(Watch Other)
{
if (this.changecount < Other.changecount)
return -1;
else if (this.changecount > Other.changecount)
return 1;
else
return 0;
}
private int CompareNotes(Watch Other)
{
if (this.notes == null & Other.notes == null)
return 0;
else if (this.notes == null)
return -1;
else if (Other.notes == null)
return 1;
else
return this.notes.CompareTo(Other.notes);
}
public int CompareTo(Watch Other, string parameter)
{
int compare = 0;
if (parameter == "Address")
{
compare = CompareAddress(Other);
if (compare == 0)
{
compare = CompareValue(Other);
if (compare == 0)
{
compare = CompareChanges(Other);
if (compare == 0)
{
compare = ComparePrev(Other);
if (compare == 0)
compare = CompareNotes(Other);
}
}
}
}
else if (parameter == "Value")
{
compare = CompareValue(Other);
if (compare == 0)
{
compare = CompareAddress(Other);
if (compare == 0)
{
compare = CompareChanges(Other);
if (compare == 0)
{
compare = ComparePrev(Other);
if (compare == 0)
compare = CompareNotes(Other);
}
}
}
}
else if (parameter == "Prev")
{
compare = ComparePrev(Other);
if (compare == 0)
{
compare = CompareAddress(Other);
if (compare == 0)
{
compare = CompareValue(Other);
if (compare == 0)
{
compare = CompareChanges(Other);
if (compare == 0)
compare = CompareNotes(Other);
}
}
}
}
else if (parameter == "Changes")
{
compare = CompareChanges(Other);
if (compare == 0)
{
compare = CompareAddress(Other);
if (compare == 0)
{
compare = CompareValue(Other);
if (compare == 0)
{
compare = ComparePrev(Other);
if (compare == 0)
compare = CompareNotes(Other);
}
}
}
}
else if (parameter == "Notes")
{
compare = CompareNotes(Other);
if (compare == 0)
{
compare = CompareAddress(Other);
if (compare == 0)
{
compare = CompareValue(Other);
if (compare == 0)
{
compare = CompareChanges(Other);
if (compare == 0)
compare = ComparePrev(Other);
}
}
}
}
return compare;
}
}
}