From 2a12cac9e5674452163f9b338a098a5ad6e3b168 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 29 Nov 2019 16:12:23 -0600 Subject: [PATCH] InputRoll - implement shift+Up/Down logic to highlight rows --- .../CustomControls/InputRoll/InputRoll.cs | 57 +++++++++++++++++-- .../tools/TAStudio/BookmarksBranchesBox.cs | 2 +- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs b/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs index 1d43f22b4d..0a85ed865e 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs @@ -490,6 +490,8 @@ namespace BizHawk.Client.EmuHawk #region Api + private int? _lastSelectedRow; + public void SelectRow(int index, bool val) { if (_columns.VisibleColumns.Any()) @@ -501,11 +503,13 @@ namespace BizHawk.Client.EmuHawk RowIndex = index, Column = _columns[0] }); + _lastSelectedRow = index; } else { IEnumerable items = _selectedItems.Where(cell => cell.RowIndex == index); _selectedItems.RemoveWhere(items.Contains); + _lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex; } } } @@ -520,16 +524,19 @@ namespace BizHawk.Client.EmuHawk } FullRowSelect = oldFullRowVal; + _lastSelectedRow = RowCount; } public void DeselectAll() { + _lastSelectedRow = null; _selectedItems.Clear(); } public void TruncateSelection(int index) { _selectedItems.RemoveWhere(cell => cell.RowIndex > index); + _lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex; } [Browsable(false)] @@ -900,11 +907,6 @@ namespace BizHawk.Client.EmuHawk public bool AnyRowsSelected => _selectedItems.Any(cell => cell.RowIndex.HasValue); - public void ClearSelectedRows() - { - _selectedItems.Clear(); - } - public IEnumerable GenerateContextMenuItems() { yield return new ToolStripSeparator(); @@ -1384,7 +1386,46 @@ namespace BizHawk.Client.EmuHawk } } } - // Selection courser + else if (!e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Up) // Shift+Up + { + if (MultiSelect && _lastSelectedRow > 0) + { + if (_selectedItems.Any(i => i.RowIndex == _lastSelectedRow.Value) + && _selectedItems.Any(i => i.RowIndex == _lastSelectedRow - 1)) // Unhighlight if already highlighted + { + SelectRow(_lastSelectedRow.Value, false); + } + else + { + SelectRow(_lastSelectedRow.Value - 1, true); + } + + Refresh(); + } + } + else if (!e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Down) // Shift+Down + { + if (MultiSelect && _lastSelectedRow < RowCount - 1) + { + if (_selectedItems.Any(i => i.RowIndex == _lastSelectedRow.Value) + && _selectedItems.Any(i => i.RowIndex == _lastSelectedRow + 1)) // Unhighlight if already highlighted + { + var origIndex = _lastSelectedRow.Value; + SelectRow(origIndex, false); + + // SelectRow assumed the max row should be selected, but in this edge case it isn't + _lastSelectedRow = _selectedItems.FirstOrDefault()?.RowIndex; + } + else + { + SelectRow(_lastSelectedRow.Value + 1, true); + + } + + Refresh(); + } + } + // Selection cursor else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Up) // Ctrl + Up { if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.First() > 0) @@ -1678,6 +1719,7 @@ namespace BizHawk.Client.EmuHawk if (!MultiSelect) { _selectedItems.Clear(); + _lastSelectedRow = null; } if (FullRowSelect) @@ -1685,6 +1727,7 @@ namespace BizHawk.Client.EmuHawk if (toggle && _selectedItems.Any(x => x.RowIndex.HasValue && x.RowIndex == cell.RowIndex)) { _selectedItems.RemoveWhere(x => x.RowIndex.HasValue && x.RowIndex == cell.RowIndex); + _lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex; } else { @@ -1695,11 +1738,13 @@ namespace BizHawk.Client.EmuHawk RowIndex = cell.RowIndex, Column = column }); + _lastSelectedRow = cell.RowIndex; } } } else { + _lastSelectedRow = null; // TODO: tracking this by cell is a lot more work if (toggle && _selectedItems.Any(x => x.RowIndex.HasValue && x.RowIndex == cell.RowIndex)) { var item = _selectedItems diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 08b8bc7360..fd44fc3715 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -337,7 +337,7 @@ namespace BizHawk.Client.EmuHawk if (index == Movie.Branches.Count) { - BranchView.ClearSelectedRows(); + BranchView.DeselectAll(); Select(Movie.Branches.Count - 1, true); }