Add `WatchList.InsertRange` and use when duplicating rows in RAM Watch

This commit is contained in:
YoshiRulz 2023-06-13 22:14:33 +10:00
parent 4d4887ee31
commit ca8a183f38
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 16 additions and 1 deletions

View File

@ -143,6 +143,21 @@ namespace BizHawk.Client.Common
Changes = true;
}
/// <param name="index">
/// <c>0</c> to prepend, <see cref="Count"/> to append, anything in-between to insert there
/// (the first elem of <paramref name="collection"/> will end up at <paramref name="index"/>)
/// </param>
public void InsertRange(int index, IEnumerable<Watch> collection)
{
#if NET6_0
if (collection.TryGetNonEnumeratedCount(out var n) && n is 0) return;
#else
if (collection is ICollection<Watch> hasCount && hasCount.Count is 0) return;
#endif
_watchList.InsertRange(index, collection);
Changes = true;
}
/// <summary>
/// Removes item at the specified index
/// </summary>

View File

@ -411,7 +411,7 @@ namespace BizHawk.Client.EmuHawk
{
if (duplicate)
{
_watches.AddRange(we.Watches);
_watches.InsertRange(WatchListView.SelectionEndIndex!.Value + 1, we.Watches); //TODO should be able to reduce the number of enumerations of selected rows if necessary --yoshi
WatchListView.RowCount = _watches.Count;
UpdateWatchCount();
}