Create and use IEnumerable.SelectAsIndexOf extension

This commit is contained in:
YoshiRulz 2019-03-24 21:06:05 +10:00
parent 6045992464
commit b72f40808b
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
12 changed files with 41 additions and 45 deletions

View File

@ -352,7 +352,7 @@ namespace BizHawk.Client.Common
_history.AddState(_watchList);
}
var removeList = indices.Select(i => _watchList[i]); // This will fail after int.MaxValue but RAM Search fails on domains that large anyway
var removeList = indices.SelectAsIndexOf(_watchList); // This will fail after int.MaxValue but RAM Search fails on domains that large anyway
_watchList = _watchList.Except(removeList).ToList();
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
@ -9,6 +10,7 @@ using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
using BizHawk.Common.CollectionExtensions;
//todo - perks - pause, copy to clipboard, backlog length limiting
@ -112,8 +114,8 @@ namespace BizHawk.Client.EmuHawk
private void buttonCopy_Click(object sender, EventArgs e)
{
var sb = new StringBuilder();
foreach (int i in virtualListView1.SelectedIndices)
sb.AppendLine(Lines[i]);
foreach (var line in virtualListView1.SelectedIndices.Cast<int>().SelectAsIndexOf(Lines))
sb.AppendLine(line);
if (sb.Length > 0)
Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
}

View File

