Cheats, Ram Watch - Fix bugs in column hide/show in new system

This commit is contained in:
adelikat 2015-01-01 01:21:06 +00:00
parent 6440c9c44b
commit 31823693ae
5 changed files with 64 additions and 60 deletions

View File

@ -74,7 +74,7 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions
} }
} }
public static ToolStripMenuItem GenerateColumnsMenu(this ToolDialogSettings.ColumnList list) public static ToolStripMenuItem GenerateColumnsMenu(this ToolDialogSettings.ColumnList list, Action changeCallback)
{ {
var menu = new ToolStripMenuItem var menu = new ToolStripMenuItem
{ {
@ -95,6 +95,7 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions
menuItem.Click += (o, ev) => menuItem.Click += (o, ev) =>
{ {
dummyList[menuItem.Name].Visible ^= true; dummyList[menuItem.Name].Visible ^= true;
changeCallback();
}; };
menu.DropDownItems.Add(menuItem); menu.DropDownItems.Add(menuItem);
@ -137,6 +138,11 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions
return listView.SelectedIndices.Cast<int>(); return listView.SelectedIndices.Cast<int>();
} }
public static IEnumerable<ColumnHeader> ColumnHeaders(this ListView listView)
{
return listView.Columns.OfType<ColumnHeader>();
}
#endregion #endregion
} }

View File

@ -493,7 +493,7 @@
this.RestoreWindowSizeMenuItem.Name = "RestoreWindowSizeMenuItem"; this.RestoreWindowSizeMenuItem.Name = "RestoreWindowSizeMenuItem";
this.RestoreWindowSizeMenuItem.Size = new System.Drawing.Size(199, 22); this.RestoreWindowSizeMenuItem.Size = new System.Drawing.Size(199, 22);
this.RestoreWindowSizeMenuItem.Text = "Restore Default Settings"; this.RestoreWindowSizeMenuItem.Text = "Restore Default Settings";
this.RestoreWindowSizeMenuItem.Click += new System.EventHandler(this.RestoreWindowSizeMenuItem_Click); this.RestoreWindowSizeMenuItem.Click += new System.EventHandler(this.RestoreDefaultsMenuItem_Click);
// //
// toolStrip1 // toolStrip1
// //

View File

@ -181,7 +181,13 @@ namespace BizHawk.Client.EmuHawk
CheatEditor.SetEditEvent(EditCheat); CheatEditor.SetEditEvent(EditCheat);
UpdateDialog(); UpdateDialog();
CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu()); CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback));
}
private void ColumnToggleCallback()
{
SaveColumnInfo();
LoadColumnInfo();
} }
private void ToggleGameGenieButton() private void ToggleGameGenieButton()
@ -235,28 +241,14 @@ namespace BizHawk.Client.EmuHawk
{ {
CheatListView.Columns.Clear(); CheatListView.Columns.Clear();
foreach (var column in Settings.Columns) var columns = Settings.Columns
.Where(c => c.Visible)
.OrderBy(c => c.Index);
foreach (var column in columns)
{ {
CheatListView.AddColumn(column); CheatListView.AddColumn(column);
} }
ColumnPositions();
}
private void ColumnPositions()
{
foreach (ColumnHeader column in CheatListView.Columns)
{
var index = Settings.Columns[column.Name].Index;
if (index < CheatListView.Columns.Count)
{
column.DisplayIndex = Settings.Columns[column.Name].Index;
}
else
{
column.DisplayIndex = CheatListView.Columns.Count - 1;
}
}
} }
private void SaveColumnInfo() private void SaveColumnInfo()
@ -621,17 +613,24 @@ namespace BizHawk.Client.EmuHawk
RefreshFloatingWindowControl(); RefreshFloatingWindowControl();
} }
private void RestoreWindowSizeMenuItem_Click(object sender, EventArgs e) private void RestoreDefaultsMenuItem_Click(object sender, EventArgs e)
{ {
Size = new Size(_defaultWidth, _defaultHeight); Size = new Size(_defaultWidth, _defaultHeight);
Settings = new CheatsSettings(); Settings = new CheatsSettings();
CheatsMenu.Items.Remove(
CheatsMenu.Items
.OfType<ToolStripMenuItem>()
.First(x => x.Name == "GeneratedColumnsSubMenu")
);
CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback));
Global.Config.DisableCheatsOnLoad = false; Global.Config.DisableCheatsOnLoad = false;
Global.Config.LoadCheatFileByGame = true; Global.Config.LoadCheatFileByGame = true;
Global.Config.CheatsAutoSaveOnClose = true; Global.Config.CheatsAutoSaveOnClose = true;
RefreshFloatingWindowControl(); RefreshFloatingWindowControl();
ColumnPositions();
LoadColumnInfo(); LoadColumnInfo();
} }

