private void addFlagOverride(FVariable flag, bool init = false) { string key = flag.Key; if (!overrideRowLookup.ContainsKey(key)) { RegistryKey editor = flagRegistry.GetSubKey(key); flag.SetEditor(editor); if (!init && flag.Type.EndsWith("Flag", Program.StringFormat) && !flag.Custom) { if (bool.TryParse(flag.Value, out bool value)) { string str = (!value) .ToString(Program.Format) .ToLower(Program.Format); flag.SetValue(str); } } DataRow row = overrideTable.Rows.Add ( flag.Name, flag.Type, flag.Value.ToLower(Program.Format) ); overrideRowLookup.Add(key, row); } overrideStatus.Text = OVERRIDE_STATUS_ON; overrideStatus.ForeColor = Color.Red; if (!init) { // Find the row that corresponds to the flag we added. var query = overrideDataGridView.Rows .Cast <DataGridViewRow>() .Where(rowMatchesSelectedRow); if (query.Any()) { // Select it. var overrideRow = query.First(); overrideDataGridView.CurrentCell = overrideRow.Cells[0]; } // Clear last custom flag. lastCustomFlag = null; // Switch to the overrides tab. tabs.SelectedTab = overridesTab; } }
private void overrideDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = overrideDataGridView.Rows[e.RowIndex]; string flagKey = getFlagKeyByRow(row); DataGridViewCell cell = row.Cells[e.ColumnIndex]; string value = cell.Value as string; var cells = row.Cells; var flagType = cells[1].Value as string; // Check if this input should be cancelled. var format = Program.StringFormat; bool badInput = false; if (flagType.EndsWith("Flag", format)) { string test = value .ToUpperInvariant() .Trim(); badInput = (test != "FALSE" && test != "TRUE"); } else if (flagType.EndsWith("Int", format)) { badInput = !int.TryParse(value, out int _); } else if (flagType.EndsWith("Log", format)) { badInput = !byte.TryParse(value, out byte _); } if (flagLookup.ContainsKey(flagKey)) { int index = flagLookup[flagKey]; FVariable flag = flags[index]; if (!badInput) { flag.SetValue(value); return; } // If we have bad input, reset the value to the original value. cell.Value = flag.Reset; } }