From 36a0580dca1cfb64749c4735529e9a0758e2cd41 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Sun, 22 May 2011 20:19:28 +0000 Subject: [PATCH] Fix a bunch of crash issues with Ram Watch & Cheats related to having no list item selected. Implement Drag & drop for .cht & .wch files on Main form --- BizHawk.MultiClient/MainForm.cs | 12 ++++++++ BizHawk.MultiClient/tools/Cheats.Designer.cs | 1 + BizHawk.MultiClient/tools/Cheats.cs | 29 ++++++++++++++++--- .../tools/LuaConsole.Designer.cs | 10 ++++--- BizHawk.MultiClient/tools/LuaConsole.cs | 10 +++++++ BizHawk.MultiClient/tools/RamWatch.cs | 8 +++-- 6 files changed, 59 insertions(+), 11 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 131767518a..d5af363922 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -541,6 +541,18 @@ namespace BizHawk.MultiClient } else if (Path.GetExtension(filePaths[0]).ToUpper() == ".STATE") LoadStateFile(filePaths[0], Path.GetFileName(filePaths[0])); + else if (Path.GetExtension(filePaths[0]).ToUpper() == ".CHT") + { + LoadCheatsWindow(); + Cheats1.LoadCheatFile(filePaths[0], false); + Cheats1.DisplayCheatsList(); + } + else if (Path.GetExtension(filePaths[0]).ToUpper() == ".WCH") + { + LoadRamWatch(); + RamWatch1.LoadWatchFile(filePaths[0], false); + RamWatch1.DisplayWatchList(); + } else LoadRom(filePaths[0]); } diff --git a/BizHawk.MultiClient/tools/Cheats.Designer.cs b/BizHawk.MultiClient/tools/Cheats.Designer.cs index 40278374e1..7942a78889 100644 --- a/BizHawk.MultiClient/tools/Cheats.Designer.cs +++ b/BizHawk.MultiClient/tools/Cheats.Designer.cs @@ -227,6 +227,7 @@ this.cheatsToolStripMenuItem.Name = "cheatsToolStripMenuItem"; this.cheatsToolStripMenuItem.Size = new System.Drawing.Size(53, 20); this.cheatsToolStripMenuItem.Text = "&Cheats"; + this.cheatsToolStripMenuItem.DropDownOpened += new System.EventHandler(this.cheatsToolStripMenuItem_DropDownOpened); // // addCheatToolStripMenuItem // diff --git a/BizHawk.MultiClient/tools/Cheats.cs b/BizHawk.MultiClient/tools/Cheats.cs index 6350fb3b57..e76b774228 100644 --- a/BizHawk.MultiClient/tools/Cheats.cs +++ b/BizHawk.MultiClient/tools/Cheats.cs @@ -282,7 +282,7 @@ namespace BizHawk.MultiClient } } - private void DisplayCheatsList() + public void DisplayCheatsList() { UpdateNumberOfCheats(); CheatListView.ItemCount = cheatList.Count; @@ -292,7 +292,7 @@ namespace BizHawk.MultiClient { ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices; Cheat temp = new Cheat(); - if (indexes[0] == 0) return; + if (indexes.Count == 0) return; foreach (int index in indexes) { temp = cheatList[index]; @@ -319,7 +319,7 @@ namespace BizHawk.MultiClient { ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices; Cheat temp = new Cheat(); - + if (indexes.Count == 0) return; foreach (int index in indexes) { temp = cheatList[index]; @@ -576,7 +576,7 @@ namespace BizHawk.MultiClient return Global.Emulator.MemoryDomains[0]; } - bool LoadCheatFile(string path, bool append) + public bool LoadCheatFile(string path, bool append) { int y; var file = new FileInfo(path); @@ -715,6 +715,7 @@ namespace BizHawk.MultiClient private void RemoveCheat() { + if (cheatList.Count == 0) return; Changes(); ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices; if (indexes.Count > 0) @@ -1102,5 +1103,25 @@ namespace BizHawk.MultiClient DisplayCheatsList(); } } + + private void cheatsToolStripMenuItem_DropDownOpened(object sender, EventArgs e) + { + + ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices; + if (indexes.Count > 0) + { + moveDownToolStripMenuItem.Enabled = false; + moveUpToolStripMenuItem.Enabled = false; + removeCheatToolStripMenuItem.Enabled = false; + duplicateToolStripMenuItem.Enabled = false; + } + else + { + moveDownToolStripMenuItem.Enabled = true; + moveUpToolStripMenuItem.Enabled = true; + removeCheatToolStripMenuItem.Enabled = true; + duplicateToolStripMenuItem.Enabled = true; + } + } } } diff --git a/BizHawk.MultiClient/tools/LuaConsole.Designer.cs b/BizHawk.MultiClient/tools/LuaConsole.Designer.cs index 23d1e88c11..de90619e7c 100644 --- a/BizHawk.MultiClient/tools/LuaConsole.Designer.cs +++ b/BizHawk.MultiClient/tools/LuaConsole.Designer.cs @@ -246,25 +246,27 @@ // removeToolStripMenuItem // this.removeToolStripMenuItem.Name = "removeToolStripMenuItem"; - this.removeToolStripMenuItem.Size = new System.Drawing.Size(141, 22); + this.removeToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.removeToolStripMenuItem.Text = "Remove"; // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(138, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(149, 6); // // moveUpToolStripMenuItem // this.moveUpToolStripMenuItem.Name = "moveUpToolStripMenuItem"; - this.moveUpToolStripMenuItem.Size = new System.Drawing.Size(141, 22); + this.moveUpToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.moveUpToolStripMenuItem.Text = "Move Up"; + this.moveUpToolStripMenuItem.Click += new System.EventHandler(this.moveUpToolStripMenuItem_Click); // // moveDownToolStripMenuItem // this.moveDownToolStripMenuItem.Name = "moveDownToolStripMenuItem"; - this.moveDownToolStripMenuItem.Size = new System.Drawing.Size(141, 22); + this.moveDownToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.moveDownToolStripMenuItem.Text = "Move Down"; + this.moveDownToolStripMenuItem.Click += new System.EventHandler(this.moveDownToolStripMenuItem_Click); // // optionsToolStripMenuItem // diff --git a/BizHawk.MultiClient/tools/LuaConsole.cs b/BizHawk.MultiClient/tools/LuaConsole.cs index fdedfab684..8c0c704430 100644 --- a/BizHawk.MultiClient/tools/LuaConsole.cs +++ b/BizHawk.MultiClient/tools/LuaConsole.cs @@ -217,5 +217,15 @@ namespace BizHawk.MultiClient { } + + private void moveUpToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + + private void moveDownToolStripMenuItem_Click(object sender, EventArgs e) + { + + } } } diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs index 5bdcfc819b..f1f6e2cb62 100644 --- a/BizHawk.MultiClient/tools/RamWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatch.cs @@ -354,7 +354,7 @@ namespace BizHawk.MultiClient return 0; } - bool LoadWatchFile(string path, bool append) + public bool LoadWatchFile(string path, bool append) { int y, z; var file = new FileInfo(path); @@ -516,9 +516,11 @@ namespace BizHawk.MultiClient void MoveUp() { + if (WatchListView.SelectedIndices.Count == 0) + return; ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices; Watch temp = new Watch(); - if (indexes[0] == 0) return; + if (indexes.Count == 0) return; foreach (int index in indexes) { temp = watchList[index]; @@ -545,7 +547,7 @@ namespace BizHawk.MultiClient { ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices; Watch temp = new Watch(); - + if (indexes.Count == 0) return; foreach (int index in indexes) { temp = watchList[index];