@ -10,6 +10,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.EmuHawk
{
@ -323,13 +324,13 @@ namespace BizHawk.Client.EmuHawk
if (indexes.Count > 0)
{
var copyStr = new StringBuilder();
foreach (int index in indexes)
foreach (var movie in indexes.Cast<int>().SelectAsIndexOf(_movieList))
{
copyStr
.Append(_movieList[index].Filename).Append('\t')
.Append(_movieList[index].SystemID).Append('\t')
.Append(_movieList[index].GameName).Append('\t')
.Append(PlatformFrameRates.MovieTime(_movieList[index]).ToString(@"hh\:mm\:ss\.fff"))
.Append(movie.Filename).Append('\t')
.Append(movie.SystemID).Append('\t')
.Append(movie.GameName).Append('\t')
.Append(PlatformFrameRates.MovieTime(movie).ToString(@"hh\:mm\:ss\.fff"))
.AppendLine();
}
Clipboard.SetDataObject(copyStr.ToString());
@ -471,7 +472,7 @@ namespace BizHawk.Client.EmuHawk
{
MovieView.SelectedIndices
.Cast<int>()
.Select(index => _movieList[index])
.SelectAsIndexOf(_movieList)
.ToList()
.ForEach(movie => System.Diagnostics.Process.Start(movie.Filename));
}

View File

@ -7,6 +7,7 @@ using System.Windows.Forms;
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.EmuHawk
{
@ -186,10 +187,7 @@ namespace BizHawk.Client.EmuHawk
private IEnumerable<int> SelectedIndices => BreakpointView.SelectedIndices.Cast<int>();
private IEnumerable<Breakpoint> SelectedItems
{
get { return SelectedIndices.Select(index => _breakpoints[index]); }
}
private IEnumerable<Breakpoint> SelectedItems => SelectedIndices.SelectAsIndexOf(_breakpoints);
private IEnumerable<Breakpoint> EditableItems
{

View File

@ -5,6 +5,8 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.EmuHawk
{
public partial class GenericDebugger
@ -199,16 +201,16 @@ namespace BizHawk.Client.EmuHawk
if (indices.Count > 0)
{
var blob = new StringBuilder();
foreach (int index in indices)
foreach (var disasmOp in indices.Cast<int>().SelectAsIndexOf(_disassemblyLines))
{
if (blob.Length != 0)
{
blob.AppendLine();
}
blob.Append(string.Format("{0:X" + _pcRegisterSize + "}", _disassemblyLines[index].Address))
blob.Append(string.Format("{0:X" + _pcRegisterSize + "}", disasmOp.Address))
.Append(" ")
.Append(_disassemblyLines[index].Mnemonic);
.Append(disasmOp.Mnemonic);
}
Clipboard.SetDataObject(blob.ToString());

View File

@ -11,6 +11,7 @@ using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
@ -96,10 +97,7 @@ namespace BizHawk.Client.EmuHawk
public bool UpdateBefore => true;
private IEnumerable<LuaFile> SelectedItems
{
get { return LuaListView.SelectedIndices().Select(index => LuaImp.ScriptList[index]); }
}
private IEnumerable<LuaFile> SelectedItems => LuaListView.SelectedIndices().SelectAsIndexOf(LuaImp.ScriptList);
private IEnumerable<LuaFile> SelectedFiles
{

View File

@ -7,6 +7,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.EmuHawk
{
@ -191,9 +192,8 @@ namespace BizHawk.Client.EmuHawk
{
var sb = new StringBuilder();
foreach (int index in indexes)
foreach (var libraryFunction in indexes.Cast<int>().SelectAsIndexOf(GlobalWin.Tools.LuaConsole.LuaImp.Docs))
{
var libraryFunction = GlobalWin.Tools.LuaConsole.LuaImp.Docs[index];
sb.Append(libraryFunction.Library).Append('.').Append(libraryFunction.Name).Append("()\n");
}

View File

@ -7,6 +7,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.EmuHawk
{
@ -269,16 +270,7 @@ namespace BizHawk.Client.EmuHawk
MarkerInputRoll.AnyRowsSelected;
}
private List<TasMovieMarker> SelectedMarkers
{
get
{
return MarkerView
.SelectedRows
.Select(index => Markers[index])
.ToList();
}
}
private List<TasMovieMarker> SelectedMarkers => MarkerView.SelectedRows.SelectAsIndexOf(Markers).ToList();
private void MarkerView_ItemActivate(object sender, EventArgs e)
{

View File

@ -9,6 +9,7 @@ using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.EmuHawk
{
@ -332,11 +333,11 @@ namespace BizHawk.Client.EmuHawk
if (indices.Count > 0)
{
var blob = new StringBuilder();
foreach (int index in indices)
foreach (var traceInfo in indices.Cast<int>().SelectAsIndexOf(_instructions))
{
blob.Append(string.Format("{0} {1}\n",
_instructions[index].Disassembly,
_instructions[index].RegisterInfo));
traceInfo.Disassembly,
traceInfo.RegisterInfo));
}
Clipboard.SetDataObject(blob.ToString());
}

View File

@ -13,6 +13,7 @@ using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.EmuHawk
{
@ -84,10 +85,7 @@ namespace BizHawk.Client.EmuHawk
private IEnumerable<int> SelectedIndices => WatchListView.SelectedIndices.Cast<int>();
private IEnumerable<Watch> SelectedItems
{
get { return SelectedIndices.Select(index => _watches[index]); }
}
private IEnumerable<Watch> SelectedItems => SelectedIndices.SelectAsIndexOf(_watches);
private IEnumerable<Watch> SelectedWatches
{

View File

@ -10,6 +10,8 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Client.EmuHawk;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.MultiHawk
{
public partial class PlayMovie : Form
@ -316,13 +318,13 @@ namespace BizHawk.Client.MultiHawk
if (indexes.Count > 0)
{
var copyStr = new StringBuilder();
foreach (int index in indexes)
foreach (var movie in indexes.Cast<int>().SelectAsIndexOf(_movieList))
{
copyStr
.Append(_movieList[index].Filename).Append('\t')
.Append(_movieList[index].SystemID).Append('\t')
.Append(_movieList[index].GameName).Append('\t')
.Append(PlatformFrameRates.MovieTime(_movieList[index]).ToString(@"hh\:mm\:ss\.fff"))
.Append(movie.Filename).Append('\t')
.Append(movie.SystemID).Append('\t')
.Append(movie.GameName).Append('\t')
.Append(PlatformFrameRates.MovieTime(movie).ToString(@"hh\:mm\:ss\.fff"))
.AppendLine();
}
Clipboard.SetDataObject(copyStr.ToString());
@ -459,7 +461,7 @@ namespace BizHawk.Client.MultiHawk
{
MovieView.SelectedIndices
.Cast<int>()
.Select(index => _movieList[index])
.SelectAsIndexOf(_movieList)
.ToList()
.ForEach(movie => System.Diagnostics.Process.Start(movie.Filename));
}

View File

@ -115,5 +115,7 @@ namespace BizHawk.Common.CollectionExtensions
return bools;
}
public static IEnumerable<T> SelectAsIndexOf<T>(this IEnumerable<int> indices, IList<T> list) => indices.Select(i => list[i]);
}
}