From 31823693ae0849f4828508ebf3f1f66188fe7e1f Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 1 Jan 2015 01:21:06 +0000 Subject: [PATCH] Cheats, Ram Watch - Fix bugs in column hide/show in new system --- .../Extensions/ControlExtensions.cs | 8 +++- .../tools/Cheats/Cheats.Designer.cs | 2 +- BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs | 43 +++++++++---------- .../tools/Watch/RamWatch.Designer.cs | 28 ++++++------ .../tools/Watch/RamWatch.cs | 43 +++++++++---------- 5 files changed, 64 insertions(+), 60 deletions(-) diff --git a/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index 42595b63b7..360bfb4e84 100644 --- a/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -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 { @@ -95,6 +95,7 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions menuItem.Click += (o, ev) => { dummyList[menuItem.Name].Visible ^= true; + changeCallback(); }; menu.DropDownItems.Add(menuItem); @@ -137,6 +138,11 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions return listView.SelectedIndices.Cast(); } + public static IEnumerable ColumnHeaders(this ListView listView) + { + return listView.Columns.OfType(); + } + #endregion } diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.Designer.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.Designer.cs index 3b83c0b605..7dbcd81993 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.Designer.cs @@ -493,7 +493,7 @@ this.RestoreWindowSizeMenuItem.Name = "RestoreWindowSizeMenuItem"; this.RestoreWindowSizeMenuItem.Size = new System.Drawing.Size(199, 22); 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 // diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index a12dfe717d..70389d5ea6 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -181,7 +181,13 @@ namespace BizHawk.Client.EmuHawk CheatEditor.SetEditEvent(EditCheat); UpdateDialog(); - CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu()); + CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback)); + } + + private void ColumnToggleCallback() + { + SaveColumnInfo(); + LoadColumnInfo(); } private void ToggleGameGenieButton() @@ -235,28 +241,14 @@ namespace BizHawk.Client.EmuHawk { 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); } - - 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() @@ -621,17 +613,24 @@ namespace BizHawk.Client.EmuHawk RefreshFloatingWindowControl(); } - private void RestoreWindowSizeMenuItem_Click(object sender, EventArgs e) + private void RestoreDefaultsMenuItem_Click(object sender, EventArgs e) { Size = new Size(_defaultWidth, _defaultHeight); Settings = new CheatsSettings(); + CheatsMenu.Items.Remove( + CheatsMenu.Items + .OfType() + .First(x => x.Name == "GeneratedColumnsSubMenu") + ); + + CheatsMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback)); + Global.Config.DisableCheatsOnLoad = false; Global.Config.LoadCheatFileByGame = true; Global.Config.CheatsAutoSaveOnClose = true; RefreshFloatingWindowControl(); - ColumnPositions(); LoadColumnInfo(); } diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.Designer.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.Designer.cs index 91bda36d88..9feed94202 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.Designer.cs @@ -65,7 +65,7 @@ this.moveDownToolStripButton = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator(); this.pauseToolStripButton = new System.Windows.Forms.ToolStripButton(); - this.menuStrip1 = new MenuStripEx(); + this.RamWatchMenu = new MenuStripEx(); this.FileSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.NewListMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OpenMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -116,7 +116,7 @@ this.ListViewContextMenu.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout(); - this.menuStrip1.SuspendLayout(); + this.RamWatchMenu.SuspendLayout(); this.SuspendLayout(); // // WatchCountLabel @@ -467,16 +467,16 @@ // // menuStrip1 // - this.menuStrip1.ClickThrough = true; - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.RamWatchMenu.ClickThrough = true; + this.RamWatchMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.FileSubMenu, this.WatchesSubMenu, this.OptionsSubMenu}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(364, 24); - this.menuStrip1.TabIndex = 3; - this.menuStrip1.Text = "menuStrip1"; + this.RamWatchMenu.Location = new System.Drawing.Point(0, 0); + this.RamWatchMenu.Name = "menuStrip1"; + this.RamWatchMenu.Size = new System.Drawing.Size(364, 24); + this.RamWatchMenu.TabIndex = 3; + this.RamWatchMenu.Text = "menuStrip1"; // // FileSubMenu // @@ -809,7 +809,7 @@ this.RestoreWindowSizeMenuItem.Name = "RestoreWindowSizeMenuItem"; this.RestoreWindowSizeMenuItem.Size = new System.Drawing.Size(217, 22); 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 // @@ -902,7 +902,7 @@ this.Controls.Add(this.MemDomainLabel); this.Controls.Add(this.WatchCountLabel); this.Controls.Add(this.toolStrip1); - this.Controls.Add(this.menuStrip1); + this.Controls.Add(this.RamWatchMenu); this.Controls.Add(this.WatchListView); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "RamWatch"; @@ -918,8 +918,8 @@ this.statusStrip1.PerformLayout(); this.toolStrip1.ResumeLayout(false); this.toolStrip1.PerformLayout(); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); + this.RamWatchMenu.ResumeLayout(false); + this.RamWatchMenu.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -935,7 +935,7 @@ private System.Windows.Forms.ColumnHeader DiffColumn; private System.Windows.Forms.ColumnHeader DomainColumn; private System.Windows.Forms.ColumnHeader NotesColumn; - private MenuStripEx menuStrip1; + private MenuStripEx RamWatchMenu; private System.Windows.Forms.ToolStripMenuItem FileSubMenu; private System.Windows.Forms.ToolStripMenuItem NewListMenuItem; private System.Windows.Forms.ToolStripMenuItem OpenMenuItem; diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 1c8b633ea5..f63866fd33 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -336,22 +336,6 @@ namespace BizHawk.Client.EmuHawk 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() { var indexes = SelectedIndices.ToList(); @@ -440,12 +424,14 @@ namespace BizHawk.Client.EmuHawk { 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); } - - ColumnPositions(); } private void LoadConfigSettings() @@ -943,15 +929,22 @@ namespace BizHawk.Client.EmuHawk RefreshFloatingWindowControl(); } - private void RestoreWindowSizeMenuItem_Click(object sender, EventArgs e) + private void RestoreDefaultsMenuItem_Click(object sender, EventArgs e) { Settings = new RamWatchSettings(); Size = new Size(_defaultWidth, _defaultHeight); + RamWatchMenu.Items.Remove( + RamWatchMenu.Items + .OfType() + .First(x => x.Name == "GeneratedColumnsSubMenu") + ); + + RamWatchMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback)); + Global.Config.DisplayRamWatch = false; RefreshFloatingWindowControl(); - ColumnPositions(); LoadColumnInfo(); } @@ -964,10 +957,16 @@ namespace BizHawk.Client.EmuHawk TopMost = Settings.TopMost; _watches = new WatchList(_core, _core.MemoryDomains.MainMemory, _emu.SystemId); LoadConfigSettings(); - menuStrip1.Items.Add(Settings.Columns.GenerateColumnsMenu()); + RamWatchMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback)); UpdateStatusBar(); } + private void ColumnToggleCallback() + { + SaveColumnInfo(); + LoadColumnInfo(); + } + private void NewRamWatch_Activated(object sender, EventArgs e) { WatchListView.Refresh();