cleanup input roll column and cell classes
This commit is contained in:
parent
b54be19e9e
commit
0ce5046061
|
@ -23,10 +23,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Cell)
|
||||
var cell = obj as Cell;
|
||||
if (cell != null)
|
||||
{
|
||||
var cell = obj as Cell;
|
||||
return this.Column == cell.Column && this.RowIndex == cell.RowIndex;
|
||||
return Column == cell.Column && RowIndex == cell.RowIndex;
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
|
@ -40,21 +40,31 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
internal class SortCell : IComparer<Cell>
|
||||
{
|
||||
int IComparer<Cell>.Compare(Cell a, Cell b)
|
||||
int IComparer<Cell>.Compare(Cell c1, Cell c2)
|
||||
{
|
||||
Cell c1 = a as Cell;
|
||||
Cell c2 = b as Cell;
|
||||
if (c1 == null && c2 == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (c2 == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (c1 == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (c1.RowIndex.HasValue)
|
||||
{
|
||||
if (c2.RowIndex.HasValue)
|
||||
{
|
||||
int row = c1.RowIndex.Value.CompareTo(c2.RowIndex.Value);
|
||||
if (row == 0)
|
||||
{
|
||||
return c1.Column.Name.CompareTo(c2.Column.Name);
|
||||
}
|
||||
|
||||
return row;
|
||||
return row == 0
|
||||
? c1.Column.Name.CompareTo(c2.Column.Name)
|
||||
: row;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -9,21 +9,11 @@
|
|||
public string Name { get; set; }
|
||||
public string Text { get; set; }
|
||||
public ColumnType Type { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Column will be drawn with an emphasized look, if true
|
||||
/// </summary>
|
||||
private bool _emphasis;
|
||||
public bool Emphasis
|
||||
{
|
||||
get { return _emphasis; }
|
||||
set { _emphasis = value; }
|
||||
}
|
||||
|
||||
public RollColumn()
|
||||
{
|
||||
Visible = true;
|
||||
}
|
||||
public bool Emphasis { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,148 +5,122 @@ using System.Linq;
|
|||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public class RollColumns : List<RollColumn>
|
||||
{
|
||||
public RollColumn this[string name] => this.SingleOrDefault(column => column.Name == name);
|
||||
|
||||
public IEnumerable<RollColumn> VisibleColumns => this.Where(c => c.Visible);
|
||||
|
||||
public Action ChangedCallback { get; set; }
|
||||
|
||||
// TODO: this shouldn't be exposed. But in order to not expose it, each RollColumn must have a change callback, and all property changes must call it, it is quicker and easier to just call this when needed
|
||||
public void ColumnsChanged()
|
||||
{
|
||||
public RollColumn this[string name]
|
||||
int pos = 0;
|
||||
|
||||
foreach (var col in VisibleColumns)
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.SingleOrDefault(column => column.Name == name);
|
||||
}
|
||||
col.Left = pos;
|
||||
pos += col.Width ?? 0;
|
||||
col.Right = pos;
|
||||
}
|
||||
|
||||
public IEnumerable<RollColumn> VisibleColumns
|
||||
ChangedCallback?.Invoke();
|
||||
}
|
||||
|
||||
public new void Add(RollColumn column)
|
||||
{
|
||||
if (this.Any(c => c.Name == column.Name))
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Where(c => c.Visible);
|
||||
}
|
||||
// The designer sucks, doing nothing for now
|
||||
return;
|
||||
//throw new InvalidOperationException("A column with this name already exists.");
|
||||
}
|
||||
|
||||
public Action ChangedCallback { get; set; }
|
||||
base.Add(column);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
private void DoChangeCallback()
|
||||
{
|
||||
// no check will make it crash for user too, not sure which way of alarm we prefer. no alarm at all will cause all sorts of subtle bugs
|
||||
if (ChangedCallback == null)
|
||||
{
|
||||
System.Diagnostics.Debug.Fail($"{nameof(ChangedCallback)} has died!");
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangedCallback();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this shouldn't be exposed. But in order to not expose it, each RollColumn must have a change callback, and all property changes must call it, it is quicker and easier to just call this when needed
|
||||
public void ColumnsChanged()
|
||||
{
|
||||
int pos = 0;
|
||||
|
||||
foreach (var col in VisibleColumns)
|
||||
{
|
||||
col.Left = pos;
|
||||
pos += col.Width.Value;
|
||||
col.Right = pos;
|
||||
}
|
||||
|
||||
DoChangeCallback();
|
||||
}
|
||||
|
||||
public new void Add(RollColumn column)
|
||||
public new void AddRange(IEnumerable<RollColumn> collection)
|
||||
{
|
||||
var items = collection.ToList();
|
||||
foreach (var column in items)
|
||||
{
|
||||
if (this.Any(c => c.Name == column.Name))
|
||||
{
|
||||
// The designer sucks, doing nothing for now
|
||||
return;
|
||||
//throw new InvalidOperationException("A column with this name already exists.");
|
||||
}
|
||||
|
||||
base.Add(column);
|
||||
ColumnsChanged();
|
||||
throw new InvalidOperationException("A column with this name already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
public new void AddRange(IEnumerable<RollColumn> collection)
|
||||
base.AddRange(items);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new void Insert(int index, RollColumn column)
|
||||
{
|
||||
if (this.Any(c => c.Name == column.Name))
|
||||
{
|
||||
foreach (var column in collection)
|
||||
{
|
||||
if (this.Any(c => c.Name == column.Name))
|
||||
{
|
||||
// The designer sucks, doing nothing for now
|
||||
return;
|
||||
// The designer sucks, doing nothing for now
|
||||
return;
|
||||
|
||||
throw new InvalidOperationException("A column with this name already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
base.AddRange(collection);
|
||||
ColumnsChanged();
|
||||
throw new InvalidOperationException("A column with this name already exists.");
|
||||
}
|
||||
|
||||
public new void Insert(int index, RollColumn column)
|
||||
base.Insert(index, column);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new void InsertRange(int index, IEnumerable<RollColumn> collection)
|
||||
{
|
||||
var items = collection.ToList();
|
||||
foreach (var column in items)
|
||||
{
|
||||
if (this.Any(c => c.Name == column.Name))
|
||||
{
|
||||
throw new InvalidOperationException("A column with this name already exists.");
|
||||
}
|
||||
|
||||
base.Insert(index, column);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new void InsertRange(int index, IEnumerable<RollColumn> collection)
|
||||
{
|
||||
foreach (var column in collection)
|
||||
{
|
||||
if (this.Any(c => c.Name == column.Name))
|
||||
{
|
||||
throw new InvalidOperationException("A column with this name already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
base.InsertRange(index, collection);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new bool Remove(RollColumn column)
|
||||
{
|
||||
var result = base.Remove(column);
|
||||
ColumnsChanged();
|
||||
return result;
|
||||
}
|
||||
|
||||
public new int RemoveAll(Predicate<RollColumn> match)
|
||||
{
|
||||
var result = base.RemoveAll(match);
|
||||
ColumnsChanged();
|
||||
return result;
|
||||
}
|
||||
|
||||
public new void RemoveAt(int index)
|
||||
{
|
||||
base.RemoveAt(index);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new void RemoveRange(int index, int count)
|
||||
{
|
||||
base.RemoveRange(index, count);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public IEnumerable<string> Groups
|
||||
{
|
||||
get
|
||||
{
|
||||
return this
|
||||
.Select(x => x.Group)
|
||||
.Distinct();
|
||||
}
|
||||
}
|
||||
base.InsertRange(index, items);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new bool Remove(RollColumn column)
|
||||
{
|
||||
var result = base.Remove(column);
|
||||
ColumnsChanged();
|
||||
return result;
|
||||
}
|
||||
|
||||
public new int RemoveAll(Predicate<RollColumn> match)
|
||||
{
|
||||
var result = base.RemoveAll(match);
|
||||
ColumnsChanged();
|
||||
return result;
|
||||
}
|
||||
|
||||
public new void RemoveAt(int index)
|
||||
{
|
||||
base.RemoveAt(index);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new void RemoveRange(int index, int count)
|
||||
{
|
||||
base.RemoveRange(index, count);
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public new void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
ColumnsChanged();
|
||||
}
|
||||
|
||||
public IEnumerable<string> Groups => this
|
||||
.Select(x => x.Group)
|
||||
.Distinct();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue