2019-10-26 21:49:52 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
namespace BizHawk.Client.EmuHawk
{
public class RollColumns : List < RollColumn >
2019-10-26 22:06:42 +00:00
{
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 ( )
2019-10-26 21:49:52 +00:00
{
2019-10-26 22:06:42 +00:00
int pos = 0 ;
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
foreach ( var col in VisibleColumns )
2019-10-26 21:49:52 +00:00
{
2019-10-26 22:06:42 +00:00
col . Left = pos ;
2019-12-03 17:26:21 +00:00
pos + = col . Width ;
2019-10-26 22:06:42 +00:00
col . Right = pos ;
2019-10-26 21:49:52 +00:00
}
2019-10-26 22:06:42 +00:00
ChangedCallback ? . Invoke ( ) ;
}
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
public new void Add ( RollColumn column )
{
if ( this . Any ( c = > c . Name = = column . Name ) )
2019-10-26 21:49:52 +00:00
{
2019-10-26 22:06:42 +00:00
// The designer sucks, doing nothing for now
return ;
//throw new InvalidOperationException("A column with this name already exists.");
2019-10-26 21:49:52 +00:00
}
2019-10-26 22:06:42 +00:00
base . Add ( column ) ;
ColumnsChanged ( ) ;
}
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
public new void AddRange ( IEnumerable < RollColumn > collection )
{
var items = collection . ToList ( ) ;
foreach ( var column in items )
2019-10-26 21:49:52 +00:00
{
if ( this . Any ( c = > c . Name = = column . Name ) )
{
// The designer sucks, doing nothing for now
return ;
2019-10-26 22:06:42 +00:00
throw new InvalidOperationException ( "A column with this name already exists." ) ;
}
2019-10-26 21:49:52 +00:00
}
2019-10-26 22:06:42 +00:00
base . AddRange ( items ) ;
ColumnsChanged ( ) ;
}
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
public new void Insert ( int index , RollColumn column )
{
if ( this . Any ( c = > c . Name = = column . Name ) )
{
// The designer sucks, doing nothing for now
return ;
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
throw new InvalidOperationException ( "A column with this name already exists." ) ;
2019-10-26 21:49:52 +00:00
}
2019-10-26 22:06:42 +00:00
base . Insert ( index , column ) ;
ColumnsChanged ( ) ;
}
public new void InsertRange ( int index , IEnumerable < RollColumn > collection )
{
var items = collection . ToList ( ) ;
foreach ( var column in items )
2019-10-26 21:49:52 +00:00
{
if ( this . Any ( c = > c . Name = = column . Name ) )
{
throw new InvalidOperationException ( "A column with this name already exists." ) ;
}
}
2019-10-26 22:06:42 +00:00
base . InsertRange ( index , items ) ;
ColumnsChanged ( ) ;
}
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
public new bool Remove ( RollColumn column )
{
var result = base . Remove ( column ) ;
ColumnsChanged ( ) ;
return result ;
}
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
public new int RemoveAll ( Predicate < RollColumn > match )
{
var result = base . RemoveAll ( match ) ;
ColumnsChanged ( ) ;
return result ;
}
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
public new void RemoveAt ( int index )
{
base . RemoveAt ( index ) ;
ColumnsChanged ( ) ;
}
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
public new void RemoveRange ( int index , int count )
{
base . RemoveRange ( index , count ) ;
ColumnsChanged ( ) ;
}
2019-10-26 21:49:52 +00:00
2019-10-26 22:06:42 +00:00
public new void Clear ( )
{
base . Clear ( ) ;
ColumnsChanged ( ) ;
2019-10-26 21:49:52 +00:00
}
2019-10-26 22:06:42 +00:00
public IEnumerable < string > Groups = > this
. Select ( x = > x . Group )
. Distinct ( ) ;
}
2019-10-26 21:49:52 +00:00
}