From a51eba88da2295dd1e52019e2154d2abdca1ef3f Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 24 Jul 2020 13:17:03 -0500 Subject: [PATCH] move some repetitive logic from tools to the RollColumns class --- .../CustomControls/InputRoll/RollColumns.cs | 16 +++----- .../tools/Cheats/Cheats.cs | 12 ++---- .../tools/Lua/LuaConsole.cs | 9 +---- .../tools/TAStudio/TAStudio.cs | 40 +++++++------------ .../tools/Watch/RamSearch.cs | 9 +---- .../tools/Watch/RamWatch.cs | 9 +---- 6 files changed, 30 insertions(+), 65 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/RollColumns.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/RollColumns.cs index 498e48affe..27b846c142 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/RollColumns.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/RollColumns.cs @@ -29,27 +29,23 @@ namespace BizHawk.Client.EmuHawk public new void Add(RollColumn column) { - if (this.Any(c => c.Name == column.Name)) + if (this[column.Name] == null) { - throw new InvalidOperationException("A column with this name already exists."); + base.Add(column); + ColumnsChanged(); } - - base.Add(column); - ColumnsChanged(); } public new void AddRange(IEnumerable collection) { - var items = collection.ToList(); - foreach (var column in items) + foreach (var column in collection) { - if (this.Any(c => c.Name == column.Name)) + if (this[column.Name] == null) { - throw new InvalidOperationException("A column with this name already exists."); + Add(column); } } - base.AddRange(items); ColumnsChanged(); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index b74469c77f..c17c407cfc 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -163,15 +163,10 @@ namespace BizHawk.Client.EmuHawk GeneralUpdate(); } - private void SetColumns() + private void SetColumns() { - foreach (var column in Settings.Columns) - { - if (CheatListView.AllColumns[column.Name] == null) - { - CheatListView.AllColumns.Add(column); - } - } + CheatListView.AllColumns.AddRange(Settings.Columns); + CheatListView.Refresh(); } private void ColumnToggleCallback() @@ -549,7 +544,6 @@ namespace BizHawk.Client.EmuHawk CheatListView.AllColumns.Clear(); SetColumns(); - CheatListView.Refresh(); } private void CheatListView_DoubleClick(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index aea22d23c4..ff93d07b8b 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -264,13 +264,8 @@ namespace BizHawk.Client.EmuHawk private void SetColumns() { - foreach (var column in Settings.Columns) - { - if (LuaListView.AllColumns[column.Name] == null) - { - LuaListView.AllColumns.Add(column); - } - } + LuaListView.AllColumns.AddRange(Settings.Columns); + LuaListView.Refresh(); } private void AddFileWatches() diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 68ff7f49e5..730829fd11 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -367,15 +367,14 @@ namespace BizHawk.Client.EmuHawk { TasView.AllColumns.Clear(); AddColumn(CursorColumnName, "", 18); - AddColumn( - new RollColumn - { - Name = FrameColumnName, - Text = "Frame#", - UnscaledWidth = 68, - Type = ColumnType.Text, - Rotatable = true - }); + TasView.AllColumns.Add(new RollColumn + { + Name = FrameColumnName, + Text = "Frame#", + UnscaledWidth = 68, + Type = ColumnType.Text, + Rotatable = true + }); var columnNames = MovieSession.Movie .LogGeneratorInstance(MovieSession.MovieController) @@ -484,14 +483,13 @@ namespace BizHawk.Client.EmuHawk public void AddColumn(string columnName, string columnText, int columnWidth, ColumnType columnType = ColumnType.Boolean) { - AddColumn( - new RollColumn - { - Name = columnName, - Text = columnText, - UnscaledWidth = columnWidth, - Type = columnType - }); + TasView.AllColumns.Add(new RollColumn + { + Name = columnName, + Text = columnText, + UnscaledWidth = columnWidth, + Type = columnType + }); } public void LoadBranchByIndex(int index) => BookMarkControl.LoadBranchExternal(index); @@ -525,14 +523,6 @@ namespace BizHawk.Client.EmuHawk } } - private void AddColumn(RollColumn column) - { - if (TasView.AllColumns[column.Name] == null) - { - TasView.AllColumns.Add(column); - } - } - private void ConvertCurrentMovieToTasproj() { MovieSession.ConvertToTasProj(); diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index d4a7abb71a..7f690338f2 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -241,13 +241,8 @@ namespace BizHawk.Client.EmuHawk private void SetColumns() { - foreach (var column in Settings.Columns) - { - if (WatchListView.AllColumns[column.Name] == null) - { - WatchListView.AllColumns.Add(column); - } - } + WatchListView.AllColumns.AddRange(Settings.Columns); + WatchListView.Refresh(); } /// diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 11c55c65e4..7b288ae37e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -102,13 +102,8 @@ namespace BizHawk.Client.EmuHawk private void SetColumns() { - foreach (var column in Settings.Columns) - { - if (WatchListView.AllColumns[column.Name] == null) - { - WatchListView.AllColumns.Add(column); - } - } + WatchListView.AllColumns.AddRange(Settings.Columns); + WatchListView.Refresh(); } [ConfigPersist]