//TODO: Make navigation functional for UI public void OnClose(InputAction.CallbackContext context) { //Debug.Log("Input: Close"); if (context.started) { CloseHeld = true; ClosePressed?.Invoke(); } else if (context.canceled) { CloseHeld = false; CloseReleased?.Invoke(); } }
private void SelectByKey(Keys keys, string keyInput = "", bool keepSelection = false) { int iRowBefore = iRowKey; int iMenuBefore = iMenuKey; Menu menu = menus[iMenuKey]; DataGridView dgv = null; DataGridView dgvBefore = null; Menu menuFromSelected = null; string textselected = string.Empty; bool isStillSelected = IsAnyMenuSelectedByKey(ref dgv, ref menuFromSelected, ref textselected); if (isStillSelected) { if (keepSelection) { // If current selection is still valid for this search then skip selecting different item if (textselected.StartsWith(keyInput, true, CultureInfo.InvariantCulture)) { return; } } dgvBefore = dgv; } else { ResetSelectedByKey(); menu = menus[iMenuKey]; dgv = menu.GetDataGridView(); } bool toClear = false; switch (keys) { case Keys.Enter: if (iRowKey > -1 && dgv.Rows.Count > iRowKey) { RowData trigger = (RowData)dgv.Rows[iRowKey].Cells[2].Value; if (trigger.IsMenuOpen || !trigger.ContainsMenu) { trigger.MouseDown(dgv, null); trigger.DoubleClick( new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0)); } else { RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); EnterPressed.Invoke(dgv, iRowKey); } } break; case Keys.Up: if (SelectMatchedReverse(dgv, iRowKey) || SelectMatchedReverse(dgv, dgv.Rows.Count - 1)) { RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } break; case Keys.Down: if (SelectMatched(dgv, iRowKey) || SelectMatched(dgv, 0)) { RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } break; case Keys.Left: int iMenuKeyNext = iMenuKey + 1; if (isStillSelected) { if (menuFromSelected != null && menuFromSelected == menus[iMenuKeyNext]) { dgv = menuFromSelected.GetDataGridView(); if (dgv.Rows.Count > 0) { iMenuKey += 1; iRowKey = -1; if (SelectMatched(dgv, iRowKey) || SelectMatched(dgv, 0)) { RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } } } } else { iRowKey = -1; iMenuKey = menus.Where(m => m != null).Count() - 1; if (menus[iMenuKey] != null) { dgv = menus[iMenuKey].GetDataGridView(); if (SelectMatched(dgv, iRowKey) || SelectMatched(dgv, 0)) { RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } } } break; case Keys.Right: if (iMenuKey > 0) { if (menus[iMenuKey - 1] != null) { iMenuKey -= 1; iRowKey = -1; menu = menus[iMenuKey]; dgv = menu.GetDataGridView(); if (SelectMatched(dgv, dgv.SelectedRows[0].Index) || SelectMatched(dgv, 0)) { RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } } } else { RowDeselected(iRowBefore, dgvBefore); iMenuKey = 0; iRowKey = -1; toClear = true; Cleared?.Invoke(); } break; case Keys.Escape: RowDeselected(iRowBefore, dgvBefore); iMenuKey = 0; iRowKey = -1; toClear = true; ClosePressed?.Invoke(); break; default: if (!string.IsNullOrEmpty(keyInput)) { if (SelectMatched(dgv, iRowKey, keyInput) || SelectMatched(dgv, 0, keyInput)) { RowDeselected(iRowBefore, null); SelectRow(dgv, iRowKey); toClear = true; } else if (isStillSelected) { iRowKey = iRowBefore - 1; if (SelectMatched(dgv, iRowKey, keyInput) || SelectMatched(dgv, 0, keyInput)) { RowDeselected(iRowBefore, null); SelectRow(dgv, iRowKey); } else { iRowKey = iRowBefore; } } } break; } if (isStillSelected && toClear) { ClearIsSelectedByKey(iMenuBefore, iRowBefore); } }