View File

@ -65,7 +65,7 @@
this.moveDownToolStripButton = new System.Windows.Forms.ToolStripButton(); this.moveDownToolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.pauseToolStripButton = new System.Windows.Forms.ToolStripButton(); this.pauseToolStripButton = new System.Windows.Forms.ToolStripButton();
this.menuStrip1 = new MenuStripEx(); this.RamWatchMenu = new MenuStripEx();
this.FileSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.FileSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.NewListMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.NewListMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.OpenMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OpenMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -116,7 +116,7 @@
this.ListViewContextMenu.SuspendLayout(); this.ListViewContextMenu.SuspendLayout();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout(); this.RamWatchMenu.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// WatchCountLabel // WatchCountLabel
@ -467,16 +467,16 @@
// //
// menuStrip1 // menuStrip1
// //
this.menuStrip1.ClickThrough = true; this.RamWatchMenu.ClickThrough = true;
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.RamWatchMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.FileSubMenu, this.FileSubMenu,
this.WatchesSubMenu, this.WatchesSubMenu,
this.OptionsSubMenu}); this.OptionsSubMenu});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.RamWatchMenu.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.RamWatchMenu.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(364, 24); this.RamWatchMenu.Size = new System.Drawing.Size(364, 24);
this.menuStrip1.TabIndex = 3; this.RamWatchMenu.TabIndex = 3;
this.menuStrip1.Text = "menuStrip1"; this.RamWatchMenu.Text = "menuStrip1";
// //
// FileSubMenu // FileSubMenu
// //
@ -809,7 +809,7 @@
this.RestoreWindowSizeMenuItem.Name = "RestoreWindowSizeMenuItem"; this.RestoreWindowSizeMenuItem.Name = "RestoreWindowSizeMenuItem";
this.RestoreWindowSizeMenuItem.Size = new System.Drawing.Size(217, 22); this.RestoreWindowSizeMenuItem.Size = new System.Drawing.Size(217, 22);
this.RestoreWindowSizeMenuItem.Text = "Restore Default Settings"; this.RestoreWindowSizeMenuItem.Text = "Restore Default Settings";
this.RestoreWindowSizeMenuItem.Click += new System.EventHandler(this.RestoreWindowSizeMenuItem_Click); this.RestoreWindowSizeMenuItem.Click += new System.EventHandler(this.RestoreDefaultsMenuItem_Click);
// //
// WatchListView // WatchListView
// //
@ -902,7 +902,7 @@
this.Controls.Add(this.MemDomainLabel); this.Controls.Add(this.MemDomainLabel);
this.Controls.Add(this.WatchCountLabel); this.Controls.Add(this.WatchCountLabel);
this.Controls.Add(this.toolStrip1); this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.menuStrip1); this.Controls.Add(this.RamWatchMenu);
this.Controls.Add(this.WatchListView); this.Controls.Add(this.WatchListView);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "RamWatch"; this.Name = "RamWatch";
@ -918,8 +918,8 @@
this.statusStrip1.PerformLayout(); this.statusStrip1.PerformLayout();
this.toolStrip1.ResumeLayout(false); this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout(); this.toolStrip1.PerformLayout();
this.menuStrip1.ResumeLayout(false); this.RamWatchMenu.ResumeLayout(false);
this.menuStrip1.PerformLayout(); this.RamWatchMenu.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -935,7 +935,7 @@
private System.Windows.Forms.ColumnHeader DiffColumn; private System.Windows.Forms.ColumnHeader DiffColumn;
private System.Windows.Forms.ColumnHeader DomainColumn; private System.Windows.Forms.ColumnHeader DomainColumn;
private System.Windows.Forms.ColumnHeader NotesColumn; private System.Windows.Forms.ColumnHeader NotesColumn;
private MenuStripEx menuStrip1; private MenuStripEx RamWatchMenu;
private System.Windows.Forms.ToolStripMenuItem FileSubMenu; private System.Windows.Forms.ToolStripMenuItem FileSubMenu;
private System.Windows.Forms.ToolStripMenuItem NewListMenuItem; private System.Windows.Forms.ToolStripMenuItem NewListMenuItem;
private System.Windows.Forms.ToolStripMenuItem OpenMenuItem; private System.Windows.Forms.ToolStripMenuItem OpenMenuItem;

