namespace Terminal.Gui; /// /// Implementation of which records toggled rows by a property on row /// objects. /// public class CheckBoxTableSourceWrapperByObject : CheckBoxTableSourceWrapperBase { private readonly Func _getter; private readonly Action _setter; private readonly IEnumerableTableSource _toWrap; /// Creates a new instance of the class wrapping the collection . /// The table you will use the source with. /// The collection of objects you will record checked state for /// Delegate method for retrieving checked state from your objects of type . /// Delegate method for setting new checked states on your objects of type . public CheckBoxTableSourceWrapperByObject ( TableView tableView, IEnumerableTableSource toWrap, Func getter, Action setter ) : base (tableView, toWrap) { _toWrap = toWrap; _getter = getter; _setter = setter; } /// protected override void ClearAllToggles () { foreach (T e in _toWrap.GetAllObjects ()) { _setter (e, false); } } /// protected override bool IsChecked (int row) { return _getter (_toWrap.GetObjectOnRow (row)); } /// protected override void ToggleAllRows () { ToggleRows (Enumerable.Range (0, _toWrap.Rows).ToArray ()); } /// protected override void ToggleRow (int row) { T d = _toWrap.GetObjectOnRow (row); _setter (d, !_getter (d)); } /// protected override void ToggleRows (int [] range) { // if all are ticked untick them if (range.All (IsChecked)) { // select none foreach (int r in range) { _setter (_toWrap.GetObjectOnRow (r), false); } } else { // otherwise tick all foreach (int r in range) { _setter (_toWrap.GetObjectOnRow (r), true); } } } }