private void tRankName_Validating( object sender, CancelEventArgs e )
{
tRankName.ForeColor = SystemColors.ControlText;
if ( selectedRank == null )
return;
string newName = tRankName.Text.Trim();
if ( newName == selectedRank.Name ) {
return;
} else if ( newName.Length == 0 ) {
MessageBox.Show( "Rank name cannot be blank." );
tRankName.ForeColor = System.Drawing.Color.Red;
e.Cancel = true;
} else if ( !Rank.IsValidRankName( newName ) ) {
MessageBox.Show( "Rank name can only contain letters, digits, and underscores." );
tRankName.ForeColor = System.Drawing.Color.Red;
e.Cancel = true;
} else if ( !RankManager.CanRenameRank( selectedRank, newName ) ) {
MessageBox.Show( "There is already another rank named \"" + newName + "\".\n" +
"Duplicate rank names are not allowed." );
tRankName.ForeColor = System.Drawing.Color.Red;
e.Cancel = true;
} else {
string oldName = MainForm.ToComboBoxOption( selectedRank );
// To avoid DataErrors in World tab's DataGridView while renaming a rank,
// the new name is first added to the list of options (without removing the old name)
rankNameList.Insert( selectedRank.Index + 1, String.Format( "{0,1}{1}", selectedRank.Prefix, newName ) );
RankManager.RenameRank( selectedRank, newName );
// Remove the old name from the list of options
rankNameList.Remove( oldName );
Worlds.ResetBindings();
RebuildRankList();
}
}