Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up mod list spacebar handling in GUI #2543

Merged
merged 1 commit into from Oct 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 26 additions & 29 deletions GUI/MainModList.cs
Expand Up @@ -289,26 +289,39 @@ private void ModList_HeaderMouseClick(object sender, DataGridViewCellMouseEventA
/// </summary>
private void ModList_KeyDown(object sender, KeyEventArgs e)
{
DataGridViewCell cell = null;
switch (e.KeyCode)
{
case Keys.Home:
// First row.
cell = ModList.Rows[0].Cells[2];
ModList.CurrentCell = ModList.Rows[0].Cells[2];
e.Handled = true;
break;

case Keys.End:
// Last row.
cell = ModList.Rows[ModList.Rows.Count - 1].Cells[2];
ModList.CurrentCell = ModList.Rows[ModList.Rows.Count - 1].Cells[2];
e.Handled = true;
break;
}

if (cell != null)
{
e.Handled = true;

// Selects the top/bottom row and scrolls the list to it.
ModList.CurrentCell = cell;
case Keys.Space:
// If they've focused one of the checkbox columns, don't intercept
if (ModList.CurrentCell.ColumnIndex > 1)
{
DataGridViewRow row = ModList.CurrentRow;
// Toggle Update column if enabled, otherwise Install
for (int colIndex = 1; colIndex >= 0; --colIndex)
{
if (row?.Cells[colIndex] is DataGridViewCheckBoxCell)
{
// Need to change the state here, because the user hasn't clicked on a checkbox
row.Cells[colIndex].Value = !(bool)row.Cells[colIndex].Value;
ModList.CommitEdit(DataGridViewDataErrorContexts.Commit);
e.Handled = true;
break;
}
}
}
break;
}
}

Expand All @@ -321,29 +334,13 @@ private void ModList_KeyDown(object sender, KeyEventArgs e)
/// </summary>
private void ModList_KeyPress(object sender, KeyPressEventArgs e)
{
var current_row = ModList.CurrentRow;
var key = e.KeyChar.ToString();

// Check the key. If it is space and the current row is selected, mark the current mod as selected.
if (key == " ")
// Don't search for spaces or newlines
if (e.KeyChar == (char)Keys.Space || e.KeyChar == (char)Keys.Enter)
{
if (current_row != null && current_row.Selected)
{
var gui_mod = (GUIMod)current_row.Tag;
if (gui_mod.IsInstallable())
MarkModForInstall(gui_mod.Identifier, gui_mod.IsInstallChecked);
}

e.Handled = true;
return;
}

if (e.KeyChar == (char)Keys.Enter)
{
// Don't try to search for newlines.
return;
}

var key = e.KeyChar.ToString();
// Determine time passed since last key press.
TimeSpan interval = DateTime.Now - lastSearchTime;
if (interval.TotalSeconds < 1)
Expand Down