move some repetitive logic from tools to the RollColumns class

This commit is contained in:
adelikat 2020-07-24 13:17:03 -05:00
parent 4a3e2113af
commit a51eba88da
6 changed files with 30 additions and 65 deletions

View File

@ -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<RollColumn> 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();
}

View File

@ -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)

View File

@ -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()

View File

@ -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();

View File

@ -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();
}
/// <summary>

View File

@ -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]