Refactors for selection in `InputRoll`

also standardises behaviour of Select All and Insert Separator buttons
see e88fa8135
This commit is contained in:
YoshiRulz 2022-06-30 00:17:49 +10:00
parent 5875df4b76
commit 206dcaf49b
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
16 changed files with 189 additions and 294 deletions

View File

@ -46,6 +46,9 @@ namespace BizHawk.Client.Common
public int ActiveCount => _cheatList.Count(c => c.Enabled); public int ActiveCount => _cheatList.Count(c => c.Enabled);
public bool AnyActive
=> _cheatList.Any(static c => c.Enabled);
public bool Changes public bool Changes
{ {
get => _changes; get => _changes;

View File

@ -586,6 +586,12 @@ namespace BizHawk.Client.EmuHawk
Refresh(); Refresh();
} }
public void ToggleSelectAll()
{
if (SelectedRows.Count() == RowCount) DeselectAll();
else SelectAll();
}
public void TruncateSelection(int index) public void TruncateSelection(int index)
{ {
_selectedItems.RemoveWhere(cell => cell.RowIndex > index); _selectedItems.RemoveWhere(cell => cell.RowIndex > index);
@ -596,17 +602,17 @@ namespace BizHawk.Client.EmuHawk
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsPointingAtColumnHeader => IsHoveringOnColumnCell; public bool IsPointingAtColumnHeader => IsHoveringOnColumnCell;
/// <returns>the <see cref="Cell.RowIndex"/> of the selected row with the earliest index, or <see langword="null"/> if no rows are selected</returns>
[Browsable(false)] [Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int? FirstSelectedIndex => AnyRowsSelected public int? SelectionStartIndex
? SelectedRows.Min() => AnyRowsSelected ? SelectedRowsWithDuplicates.Min() : null;
: (int?)null;
/// <returns>the <see cref="Cell.RowIndex"/> of the selected row with the latest index, or <see langword="null"/> if no rows are selected</returns>
[Browsable(false)] [Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int? LastSelectedIndex => AnyRowsSelected public int? SelectionEndIndex
? SelectedRows.Max() => AnyRowsSelected ? SelectedRowsWithDuplicates.Max() : null;
: (int?)null;
/// <summary> /// <summary>
/// Gets or sets the current Cell that the mouse was in. /// Gets or sets the current Cell that the mouse was in.
@ -919,13 +925,26 @@ namespace BizHawk.Client.EmuHawk
} }
[Browsable(false)] [Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] private IEnumerable<int> SelectedRowsWithDuplicates
public IEnumerable<int> SelectedRows => _selectedItems => _selectedItems.Where(static cell => cell.RowIndex is not null).Select(static cell => cell.RowIndex.Value);
.Where(cell => cell.RowIndex.HasValue)
.Select(cell => cell.RowIndex.Value)
.Distinct();
public bool AnyRowsSelected => _selectedItems.Any(cell => cell.RowIndex.HasValue); [Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IEnumerable<int> SelectedRows
=> SelectedRowsWithDuplicates.Distinct();
[Browsable(false)]
public bool AnyRowsSelected
=> _selectedItems.Any(static cell => cell.RowIndex is not null);
/// <returns>the <see cref="Cell.RowIndex"/> of the first row in the selection list (throws if no rows are selected)</returns>
/// <remarks>you probably want <see cref="SelectionStartIndex"/>, TODO check existing callsites</remarks>
[Browsable(false)]
public int FirstSelectedRowIndex
=> SelectedRowsWithDuplicates.First();
public bool IsRowSelected(int rowIndex)
=> _selectedItems.Any(cell => cell.RowIndex == rowIndex);
public IEnumerable<ToolStripItem> GenerateContextMenuItems() public IEnumerable<ToolStripItem> GenerateContextMenuItems()
{ {
@ -1356,7 +1375,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (ChangeSelectionWhenPaging) if (ChangeSelectionWhenPaging)
{ {
var selectedRow = SelectedRows.Any() ? SelectedRows.First() : FirstVisibleRow; var selectedRow = AnyRowsSelected ? FirstSelectedRowIndex : FirstVisibleRow;
var increment = LastVisibleRow - FirstVisibleRow; var increment = LastVisibleRow - FirstVisibleRow;
var newSelectedRow = selectedRow - increment; var newSelectedRow = selectedRow - increment;
if (newSelectedRow < 0) if (newSelectedRow < 0)
@ -1378,7 +1397,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (ChangeSelectionWhenPaging) if (ChangeSelectionWhenPaging)
{ {
var selectedRow = SelectedRows.Any() ? SelectedRows.First() : FirstVisibleRow; var selectedRow = AnyRowsSelected ? FirstSelectedRowIndex : FirstVisibleRow;
var increment = LastVisibleRow - FirstVisibleRow; var increment = LastVisibleRow - FirstVisibleRow;
var newSelectedRow = selectedRow + increment; var newSelectedRow = selectedRow + increment;
if (newSelectedRow > RowCount - 1) if (newSelectedRow > RowCount - 1)
@ -1412,9 +1431,9 @@ namespace BizHawk.Client.EmuHawk
} }
else if (e.IsPressed(Keys.Up)) else if (e.IsPressed(Keys.Up))
{ {
if (SelectedRows.Any()) if (AnyRowsSelected)
{ {
var selectedRow = SelectedRows.First(); var selectedRow = FirstSelectedRowIndex;
if (selectedRow > 0) if (selectedRow > 0)
{ {
var targetSelectedRow = selectedRow - 1; var targetSelectedRow = selectedRow - 1;
@ -1427,9 +1446,9 @@ namespace BizHawk.Client.EmuHawk
} }
else if (e.IsPressed(Keys.Down)) else if (e.IsPressed(Keys.Down))
{ {
if (SelectedRows.Any()) if (AnyRowsSelected)
{ {
var selectedRow = SelectedRows.First(); var selectedRow = FirstSelectedRowIndex;
if (selectedRow < RowCount - 1) if (selectedRow < RowCount - 1)
{ {
var targetSelectedRow = selectedRow + 1; var targetSelectedRow = selectedRow + 1;
@ -1482,7 +1501,7 @@ namespace BizHawk.Client.EmuHawk
// Selection cursor // Selection cursor
else if (e.IsCtrl(Keys.Up)) else if (e.IsCtrl(Keys.Up))
{ {
if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.First() > 0) if (AnyRowsSelected && LetKeysModifySelection && FirstSelectedRowIndex > 0)
{ {
foreach (var row in SelectedRows.ToList()) // clones SelectedRows foreach (var row in SelectedRows.ToList()) // clones SelectedRows
{ {
@ -1493,7 +1512,7 @@ namespace BizHawk.Client.EmuHawk
} }
else if (e.IsCtrl(Keys.Down)) else if (e.IsCtrl(Keys.Down))
{ {
if (SelectedRows.Any() && LetKeysModifySelection) if (AnyRowsSelected && LetKeysModifySelection)
{ {
foreach (var row in SelectedRows.Reverse()) // clones SelectedRows foreach (var row in SelectedRows.Reverse()) // clones SelectedRows
{ {
@ -1504,30 +1523,30 @@ namespace BizHawk.Client.EmuHawk
} }
else if (e.IsCtrl(Keys.Left)) else if (e.IsCtrl(Keys.Left))
{ {
if (SelectedRows.Any() && LetKeysModifySelection) if (AnyRowsSelected && LetKeysModifySelection)
{ {
SelectRow(SelectedRows.Last(), false); SelectRow(SelectedRows.Last(), false);
} }
} }
else if (e.IsCtrl(Keys.Right)) else if (e.IsCtrl(Keys.Right))
{ {
if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.Last() < _rowCount - 1) if (AnyRowsSelected && LetKeysModifySelection && SelectedRows.Last() < _rowCount - 1)
{ {
SelectRow(SelectedRows.Last() + 1, true); SelectRow(SelectedRows.Last() + 1, true);
} }
} }
else if (e.IsCtrlShift(Keys.Left)) else if (e.IsCtrlShift(Keys.Left))
{ {
if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.First() > 0) if (AnyRowsSelected && LetKeysModifySelection && FirstSelectedRowIndex > 0)
{ {
SelectRow(SelectedRows.First() - 1, true); SelectRow(FirstSelectedRowIndex - 1, true);
} }
} }
else if (e.IsCtrlShift(Keys.Right)) else if (e.IsCtrlShift(Keys.Right))
{ {
if (SelectedRows.Any() && LetKeysModifySelection) if (AnyRowsSelected && LetKeysModifySelection)
{ {
SelectRow(SelectedRows.First(), false); SelectRow(FirstSelectedRowIndex, false);
} }
} }
else if (e.IsCtrl(Keys.PageUp)) else if (e.IsCtrl(Keys.PageUp))

View File

@ -1462,7 +1462,7 @@ namespace BizHawk.Client.EmuHawk
public void UpdateCheatStatus() public void UpdateCheatStatus()
{ {
if (CheatList.ActiveCount > 0) if (CheatList.AnyActive)
{ {
CheatStatusButton.ToolTipText = "Cheats are currently active"; CheatStatusButton.ToolTipText = "Cheats are currently active";
CheatStatusButton.Image = Properties.Resources.Freeze; CheatStatusButton.Image = Properties.Resources.Freeze;

View File

@ -384,10 +384,11 @@ namespace BizHawk.Client.EmuHawk
MoveUpMenuItem.Enabled = MoveUpMenuItem.Enabled =
MoveDownMenuItem.Enabled = MoveDownMenuItem.Enabled =
ToggleMenuItem.Enabled = ToggleMenuItem.Enabled =
SelectedIndices.Any(); CheatListView.AnyRowsSelected;
// Always leave enabled even if no cheats enabled. This way the hotkey will always work however a new cheat is enabled #if false // Always leave enabled even if no cheats enabled. This way the hotkey will always work, even if a new cheat is enabled without also refreshing the menu
// DisableAllCheatsMenuItem.Enabled = MainForm.CheatList.ActiveCount > 0; DisableAllCheatsMenuItem.Enabled = MainForm.CheatList.AnyActive;
#endif
GameGenieSeparator.Visible = GameGenieSeparator.Visible =
OpenGameGenieEncoderDecoderMenuItem.Visible = OpenGameGenieEncoderDecoderMenuItem.Visible =
@ -411,15 +412,7 @@ namespace BizHawk.Client.EmuHawk
private void InsertSeparatorMenuItem_Click(object sender, EventArgs e) private void InsertSeparatorMenuItem_Click(object sender, EventArgs e)
{ {
if (SelectedIndices.Any()) MainForm.CheatList.Insert(CheatListView.SelectionStartIndex ?? MainForm.CheatList.Count, Cheat.Separator);
{
MainForm.CheatList.Insert(SelectedIndices.Max(), Cheat.Separator);
}
else
{
MainForm.CheatList.Add(Cheat.Separator);
}
GeneralUpdate(); GeneralUpdate();
UpdateMessageLabel(); UpdateMessageLabel();
} }
@ -480,9 +473,7 @@ namespace BizHawk.Client.EmuHawk
} }
private void SelectAllMenuItem_Click(object sender, EventArgs e) private void SelectAllMenuItem_Click(object sender, EventArgs e)
{ => CheatListView.ToggleSelectAll();
CheatListView.SelectAll();
}
private void ToggleMenuItem_Click(object sender, EventArgs e) private void ToggleMenuItem_Click(object sender, EventArgs e)
{ {
@ -606,7 +597,7 @@ namespace BizHawk.Client.EmuHawk
RemoveContextMenuItem.Enabled = RemoveContextMenuItem.Enabled =
SelectedCheats.Any(); SelectedCheats.Any();
DisableAllContextMenuItem.Enabled = MainForm.CheatList.ActiveCount > 0; DisableAllContextMenuItem.Enabled = MainForm.CheatList.AnyActive;
} }
private void ViewInHexEditorContextMenuItem_Click(object sender, EventArgs e) private void ViewInHexEditorContextMenuItem_Click(object sender, EventArgs e)

View File

@ -209,25 +209,13 @@ namespace BizHawk.Client.EmuHawk
private void CopySelectedDisassembler() private void CopySelectedDisassembler()
{ {
var indices = DisassemblerView.SelectedRows.ToList(); if (!DisassemblerView.AnyRowsSelected) return;
StringBuilder blob = new();
if (indices.Count > 0) foreach (var line in DisassemblerView.SelectedRows.Select(i => _disassemblyLines[i]))
{ {
var blob = new StringBuilder(); blob.AppendFormat("{0} {1}\n", line.Address.ToHexString(_pcRegisterSize), line.Mnemonic);
foreach (int index in indices)
{
if (blob.Length != 0)
{
blob.AppendLine();
}
blob.Append(_disassemblyLines[index].Address.ToHexString(_pcRegisterSize))
.Append(' ')
.Append(_disassemblyLines[index].Mnemonic);
}
Clipboard.SetDataObject(blob.ToString());
} }
Clipboard.SetDataObject(blob.ToString());
} }
private void OnPauseChanged(bool isPaused) private void OnPauseChanged(bool isPaused)
@ -237,16 +225,14 @@ namespace BizHawk.Client.EmuHawk
private void DisassemblerContextMenu_Opening(object sender, EventArgs e) private void DisassemblerContextMenu_Opening(object sender, EventArgs e)
{ {
AddBreakpointContextMenuItem.Enabled = DisassemblerView.SelectedRows.Any(); AddBreakpointContextMenuItem.Enabled = DisassemblerView.AnyRowsSelected;
} }
private void AddBreakpointContextMenuItem_Click(object sender, EventArgs e) private void AddBreakpointContextMenuItem_Click(object sender, EventArgs e)
{ {
var indices = DisassemblerView.SelectedRows.ToList(); if (DisassemblerView.AnyRowsSelected)
if (indices.Count > 0)
{ {
var line = _disassemblyLines[indices[0]]; var line = _disassemblyLines[DisassemblerView.FirstSelectedRowIndex];
BreakPointControl1.AddBreakpoint(line.Address, 0xFFFFFFFF, Emulation.Common.MemoryCallbackType.Execute); BreakPointControl1.AddBreakpoint(line.Address, 0xFFFFFFFF, Emulation.Common.MemoryCallbackType.Execute);
} }
} }

View File

@ -1991,7 +1991,7 @@ namespace BizHawk.Client.EmuHawk
(_highlightedAddress.HasValue || _secondaryHighlightedAddresses.Any()) && (_highlightedAddress.HasValue || _secondaryHighlightedAddresses.Any()) &&
_domain.Writable; _domain.Writable;
UnfreezeAllContextItem.Visible = MainForm.CheatList.ActiveCount > 0; UnfreezeAllContextItem.Visible = MainForm.CheatList.AnyActive;
PasteContextItem.Visible = _domain.Writable && data != null && data.GetDataPresent(DataFormats.Text); PasteContextItem.Visible = _domain.Writable && data != null && data.GetDataPresent(DataFormats.Text);
ContextSeparator1.Visible = ContextSeparator1.Visible =

View File

@ -829,7 +829,7 @@ namespace BizHawk.Client.EmuHawk
DuplicateScriptMenuItem.Enabled = DuplicateScriptMenuItem.Enabled =
MoveUpMenuItem.Enabled = MoveUpMenuItem.Enabled =
MoveDownMenuItem.Enabled = MoveDownMenuItem.Enabled =
LuaListView.SelectedRows.Any(); LuaListView.AnyRowsSelected;
SelectAllMenuItem.Enabled = LuaImp.ScriptList.Any(); SelectAllMenuItem.Enabled = LuaImp.ScriptList.Any();
StopAllScriptsMenuItem.Enabled = LuaImp.ScriptList.Any(script => script.Enabled); StopAllScriptsMenuItem.Enabled = LuaImp.ScriptList.Any(script => script.Enabled);
@ -986,7 +986,7 @@ namespace BizHawk.Client.EmuHawk
private void DuplicateScriptMenuItem_Click(object sender, EventArgs e) private void DuplicateScriptMenuItem_Click(object sender, EventArgs e)
{ {
if (LuaListView.SelectedRows.Any()) if (LuaListView.AnyRowsSelected)
{ {
var script = SelectedItems.First(); var script = SelectedItems.First();
@ -1024,16 +1024,7 @@ namespace BizHawk.Client.EmuHawk
private void InsertSeparatorMenuItem_Click(object sender, EventArgs e) private void InsertSeparatorMenuItem_Click(object sender, EventArgs e)
{ {
var indices = LuaListView.SelectedRows.ToList(); LuaImp.ScriptList.Insert(LuaListView.SelectionStartIndex ?? LuaImp.ScriptList.Count, LuaFile.SeparatorInstance);
if (indices.Any() && indices.Last() < LuaImp.ScriptList.Count)
{
LuaImp.ScriptList.Insert(indices.Last(), LuaFile.SeparatorInstance);
}
else
{
LuaImp.ScriptList.Add(LuaFile.SeparatorInstance);
}
UpdateDialog(); UpdateDialog();
} }
@ -1090,9 +1081,7 @@ namespace BizHawk.Client.EmuHawk
} }
private void SelectAllMenuItem_Click(object sender, EventArgs e) private void SelectAllMenuItem_Click(object sender, EventArgs e)
{ => LuaListView.ToggleSelectAll();
LuaListView.SelectAll();
}
private void StopAllScriptsMenuItem_Click(object sender, EventArgs e) private void StopAllScriptsMenuItem_Click(object sender, EventArgs e)
{ {

View File

@ -170,9 +170,8 @@ namespace BizHawk.Client.EmuHawk
MainForm.UpdateStatusSlots(); MainForm.UpdateStatusSlots();
} }
public TasBranch SelectedBranch => BranchView.AnyRowsSelected public TasBranch SelectedBranch
? Branches[BranchView.SelectedRows.First()] => BranchView.AnyRowsSelected ? Branches[BranchView.FirstSelectedRowIndex] : null;
: null;
private TasBranch CreateBranch() private TasBranch CreateBranch()
{ {
@ -214,8 +213,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (SelectedBranch != null) if (SelectedBranch != null)
{ {
int index = BranchView.SelectedRows.First(); Branches.Current = BranchView.FirstSelectedRowIndex;
Branches.Current = index;
LoadBranch(SelectedBranch); LoadBranch(SelectedBranch);
BranchView.Refresh(); BranchView.Refresh();
Tastudio.MainForm.AddOnScreenMessage($"Loaded branch {Branches.Current + 1}"); Tastudio.MainForm.AddOnScreenMessage($"Loaded branch {Branches.Current + 1}");
@ -267,7 +265,7 @@ namespace BizHawk.Client.EmuHawk
if (BranchView.AnyRowsSelected) if (BranchView.AnyRowsSelected)
{ {
LoadSelectedBranch(); LoadSelectedBranch();
LoadedCallback?.Invoke(BranchView.SelectedRows.First()); LoadedCallback?.Invoke(BranchView.FirstSelectedRowIndex);
} }
} }
@ -278,7 +276,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
Branches.Current = BranchView.SelectedRows.First(); Branches.Current = BranchView.FirstSelectedRowIndex;
_backupBranch = SelectedBranch.Clone(); _backupBranch = SelectedBranch.Clone();
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true; UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
@ -300,7 +298,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
int index = BranchView.SelectedRows.First(); var index = BranchView.FirstSelectedRowIndex;
string oldText = SelectedBranch.UserText; string oldText = SelectedBranch.UserText;
if (EditBranchTextPopUp(index)) if (EditBranchTextPopUp(index))
@ -318,14 +316,7 @@ namespace BizHawk.Client.EmuHawk
private void JumpToBranchToolStripMenuItem_Click(object sender, EventArgs e) private void JumpToBranchToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (!BranchView.AnyRowsSelected) if (BranchView.AnyRowsSelected) Tastudio.GoToFrame(Branches[BranchView.FirstSelectedRowIndex].Frame);
{
return;
}
int index = BranchView.SelectedRows.First();
var branch = Branches[index];
Tastudio.GoToFrame(branch.Frame);
} }
private void RemoveBranchToolStripMenuItem_Click(object sender, EventArgs e) private void RemoveBranchToolStripMenuItem_Click(object sender, EventArgs e)
@ -491,7 +482,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
int sel = BranchView.SelectedRows.First(); var sel = BranchView.FirstSelectedRowIndex;
if (next) if (next)
{ {
if (Branches[sel + 1] != null) if (Branches[sel + 1] != null)

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
@ -17,6 +16,9 @@ namespace BizHawk.Client.EmuHawk
public IDialogController DialogController => Tastudio.MainForm; public IDialogController DialogController => Tastudio.MainForm;
private TasMovieMarker FirstSelectedMarker
=> Markers[MarkerView.FirstSelectedRowIndex];
public MarkerControl() public MarkerControl()
{ {
InitializeComponent(); InitializeComponent();
@ -122,7 +124,7 @@ namespace BizHawk.Client.EmuHawk
{ {
EditMarkerToolStripMenuItem.Enabled = EditMarkerToolStripMenuItem.Enabled =
RemoveMarkerToolStripMenuItem.Enabled = RemoveMarkerToolStripMenuItem.Enabled =
MarkerInputRoll.AnyRowsSelected && MarkerView.SelectedRows.First() != 0; MarkerInputRoll.AnyRowsSelected && MarkerView.FirstSelectedRowIndex is not 0;
JumpToMarkerToolStripMenuItem.Enabled = JumpToMarkerToolStripMenuItem.Enabled =
ScrollToMarkerToolStripMenuItem.Enabled = ScrollToMarkerToolStripMenuItem.Enabled =
@ -133,29 +135,19 @@ namespace BizHawk.Client.EmuHawk
{ {
if (MarkerView.AnyRowsSelected) if (MarkerView.AnyRowsSelected)
{ {
Tastudio.SetVisibleFrame(SelectedMarkerFrame()); Tastudio.SetVisibleFrame(FirstSelectedMarker.Frame);
Tastudio.RefreshDialog(); Tastudio.RefreshDialog();
} }
} }
private void JumpToMarkerToolStripMenuItem_Click(object sender, EventArgs e) private void JumpToMarkerToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (MarkerView.AnyRowsSelected) if (MarkerView.AnyRowsSelected) Tastudio.GoToFrame(FirstSelectedMarker.Frame);
{
var index = MarkerView.SelectedRows.First();
var marker = Markers[index];
Tastudio.GoToFrame(marker.Frame);
}
} }
private void EditMarkerToolStripMenuItem_Click(object sender, EventArgs e) private void EditMarkerToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (MarkerView.AnyRowsSelected) if (MarkerView.AnyRowsSelected) EditMarkerPopUp(FirstSelectedMarker);
{
var index = MarkerView.SelectedRows.First();
var marker = Markers[index];
EditMarkerPopUp(marker);
}
} }
private void AddMarkerToolStripMenuItem_Click(object sender, EventArgs e) private void AddMarkerToolStripMenuItem_Click(object sender, EventArgs e)
@ -170,12 +162,10 @@ namespace BizHawk.Client.EmuHawk
private void RemoveMarkerToolStripMenuItem_Click(object sender, EventArgs e) private void RemoveMarkerToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (MarkerView.AnyRowsSelected) if (!MarkerView.AnyRowsSelected) return;
{ foreach (var i in MarkerView.SelectedRows.Select(index => Markers[index]).ToList()) Markers.Remove(i);
SelectedMarkers.ForEach(i => Markers.Remove(i)); MarkerView.RowCount = Markers.Count;
MarkerView.RowCount = Markers.Count; Tastudio.RefreshDialog();
Tastudio.RefreshDialog();
}
} }
public void UpdateMarkerCount() public void UpdateMarkerCount()
@ -283,41 +273,18 @@ namespace BizHawk.Client.EmuHawk
{ {
EditMarkerButton.Enabled = EditMarkerButton.Enabled =
RemoveMarkerButton.Enabled = RemoveMarkerButton.Enabled =
MarkerInputRoll.AnyRowsSelected && MarkerView.SelectedRows.First() != 0; MarkerInputRoll.AnyRowsSelected && MarkerView.FirstSelectedRowIndex is not 0;
JumpToMarkerButton.Enabled = JumpToMarkerButton.Enabled =
ScrollToMarkerButton.Enabled = ScrollToMarkerButton.Enabled =
MarkerInputRoll.AnyRowsSelected; MarkerInputRoll.AnyRowsSelected;
} }
private List<TasMovieMarker> SelectedMarkers => MarkerView
.SelectedRows
.Select(index => Markers[index])
.ToList();
// SuuperW: Marker renaming can be done with a right-click. // SuuperW: Marker renaming can be done with a right-click.
// A much more useful feature would be to easily jump to it. // A much more useful feature would be to easily jump to it.
private void MarkerView_MouseDoubleClick(object sender, EventArgs e) private void MarkerView_MouseDoubleClick(object sender, EventArgs e)
{ {
if (MarkerView.AnyRowsSelected) if (MarkerView.AnyRowsSelected) Tastudio.GoToFrame(FirstSelectedMarker.Frame);
{
var index = MarkerView.SelectedRows.First();
var marker = Markers[index];
Tastudio.GoToFrame(marker.Frame);
}
}
public int SelectedMarkerFrame()
{
if (MarkerView.AnyRowsSelected)
{
var index = MarkerView.SelectedRows.First();
var marker = Markers[index];
return marker.Frame;
}
return -1;
} }
} }
} }

View File

@ -377,11 +377,11 @@ namespace BizHawk.Client.EmuHawk
if (columnName == FrameColumnName) if (columnName == FrameColumnName)
{ {
CurrentTasMovie.Markers.Add(TasView.LastSelectedIndex.Value, ""); CurrentTasMovie.Markers.Add(TasView.SelectionEndIndex!.Value, "");
} }
else if (columnName != CursorColumnName) else if (columnName != CursorColumnName)
{ {
int frame = TasView.SelectedRows.FirstOrDefault(); var frame = TasView.AnyRowsSelected ? TasView.FirstSelectedRowIndex : 0;
string buttonName = TasView.CurrentCell.Column.Name; string buttonName = TasView.CurrentCell.Column.Name;
if (ControllerType.BoolButtons.Contains(buttonName)) if (ControllerType.BoolButtons.Contains(buttonName))
@ -566,7 +566,7 @@ namespace BizHawk.Client.EmuHawk
_extraAxisRows.Clear(); _extraAxisRows.Clear();
_extraAxisRows.AddRange(TasView.SelectedRows); _extraAxisRows.AddRange(TasView.SelectedRows);
_startSelectionDrag = true; _startSelectionDrag = true;
_selectionDragState = TasView.SelectedRows.Contains(frame); _selectionDragState = TasView.IsRowSelected(frame);
return; return;
} }
if (_axisEditColumn != buttonName if (_axisEditColumn != buttonName
@ -608,7 +608,7 @@ namespace BizHawk.Client.EmuHawk
else else
{ {
_startSelectionDrag = true; _startSelectionDrag = true;
_selectionDragState = TasView.SelectedRows.Contains(frame); _selectionDragState = TasView.IsRowSelected(frame);
} }
} }
else if (TasView.CurrentCell.Column.Type != ColumnType.Text) // User changed input else if (TasView.CurrentCell.Column.Type != ColumnType.Text) // User changed input
@ -637,12 +637,12 @@ namespace BizHawk.Client.EmuHawk
else if (ModifierKeys == Keys.Shift && ModifierKeys != Keys.Alt) else if (ModifierKeys == Keys.Shift && ModifierKeys != Keys.Alt)
{ {
if (!TasView.AnyRowsSelected) return; if (!TasView.AnyRowsSelected) return;
int firstSel = TasView.SelectedRows.First(); var firstSel = TasView.FirstSelectedRowIndex;
if (frame <= firstSel) if (frame <= firstSel)
{ {
firstSel = frame; firstSel = frame;
frame = TasView.SelectedRows.First(); frame = TasView.FirstSelectedRowIndex;
} }
bool allPressed = true; bool allPressed = true;
@ -729,13 +729,13 @@ namespace BizHawk.Client.EmuHawk
_rightClickControl = (ModifierKeys | Keys.Control) == ModifierKeys; _rightClickControl = (ModifierKeys | Keys.Control) == ModifierKeys;
_rightClickShift = (ModifierKeys | Keys.Shift) == ModifierKeys; _rightClickShift = (ModifierKeys | Keys.Shift) == ModifierKeys;
_rightClickAlt = (ModifierKeys | Keys.Alt) == ModifierKeys; _rightClickAlt = (ModifierKeys | Keys.Alt) == ModifierKeys;
if (TasView.SelectedRows.Contains(frame)) if (TasView.IsRowSelected(frame))
{ {
_rightClickInput = new string[TasView.SelectedRows.Count()]; _rightClickInput = new string[TasView.SelectedRows.Count()];
_rightClickFrame = TasView.FirstSelectedIndex.Value; _rightClickFrame = TasView.SelectionStartIndex!.Value;
try try
{ {
CurrentTasMovie.GetLogEntries().CopyTo(_rightClickFrame, _rightClickInput, 0, TasView.SelectedRows.Count()); CurrentTasMovie.GetLogEntries().CopyTo(_rightClickFrame, _rightClickInput, 0, _rightClickInput.Length);
} }
catch { } catch { }
if (_rightClickControl && _rightClickShift) if (_rightClickControl && _rightClickShift)
@ -817,10 +817,10 @@ namespace BizHawk.Client.EmuHawk
private void TasView_MouseUp(object sender, MouseEventArgs e) private void TasView_MouseUp(object sender, MouseEventArgs e)
{ {
if (e.Button == MouseButtons.Right && !TasView.IsPointingAtColumnHeader && if (e.Button == MouseButtons.Right && !TasView.IsPointingAtColumnHeader
!_suppressContextMenu && TasView.SelectedRows.Any() && !_leftButtonHeld) && !_suppressContextMenu && !_leftButtonHeld && TasView.AnyRowsSelected)
{ {
if (CurrentTasMovie.FrameCount < TasView.SelectedRows.Max()) if (CurrentTasMovie.FrameCount < TasView.SelectionEndIndex)
{ {
// trying to be smart here // trying to be smart here
// if a loaded branch log is shorter than selection, keep selection until you attempt to call context menu // if a loaded branch log is shorter than selection, keep selection until you attempt to call context menu

View File

@ -54,13 +54,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (SaveRamEmulator.CloneSaveRam() != null) if (SaveRamEmulator.CloneSaveRam() != null)
{ {
int index = 0; GoToFrame(TasView.AnyRowsSelected ? TasView.FirstSelectedRowIndex : 0);
if (TasView.SelectedRows.Any())
{
index = TasView.SelectedRows.First();
}
GoToFrame(index);
var newProject = CurrentTasMovie.ConvertToSaveRamAnchoredMovie( var newProject = CurrentTasMovie.ConvertToSaveRamAnchoredMovie(
SaveRamEmulator.CloneSaveRam()); SaveRamEmulator.CloneSaveRam());
MainForm.PauseEmulator(); MainForm.PauseEmulator();
@ -224,7 +218,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
if (TasView.LastSelectedIndex == CurrentTasMovie.InputLogLength) if (TasView.SelectionEndIndex == CurrentTasMovie.InputLogLength)
{ {
TasView.SelectRow(CurrentTasMovie.InputLogLength, false); TasView.SelectRow(CurrentTasMovie.InputLogLength, false);
} }
@ -238,12 +232,13 @@ namespace BizHawk.Client.EmuHawk
if (file != null) if (file != null)
{ {
var selectionStart = TasView.SelectionStartIndex!.Value;
new MovieZone( new MovieZone(
Emulator, Emulator,
Tools, Tools,
MovieSession, MovieSession,
TasView.FirstSelectedIndex.Value, start: selectionStart,
TasView.LastSelectedIndex.Value - TasView.FirstSelectedIndex.Value + 1) length: TasView.SelectionEndIndex!.Value - selectionStart + 1)
.Save(file.FullName); .Save(file.FullName);
Config.RecentMacros.Add(file.FullName); Config.RecentMacros.Add(file.FullName);
@ -406,6 +401,7 @@ namespace BizHawk.Client.EmuHawk
TasView.Refresh(); TasView.Refresh();
} }
/// <remarks>TODO merge w/ Deselect?</remarks>
private void SelectAllMenuItem_Click(object sender, EventArgs e) private void SelectAllMenuItem_Click(object sender, EventArgs e)
{ {
TasView.SelectAll(); TasView.SelectAll();
@ -416,8 +412,9 @@ namespace BizHawk.Client.EmuHawk
{ {
if (TasView.Focused && TasView.AnyRowsSelected) if (TasView.Focused && TasView.AnyRowsSelected)
{ {
var prevMarker = CurrentTasMovie.Markers.PreviousOrCurrent(TasView.LastSelectedIndex ?? 0); var selectionEnd = TasView.SelectionEndIndex ?? 0;
var nextMarker = CurrentTasMovie.Markers.Next(TasView.LastSelectedIndex ?? 0); var prevMarker = CurrentTasMovie.Markers.PreviousOrCurrent(selectionEnd);
var nextMarker = CurrentTasMovie.Markers.Next(selectionEnd);
int prev = prevMarker?.Frame ?? 0; int prev = prevMarker?.Frame ?? 0;
int next = nextMarker?.Frame ?? CurrentTasMovie.InputLogLength; int next = nextMarker?.Frame ?? CurrentTasMovie.InputLogLength;
@ -499,7 +496,7 @@ namespace BizHawk.Client.EmuHawk
_tasClipboard.Add(new TasClipboardEntry(i, line)); _tasClipboard.Add(new TasClipboardEntry(i, line));
} }
var rollbackFrame = CurrentTasMovie.CopyOverInput(TasView.FirstSelectedIndex ?? 0, _tasClipboard.Select(x => x.ControllerState)); var rollbackFrame = CurrentTasMovie.CopyOverInput(TasView.SelectionStartIndex ?? 0, _tasClipboard.Select(static x => x.ControllerState));
if (rollbackFrame > 0) if (rollbackFrame > 0)
{ {
GoToLastEmulatedFrameIfNecessary(rollbackFrame); GoToLastEmulatedFrameIfNecessary(rollbackFrame);
@ -539,11 +536,12 @@ namespace BizHawk.Client.EmuHawk
_tasClipboard.Add(new TasClipboardEntry(i, line)); _tasClipboard.Add(new TasClipboardEntry(i, line));
} }
var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var selectionStart = TasView.SelectionStartIndex;
CurrentTasMovie.InsertInput(TasView.FirstSelectedIndex ?? 0, _tasClipboard.Select(x => x.ControllerState)); var needsToRollback = selectionStart < Emulator.Frame;
CurrentTasMovie.InsertInput(selectionStart ?? 0, _tasClipboard.Select(static x => x.ControllerState));
if (needsToRollback) if (needsToRollback)
{ {
GoToLastEmulatedFrameIfNecessary(TasView.FirstSelectedIndex.Value); GoToLastEmulatedFrameIfNecessary(selectionStart!.Value);
DoAutoRestore(); DoAutoRestore();
} }
@ -558,8 +556,9 @@ namespace BizHawk.Client.EmuHawk
{ {
if (TasView.Focused && TasView.AnyRowsSelected) if (TasView.Focused && TasView.AnyRowsSelected)
{ {
var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var selectionStart = TasView.SelectionStartIndex;
var rollBackFrame = TasView.FirstSelectedIndex ?? 0; var needsToRollback = selectionStart < Emulator.Frame;
var rollBackFrame = selectionStart ?? 0;
_tasClipboard.Clear(); _tasClipboard.Clear();
var list = TasView.SelectedRows.ToArray(); var list = TasView.SelectedRows.ToArray();
@ -598,9 +597,9 @@ namespace BizHawk.Client.EmuHawk
{ {
var firstWithInput = FirstNonEmptySelectedFrame; var firstWithInput = FirstNonEmptySelectedFrame;
bool needsToRollback = firstWithInput.HasValue && firstWithInput < Emulator.Frame; bool needsToRollback = firstWithInput.HasValue && firstWithInput < Emulator.Frame;
int rollBackFrame = TasView.FirstSelectedIndex ?? 0; var rollBackFrame = TasView.SelectionStartIndex ?? 0;
CurrentTasMovie.ChangeLog.BeginNewBatch($"Clear frames {TasView.SelectedRows.Min()}-{TasView.SelectedRows.Max()}"); CurrentTasMovie.ChangeLog.BeginNewBatch($"Clear frames {TasView.SelectionStartIndex}-{TasView.SelectionEndIndex}");
foreach (int frame in TasView.SelectedRows) foreach (int frame in TasView.SelectedRows)
{ {
CurrentTasMovie.ClearFrame(frame); CurrentTasMovie.ClearFrame(frame);
@ -622,8 +621,9 @@ namespace BizHawk.Client.EmuHawk
{ {
if (TasView.Focused && TasView.AnyRowsSelected) if (TasView.Focused && TasView.AnyRowsSelected)
{ {
var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var selectionStart = TasView.SelectionStartIndex;
var rollBackFrame = TasView.FirstSelectedIndex ?? 0; var needsToRollback = selectionStart < Emulator.Frame;
var rollBackFrame = selectionStart ?? 0;
if (rollBackFrame >= CurrentTasMovie.InputLogLength) if (rollBackFrame >= CurrentTasMovie.InputLogLength)
{ {
// Cannot delete non-existent frames // Cannot delete non-existent frames
@ -665,8 +665,8 @@ namespace BizHawk.Client.EmuHawk
if (TasView.Focused && TasView.AnyRowsSelected) if (TasView.Focused && TasView.AnyRowsSelected)
{ {
var framesToInsert = TasView.SelectedRows; var framesToInsert = TasView.SelectedRows;
var insertionFrame = Math.Min((TasView.LastSelectedIndex ?? 0) + 1, CurrentTasMovie.InputLogLength); var insertionFrame = Math.Min((TasView.SelectionEndIndex ?? 0) + 1, CurrentTasMovie.InputLogLength);
var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var needsToRollback = TasView.SelectionStartIndex < Emulator.Frame;
var inputLog = framesToInsert var inputLog = framesToInsert
.Select(frame => CurrentTasMovie.GetInputLogEntry(frame)) .Select(frame => CurrentTasMovie.GetInputLogEntry(frame))
@ -689,8 +689,9 @@ namespace BizHawk.Client.EmuHawk
{ {
if (TasView.Focused && TasView.AnyRowsSelected) if (TasView.Focused && TasView.AnyRowsSelected)
{ {
var insertionFrame = TasView.FirstSelectedIndex ?? 0; var selectionStart = TasView.SelectionStartIndex;
var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var insertionFrame = selectionStart ?? 0;
var needsToRollback = selectionStart < Emulator.Frame;
CurrentTasMovie.InsertEmptyFrame(insertionFrame); CurrentTasMovie.InsertEmptyFrame(insertionFrame);
@ -708,7 +709,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (TasView.Focused && TasView.AnyRowsSelected) if (TasView.Focused && TasView.AnyRowsSelected)
{ {
int insertionFrame = TasView.FirstSelectedIndex ?? 0; var insertionFrame = TasView.SelectionStartIndex ?? 0;
using var framesPrompt = new FramesPrompt(); using var framesPrompt = new FramesPrompt();
if (framesPrompt.ShowDialog().IsOk()) if (framesPrompt.ShowDialog().IsOk())
{ {
@ -721,8 +722,8 @@ namespace BizHawk.Client.EmuHawk
{ {
if (TasView.Focused && TasView.AnyRowsSelected) if (TasView.Focused && TasView.AnyRowsSelected)
{ {
var rollbackFrame = TasView.LastSelectedIndex ?? 0; var rollbackFrame = TasView.SelectionEndIndex ?? 0;
var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var needsToRollback = TasView.SelectionStartIndex < Emulator.Frame;
CurrentTasMovie.Truncate(rollbackFrame); CurrentTasMovie.Truncate(rollbackFrame);
MarkerControl.MarkerInputRoll.TruncateSelection(CurrentTasMovie.Markers.Count - 1); MarkerControl.MarkerInputRoll.TruncateSelection(CurrentTasMovie.Markers.Count - 1);
@ -755,12 +756,12 @@ namespace BizHawk.Client.EmuHawk
private void SetMarkerWithTextMenuItem_Click(object sender, EventArgs e) private void SetMarkerWithTextMenuItem_Click(object sender, EventArgs e)
{ {
MarkerControl.AddMarker(TasView.SelectedRows.FirstOrDefault(), true); MarkerControl.AddMarker(TasView.AnyRowsSelected ? TasView.FirstSelectedRowIndex : 0, true);
} }
private void RemoveMarkersMenuItem_Click(object sender, EventArgs e) private void RemoveMarkersMenuItem_Click(object sender, EventArgs e)
{ {
CurrentTasMovie.Markers.RemoveAll(m => TasView.SelectedRows.Contains(m.Frame)); CurrentTasMovie.Markers.RemoveAll(m => TasView.IsRowSelected(m.Frame));
MarkerControl.UpdateMarkerCount(); MarkerControl.UpdateMarkerCount();
RefreshDialog(); RefreshDialog();
} }
@ -1405,7 +1406,7 @@ namespace BizHawk.Client.EmuHawk
StartNewProjectFromNowMenuItem.Visible = StartNewProjectFromNowMenuItem.Visible =
TasView.SelectedRows.Count() == 1 TasView.SelectedRows.Count() == 1
&& TasView.SelectedRows.Contains(Emulator.Frame) && TasView.IsRowSelected(Emulator.Frame)
&& !CurrentTasMovie.StartsFromSaveRam; && !CurrentTasMovie.StartsFromSaveRam;
StartANewProjectFromSaveRamMenuItem.Visible = StartANewProjectFromSaveRamMenuItem.Visible =
@ -1414,7 +1415,7 @@ namespace BizHawk.Client.EmuHawk
&& !CurrentTasMovie.StartsFromSavestate; && !CurrentTasMovie.StartsFromSavestate;
StartFromNowSeparator.Visible = StartNewProjectFromNowMenuItem.Visible || StartANewProjectFromSaveRamMenuItem.Visible; StartFromNowSeparator.Visible = StartNewProjectFromNowMenuItem.Visible || StartANewProjectFromSaveRamMenuItem.Visible;
RemoveMarkersContextMenuItem.Enabled = CurrentTasMovie.Markers.Any(m => TasView.SelectedRows.Contains(m.Frame)); // Disable the option to remove markers if no markers are selected (FCEUX does this). RemoveMarkersContextMenuItem.Enabled = CurrentTasMovie.Markers.Any(m => TasView.IsRowSelected(m.Frame)); // Disable the option to remove markers if no markers are selected (FCEUX does this).
CancelSeekContextMenuItem.Enabled = MainForm.PauseOnFrame.HasValue; CancelSeekContextMenuItem.Enabled = MainForm.PauseOnFrame.HasValue;
BranchContextMenuItem.Visible = TasView.CurrentCell?.RowIndex == Emulator.Frame; BranchContextMenuItem.Visible = TasView.CurrentCell?.RowIndex == Emulator.Frame;

View File

@ -686,7 +686,7 @@ namespace BizHawk.Client.EmuHawk
var loadZone = new MovieZone(path, MainForm, Emulator, MovieSession, Tools) var loadZone = new MovieZone(path, MainForm, Emulator, MovieSession, Tools)
{ {
Start = TasView.FirstSelectedIndex.Value Start = TasView.SelectionStartIndex!.Value,
}; };
loadZone.PlaceZone(CurrentTasMovie, Config); loadZone.PlaceZone(CurrentTasMovie, Config);
} }
@ -981,7 +981,8 @@ namespace BizHawk.Client.EmuHawk
private void SetSplicer() private void SetSplicer()
{ {
// TODO: columns selected? // TODO: columns selected?
var temp = $"Selected: {TasView.SelectedRows.Count()} {(TasView.SelectedRows.Count() == 1 ? "frame" : "frames")}, States: {CurrentTasMovie.TasStateManager.Count}"; var selectedRowCount = TasView.SelectedRows.Count();
var temp = $"Selected: {selectedRowCount} {(selectedRowCount == 1 ? "frame" : "frames")}, States: {CurrentTasMovie.TasStateManager.Count}";
if (_tasClipboard.Any()) temp += $", Clipboard: {_tasClipboard.Count} {(_tasClipboard.Count == 1 ? "frame" : "frames")}"; if (_tasClipboard.Any()) temp += $", Clipboard: {_tasClipboard.Count} {(_tasClipboard.Count == 1 ? "frame" : "frames")}";
SplicerStatusLabel.Text = temp; SplicerStatusLabel.Text = temp;
} }
@ -1014,7 +1015,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (insertionFrame <= CurrentTasMovie.InputLogLength) if (insertionFrame <= CurrentTasMovie.InputLogLength)
{ {
bool needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var needsToRollback = TasView.SelectionStartIndex < Emulator.Frame;
CurrentTasMovie.InsertEmptyFrame(insertionFrame, numberOfFrames); CurrentTasMovie.InsertEmptyFrame(insertionFrame, numberOfFrames);
@ -1055,7 +1056,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (beginningFrame < CurrentTasMovie.InputLogLength) if (beginningFrame < CurrentTasMovie.InputLogLength)
{ {
bool needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var needsToRollback = TasView.SelectionStartIndex < Emulator.Frame;
int last = Math.Min(beginningFrame + numberOfFrames, CurrentTasMovie.InputLogLength); int last = Math.Min(beginningFrame + numberOfFrames, CurrentTasMovie.InputLogLength);
for (int i = beginningFrame; i < last; i++) for (int i = beginningFrame; i < last; i++)
{ {

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
@ -85,9 +84,8 @@ namespace BizHawk.Client.EmuHawk
_tastudio.RefreshDialog(); _tastudio.RefreshDialog();
} }
private int SelectedItem => HistoryView.SelectedRows.Any() private int SelectedItem
? HistoryView.SelectedRows.First() => HistoryView.AnyRowsSelected ? HistoryView.FirstSelectedRowIndex : -1;
: -1;
private void UndoToHere(int index) private void UndoToHere(int index)
{ {

View File

@ -321,17 +321,13 @@ namespace BizHawk.Client.EmuHawk
private void CopyMenuItem_Click(object sender, EventArgs e) private void CopyMenuItem_Click(object sender, EventArgs e)
{ {
var indices = TraceView.SelectedRows.ToList(); if (!TraceView.AnyRowsSelected) return;
StringBuilder blob = new();
if (indices.Count > 0) foreach (var info in TraceView.SelectedRows.Select(index => _instructions[index]))
{ {
var blob = new StringBuilder(); blob.AppendFormat("{0} {1}\n", info.Disassembly, info.RegisterInfo);
foreach (int index in indices)
{
blob.Append($"{_instructions[index].Disassembly} {_instructions[index].RegisterInfo}\n");
}
Clipboard.SetDataObject(blob.ToString());
} }
Clipboard.SetDataObject(blob.ToString());
} }
private void SelectAllMenuItem_Click(object sender, EventArgs e) private void SelectAllMenuItem_Click(object sender, EventArgs e)

View File

@ -421,8 +421,7 @@ namespace BizHawk.Client.EmuHawk
PokeAddressToolBarItem.Enabled = PokeAddressToolBarItem.Enabled =
FreezeAddressToolBarItem.Enabled = FreezeAddressToolBarItem.Enabled =
SelectedIndices.Any() WatchListView.AnyRowsSelected && _searches.Domain.Writable;
&& _searches.Domain.Writable;
} }
private long? CompareToValue private long? CompareToValue
@ -546,6 +545,9 @@ namespace BizHawk.Client.EmuHawk
private IEnumerable<Watch> SelectedWatches => SelectedItems.Where(x => !x.IsSeparator); private IEnumerable<Watch> SelectedWatches => SelectedItems.Where(x => !x.IsSeparator);
private bool MayPokeAllSelected
=> WatchListView.AnyRowsSelected && SelectedWatches.All(static w => w.Domain.Writable);
private void SetRemovedMessage(int val) private void SetRemovedMessage(int val)
{ {
MessageLabel.Text = $"{val} {(val == 1 ? "address" : "addresses")} removed"; MessageLabel.Text = $"{val} {(val == 1 ? "address" : "addresses")} removed";
@ -876,16 +878,10 @@ namespace BizHawk.Client.EmuHawk
private void PokeAddress() private void PokeAddress()
{ {
if (SelectedIndices.Any()) if (!WatchListView.AnyRowsSelected) return;
{ using RamPoke poke = new(DialogController, SelectedItems, MainForm.CheatList) { InitialLocation = this.ChildPointToScreen(WatchListView) };
var poke = new RamPoke(DialogController, SelectedIndices.Select(t => _searches[t]), MainForm.CheatList) this.ShowDialogWithTempMute(poke);
{ UpdateList();
InitialLocation = this.ChildPointToScreen(WatchListView)
};
this.ShowDialogWithTempMute(poke);
UpdateList();
}
} }
private void RemoveRamWatchesFromList() private void RemoveRamWatchesFromList()
@ -944,12 +940,6 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private void SelectAllAddresses()
{
if (SelectedIndices.Count() == WatchListView.RowCount) WatchListView.DeselectAll();
else WatchListView.SelectAll();
}
public class RamSearchSettings public class RamSearchSettings
{ {
public RamSearchSettings() public RamSearchSettings()
@ -1196,12 +1186,11 @@ namespace BizHawk.Client.EmuHawk
RemoveMenuItem.Enabled = RemoveMenuItem.Enabled =
AddToRamWatchMenuItem.Enabled = AddToRamWatchMenuItem.Enabled =
SelectedIndices.Any(); WatchListView.AnyRowsSelected;
PokeAddressMenuItem.Enabled = PokeAddressMenuItem.Enabled =
FreezeAddressMenuItem.Enabled = FreezeAddressMenuItem.Enabled =
SelectedIndices.Any() && MayPokeAllSelected;
SelectedWatches.All(w => w.Domain.Writable);
UndoMenuItem.Enabled = UndoMenuItem.Enabled =
ClearUndoMenuItem.Enabled = ClearUndoMenuItem.Enabled =
@ -1299,9 +1288,7 @@ namespace BizHawk.Client.EmuHawk
} }
private void SelectAllMenuItem_Click(object sender, EventArgs e) private void SelectAllMenuItem_Click(object sender, EventArgs e)
{ => WatchListView.ToggleSelectAll();
SelectAllAddresses();
}
private void SettingsSubMenu_DropDownOpened(object sender, EventArgs e) private void SettingsSubMenu_DropDownOpened(object sender, EventArgs e)
{ {
@ -1379,27 +1366,17 @@ namespace BizHawk.Client.EmuHawk
FreezeContextMenuItem.Visible = FreezeContextMenuItem.Visible =
ContextMenuSeparator2.Visible = ContextMenuSeparator2.Visible =
ViewInHexEditorContextMenuItem.Visible = ViewInHexEditorContextMenuItem.Visible =
SelectedIndices.Any(); WatchListView.AnyRowsSelected;
PokeContextMenuItem.Enabled = PokeContextMenuItem.Enabled =
FreezeContextMenuItem.Visible = FreezeContextMenuItem.Visible =
SelectedIndices.Any() && MayPokeAllSelected;
SelectedWatches.All(w => w.Domain.Writable);
UnfreezeAllContextMenuItem.Visible = MainForm.CheatList.ActiveCount > 0; UnfreezeAllContextMenuItem.Visible = MainForm.CheatList.AnyActive;
ContextMenuSeparator3.Visible = SelectedIndices.Any() || (MainForm.CheatList.ActiveCount > 0); ContextMenuSeparator3.Visible = WatchListView.AnyRowsSelected || MainForm.CheatList.AnyActive;
var allCheats = true; if (SelectedItems.All(watch => MainForm.CheatList.IsActive(_settings.Domain, watch.Address)))
foreach (var index in SelectedIndices)
{
if (!MainForm.CheatList.IsActive(_settings.Domain, _searches[index].Address))
{
allCheats = false;
}
}
if (allCheats)
{ {
FreezeContextMenuItem.Text = "&Unfreeze Address"; FreezeContextMenuItem.Text = "&Unfreeze Address";
FreezeContextMenuItem.Image = Resources.Unfreeze; FreezeContextMenuItem.Image = Resources.Unfreeze;
@ -1658,12 +1635,11 @@ namespace BizHawk.Client.EmuHawk
{ {
RemoveToolBarItem.Enabled = RemoveToolBarItem.Enabled =
AddToRamWatchToolBarItem.Enabled = AddToRamWatchToolBarItem.Enabled =
SelectedIndices.Any(); WatchListView.AnyRowsSelected;
PokeAddressToolBarItem.Enabled = PokeAddressToolBarItem.Enabled =
FreezeAddressToolBarItem.Enabled = FreezeAddressToolBarItem.Enabled =
SelectedIndices.Any() WatchListView.AnyRowsSelected && _searches.Domain.Writable;
&& _searches.Domain.Writable;
} }
private void WatchListView_Enter(object sender, EventArgs e) private void WatchListView_Enter(object sender, EventArgs e)
@ -1688,7 +1664,7 @@ namespace BizHawk.Client.EmuHawk
private void WatchListView_MouseDoubleClick(object sender, MouseEventArgs e) private void WatchListView_MouseDoubleClick(object sender, MouseEventArgs e)
{ {
if (SelectedIndices.Any()) if (WatchListView.AnyRowsSelected)
{ {
AddToRamWatch(); AddToRamWatch();
} }

View File

@ -142,6 +142,9 @@ namespace BizHawk.Client.EmuHawk
private IEnumerable<Watch> SelectedWatches => SelectedItems.Where(x => !x.IsSeparator); private IEnumerable<Watch> SelectedWatches => SelectedItems.Where(x => !x.IsSeparator);
private IEnumerable<Watch> SelectedSeparators => SelectedItems.Where(x => x.IsSeparator); private IEnumerable<Watch> SelectedSeparators => SelectedItems.Where(x => x.IsSeparator);
private bool MayPokeAllSelected
=> WatchListView.AnyRowsSelected && SelectedWatches.All(static w => w.Domain.Writable);
public IEnumerable<Watch> Watches => _watches.Where(x => !x.IsSeparator); public IEnumerable<Watch> Watches => _watches.Where(x => !x.IsSeparator);
protected override void GeneralUpdate() => FrameUpdate(); protected override void GeneralUpdate() => FrameUpdate();
@ -233,8 +236,7 @@ namespace BizHawk.Client.EmuHawk
GeneralUpdate(); GeneralUpdate();
PokeAddressToolBarItem.Enabled = PokeAddressToolBarItem.Enabled =
FreezeAddressToolBarItem.Enabled = FreezeAddressToolBarItem.Enabled =
SelectedIndices.Any() MayPokeAllSelected;
&& SelectedWatches.All(w => w.Domain.Writable);
} }
} }
} }
@ -507,8 +509,7 @@ namespace BizHawk.Client.EmuHawk
PokeAddressToolBarItem.Enabled = PokeAddressToolBarItem.Enabled =
FreezeAddressToolBarItem.Enabled = FreezeAddressToolBarItem.Enabled =
SelectedIndices.Any() && MayPokeAllSelected;
SelectedWatches.All(w => w.Domain.Writable);
} }
} }
@ -704,14 +705,13 @@ namespace BizHawk.Client.EmuHawk
MoveDownMenuItem.Enabled = MoveDownMenuItem.Enabled =
MoveTopMenuItem.Enabled = MoveTopMenuItem.Enabled =
MoveBottomMenuItem.Enabled = MoveBottomMenuItem.Enabled =
SelectedIndices.Any(); WatchListView.AnyRowsSelected;
SplitWatchMenuItem.Enabled = MaySplitAllSelected; SplitWatchMenuItem.Enabled = MaySplitAllSelected;
PokeAddressMenuItem.Enabled = PokeAddressMenuItem.Enabled =
FreezeAddressMenuItem.Enabled = FreezeAddressMenuItem.Enabled =
SelectedIndices.Any() && MayPokeAllSelected;
SelectedWatches.All(w => w.Domain.Writable);
} }
private MemoryDomain _currentDomain; private MemoryDomain _currentDomain;
@ -756,19 +756,11 @@ namespace BizHawk.Client.EmuHawk
private void RemoveWatchMenuItem_Click(object sender, EventArgs e) private void RemoveWatchMenuItem_Click(object sender, EventArgs e)
{ {
var indices = SelectedIndices if (!WatchListView.AnyRowsSelected) return;
.OrderByDescending(i => i) foreach (var index in SelectedIndices.OrderByDescending(static i => i).ToList()) _watches.RemoveAt(index);
.ToList(); WatchListView.RowCount = _watches.Count;
if (indices.Any()) GeneralUpdate();
{ UpdateWatchCount();
foreach (var index in indices)
{
_watches.RemoveAt(index);
}
WatchListView.RowCount = _watches.Count;
GeneralUpdate();
UpdateWatchCount();
}
} }
private void DuplicateWatchMenuItem_Click(object sender, EventArgs e) private void DuplicateWatchMenuItem_Click(object sender, EventArgs e)
@ -840,16 +832,7 @@ namespace BizHawk.Client.EmuHawk
private void InsertSeparatorMenuItem_Click(object sender, EventArgs e) private void InsertSeparatorMenuItem_Click(object sender, EventArgs e)
{ {
var indexes = SelectedIndices.ToList(); _watches.Insert(WatchListView.SelectionStartIndex ?? _watches.Count, SeparatorWatch.Instance);
if (indexes.Any())
{
_watches.Insert(indexes[0], SeparatorWatch.Instance);
}
else
{
_watches.Add(SeparatorWatch.Instance);
}
WatchListView.RowCount = _watches.Count; WatchListView.RowCount = _watches.Count;
Changes(); Changes();
UpdateWatchCount(); UpdateWatchCount();
@ -975,9 +958,7 @@ namespace BizHawk.Client.EmuHawk
} }
private void SelectAllMenuItem_Click(object sender, EventArgs e) private void SelectAllMenuItem_Click(object sender, EventArgs e)
{ => WatchListView.ToggleSelectAll();
WatchListView.SelectAll();
}
private void SettingsSubMenu_DropDownOpened(object sender, EventArgs e) private void SettingsSubMenu_DropDownOpened(object sender, EventArgs e)
{ {
@ -1051,8 +1032,7 @@ namespace BizHawk.Client.EmuHawk
UpdateStatusBar(); UpdateStatusBar();
PokeAddressToolBarItem.Enabled = PokeAddressToolBarItem.Enabled =
FreezeAddressToolBarItem.Enabled = FreezeAddressToolBarItem.Enabled =
SelectedIndices.Any() && MayPokeAllSelected;
SelectedWatches.All(w => w.Domain.Writable);
} }
private void ColumnToggleCallback() private void ColumnToggleCallback()
@ -1072,12 +1052,11 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private bool MaySplitAllSelected => SelectedIndices.Any() && SelectedWatches.All(static w => w.IsSplittable); private bool MaySplitAllSelected
=> WatchListView.AnyRowsSelected && SelectedWatches.All(static w => w.IsSplittable);
private void ListViewContextMenu_Opening(object sender, CancelEventArgs e) private void ListViewContextMenu_Opening(object sender, CancelEventArgs e)
{ {
var indexes = WatchListView.SelectedRows.ToList();
EditContextMenuItem.Visible = EditContextMenuItem.Visible =
RemoveContextMenuItem.Visible = RemoveContextMenuItem.Visible =
DuplicateContextMenuItem.Visible = DuplicateContextMenuItem.Visible =
@ -1093,7 +1072,7 @@ namespace BizHawk.Client.EmuHawk
MoveDownContextMenuItem.Visible = MoveDownContextMenuItem.Visible =
MoveTopContextMenuItem.Visible = MoveTopContextMenuItem.Visible =
MoveBottomContextMenuItem.Visible = MoveBottomContextMenuItem.Visible =
indexes.Count > 0; WatchListView.AnyRowsSelected;
ReadBreakpointContextMenuItem.Visible = ReadBreakpointContextMenuItem.Visible =
WriteBreakpointContextMenuItem.Visible = WriteBreakpointContextMenuItem.Visible =
@ -1107,8 +1086,7 @@ namespace BizHawk.Client.EmuHawk
PokeContextMenuItem.Enabled = PokeContextMenuItem.Enabled =
FreezeContextMenuItem.Visible = FreezeContextMenuItem.Visible =
SelectedIndices.Any() MayPokeAllSelected;
&& SelectedWatches.All(w => w.Domain.Writable);
var allCheats = SelectedWatches.All(x => MainForm.CheatList.IsActive(x.Domain, x.Address)); var allCheats = SelectedWatches.All(x => MainForm.CheatList.IsActive(x.Domain, x.Address));
@ -1123,11 +1101,11 @@ namespace BizHawk.Client.EmuHawk
FreezeContextMenuItem.Image = Resources.Freeze; FreezeContextMenuItem.Image = Resources.Freeze;
} }
UnfreezeAllContextMenuItem.Visible = MainForm.CheatList.ActiveCount > 0; UnfreezeAllContextMenuItem.Visible = MainForm.CheatList.AnyActive;
ViewInHexEditorContextMenuItem.Visible = SelectedWatches.Count() == 1; ViewInHexEditorContextMenuItem.Visible = SelectedWatches.Count() == 1;
newToolStripMenuItem.Visible = indexes.Count == 0; newToolStripMenuItem.Visible = !WatchListView.AnyRowsSelected;
} }
private void UnfreezeAllContextMenuItem_Click(object sender, EventArgs e) private void UnfreezeAllContextMenuItem_Click(object sender, EventArgs e)
@ -1207,8 +1185,7 @@ namespace BizHawk.Client.EmuHawk
{ {
PokeAddressToolBarItem.Enabled = PokeAddressToolBarItem.Enabled =
FreezeAddressToolBarItem.Enabled = FreezeAddressToolBarItem.Enabled =
SelectedIndices.Any() MayPokeAllSelected;
&& SelectedWatches.All(w => w.Domain.Writable);
} }
private void WatchListView_MouseDoubleClick(object sender, MouseEventArgs e) private void WatchListView_MouseDoubleClick(object sender, MouseEventArgs e)