View File

@ -336,22 +336,6 @@ namespace BizHawk.Client.EmuHawk
UpdateStatusBar(); UpdateStatusBar();
} }
private void ColumnPositions()
{
foreach (ColumnHeader column in WatchListView.Columns)
{
var index = Settings.Columns[column.Name].Index;
if (index < WatchListView.Columns.Count)
{
column.DisplayIndex = Settings.Columns[column.Name].Index;
}
else
{
column.DisplayIndex = WatchListView.Columns.Count - 1;
}
}
}
private void CopyWatchesToClipBoard() private void CopyWatchesToClipBoard()
{ {
var indexes = SelectedIndices.ToList(); var indexes = SelectedIndices.ToList();
@ -440,12 +424,14 @@ namespace BizHawk.Client.EmuHawk
{ {
WatchListView.Columns.Clear(); WatchListView.Columns.Clear();
foreach (var column in Settings.Columns) var columns = Settings.Columns
.Where(c => c.Visible)
.OrderBy(c => c.Index);
foreach (var column in columns)
{ {
WatchListView.AddColumn(column); WatchListView.AddColumn(column);
} }
ColumnPositions();
} }
private void LoadConfigSettings() private void LoadConfigSettings()
@ -943,15 +929,22 @@ namespace BizHawk.Client.EmuHawk
RefreshFloatingWindowControl(); RefreshFloatingWindowControl();
} }
private void RestoreWindowSizeMenuItem_Click(object sender, EventArgs e) private void RestoreDefaultsMenuItem_Click(object sender, EventArgs e)
{ {
Settings = new RamWatchSettings(); Settings = new RamWatchSettings();
Size = new Size(_defaultWidth, _defaultHeight); Size = new Size(_defaultWidth, _defaultHeight);
RamWatchMenu.Items.Remove(
RamWatchMenu.Items
.OfType<ToolStripMenuItem>()
.First(x => x.Name == "GeneratedColumnsSubMenu")
);
RamWatchMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback));
Global.Config.DisplayRamWatch = false; Global.Config.DisplayRamWatch = false;
RefreshFloatingWindowControl(); RefreshFloatingWindowControl();
ColumnPositions();
LoadColumnInfo(); LoadColumnInfo();
} }
@ -964,10 +957,16 @@ namespace BizHawk.Client.EmuHawk
TopMost = Settings.TopMost; TopMost = Settings.TopMost;
_watches = new WatchList(_core, _core.MemoryDomains.MainMemory, _emu.SystemId); _watches = new WatchList(_core, _core.MemoryDomains.MainMemory, _emu.SystemId);
LoadConfigSettings(); LoadConfigSettings();
menuStrip1.Items.Add(Settings.Columns.GenerateColumnsMenu()); RamWatchMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback));
UpdateStatusBar(); UpdateStatusBar();
} }
private void ColumnToggleCallback()
{
SaveColumnInfo();
LoadColumnInfo();
}
private void NewRamWatch_Activated(object sender, EventArgs e) private void NewRamWatch_Activated(object sender, EventArgs e)
{ {
WatchListView.Refresh(); WatchListView.Refresh();