Skip to content

Commit

Permalink
Profile editor Trim long names on Copy\Paste
Browse files Browse the repository at this point in the history
  • Loading branch information
LIPtoH committed Oct 23, 2020
1 parent cffbea3 commit 2a2a6b9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions TS SE Tool/Forms/ProfileEditor/FormProfileEditorRenameClone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void textBoxNewName_KeyDown(object sender, KeyEventArgs e)
{
if (textBoxNewName.Text.Length == 0) return;

if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Back || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right || e.KeyCode == Keys.Home || e.KeyCode == Keys.End || e.KeyCode == Keys.Delete)
if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Back || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Home || e.KeyCode == Keys.End || e.KeyCode == Keys.PageDown || e.KeyCode == Keys.PageUp || e.KeyCode == Keys.Delete)
{
e.Handled = false;
aboveLimitLength = false;
Expand Down Expand Up @@ -161,6 +161,30 @@ private void textBoxNewName_KeyPress(object sender, KeyPressEventArgs e)

private void textBoxNewName_TextChanged(object sender, EventArgs e)
{
//Trim on paste
if (textBoxNewName.Multiline)
{
int linecount = textBoxNewName.Lines.Length;

var tmpLines = textBoxNewName.Lines;

for (int i = 0; i < linecount; i++)
{
if(textBoxNewName.Lines[i].Length > NameLengthLimit)
{
tmpLines[i] = textBoxNewName.Lines[i].Substring(0, NameLengthLimit);
}

textBoxNewName.Lines = tmpLines;
}
}
else
{
if (textBoxNewName.Text.Length > NameLengthLimit)
textBoxNewName.Text = textBoxNewName.Text.Substring(0, NameLengthLimit);
}

//
calculateTextBoxNewNameSize();

indicateCharLimit();
Expand Down Expand Up @@ -492,7 +516,7 @@ private void indicateCharLimit()
labelCharCountLimit.ForeColor = Color.Red;
labelCharCountLimit.Font = new Font(labelCharCountLimit.Font, FontStyle.Bold);
}
else if (txtLength == NameLengthLimit)
else if (txtLength >= NameLengthLimit)
{
labelCharCountLimit.ForeColor = Color.Red;
labelCharCountLimit.Font = new Font(labelCharCountLimit.Font, FontStyle.Bold);
Expand Down

0 comments on commit 2a2a6b9

Please sign in to comment.