Skip to content

Commit

Permalink
* Refactored the events for handling validation of the user input to …
Browse files Browse the repository at this point in the history
…use Validation events.
  • Loading branch information
DrWhoCares committed Jul 4, 2019
1 parent eb1bdc6 commit 3a9b8af
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 129 deletions.
24 changes: 14 additions & 10 deletions TranslationScriptMaker/TranslationScriptMaker/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 104 additions & 35 deletions TranslationScriptMaker/TranslationScriptMaker/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public partial class MainForm : Form
private const string CONFIG_FILENAME = "TSMConfig.txt";
private const char CFG_DELIMITER = '=';
private const string CFG_TRANSLATOR_NAME = "Translator=";

private bool WasRawsLocationVerified { get; set; }
private bool WasOutputLocationVerified { get; set; }
private bool WasTranslatorNameVerified { get; set; }
private bool WasChapterNameVerified { get; set; }
private bool WasScriptLocationVerified { get; set; }
private bool WasEditingRawsLocationVerified { get; set; }
private string OutputLocationFullPath { get; set; }
private string TranslatorName { get; set; }
private string ScriptLocationFullPath { get; set; }
Expand Down Expand Up @@ -100,13 +107,24 @@ private void RawsLocationButton_MouseClick(object sender, MouseEventArgs e)
if ( rawsLocationDialog.ShowDialog() == CommonFileDialogResult.Ok )
{
RawsLocationTextBox.Text = rawsLocationDialog.FileName;
WasRawsLocationVerified = VerifyRawsLocation(RawsLocationTextBox);
}
}
}

private void RawsLocationTextBox_TextChanged(object sender, System.EventArgs e)
private void RawsLocationTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = !VerifyRawsLocation(RawsLocationTextBox);

if ( e.Cancel )
{
WasRawsLocationVerified = false;
}
}

private void RawsLocationTextBox_Validated(object sender, EventArgs e)
{
BeginScriptCreationButton.Enabled = AreScriptCreationInputsValid();
WasRawsLocationVerified = true;
}

private void OutputLocationButton_MouseClick(object sender, MouseEventArgs e)
Expand All @@ -119,66 +137,83 @@ private void OutputLocationButton_MouseClick(object sender, MouseEventArgs e)
if ( outputLocationDialog.ShowDialog() == CommonFileDialogResult.Ok )
{
OutputLocationTextBox.Text = outputLocationDialog.FileName;
WasOutputLocationVerified = VerifyOutputLocation();
}
}

private void OutputLocationTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = !VerifyOutputLocation();

if ( e.Cancel )
{
WasOutputLocationVerified = false;
}
}

private void OutputLocationTextBox_TextChanged(object sender, EventArgs e)
private void OutputLocationTextBox_Validated(object sender, EventArgs e)
{
BeginScriptCreationButton.Enabled = AreScriptCreationInputsValid();
WasOutputLocationVerified = true;
}

private void TranslatorNameTextBox_KeyDown(object sender, KeyEventArgs e)
private void TranslatorNameTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if ( e.KeyCode == Keys.Enter )
e.Cancel = !VerifyTranslatorName();

if ( e.Cancel )
{
if ( AreScriptCreationInputsValid() )
{
BeginScriptCreation();
}
WasTranslatorNameVerified = false;
}
}

private void TranslatorNameTextBox_TextChanged(object sender, EventArgs e)
private void TranslatorNameTextBox_Validated(object sender, EventArgs e)
{
BeginScriptCreationButton.Enabled = AreScriptCreationInputsValid();
WasTranslatorNameVerified = true;
}

private void ChapterNumberTextBox_KeyDown(object sender, KeyEventArgs e)
private void ChapterNumberTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if ( e.KeyCode == Keys.Enter )
e.Cancel = !VerifyChapterNumber();

if ( e.Cancel )
{
if ( AreScriptCreationInputsValid() )
{
BeginScriptCreation();
}
WasChapterNameVerified = false;
}
}

private void ChapterNumberTextBox_TextChanged(object sender, EventArgs e)
private void ChapterNumberTextBox_Validated(object sender, EventArgs e)
{
BeginScriptCreationButton.Enabled = AreScriptCreationInputsValid();
WasChapterNameVerified = true;
}

private void BeginScriptCreationButton_MouseClick(object sender, MouseEventArgs e) => BeginScriptCreation();
private void BeginScriptCreationButton_MouseClick(object sender, MouseEventArgs e)
{
this.ValidateChildren();

if ( AreScriptCreationInputsValid() )
{
BeginScriptCreation();
}
}

private bool AreScriptCreationInputsValid()
{
if ( !VerifyRawsLocation(RawsLocationTextBox) )
if ( !WasRawsLocationVerified )
{
return false;
}

if ( !VerifyOutputLocation() )
if ( !WasOutputLocationVerified )
{
return false;
}

if ( !VerifyTranslatorName() )
if ( !WasTranslatorNameVerified )
{
return false;
}

if ( !VerifyChapterNumber() )
if ( !WasChapterNameVerified )
{
return false;
}
Expand Down Expand Up @@ -338,13 +373,24 @@ private void ScriptLocationButton_MouseClick(object sender, MouseEventArgs e)
}

ScriptLocationTextBox.Text = scriptLocationDialog.FileName;
}
WasScriptLocationVerified = VerifyScriptLocation();
}
}

private void ScriptLocationTextBox_TextChanged(object sender, EventArgs e)
{
BeginScriptEditingButton.Enabled = AreScriptEditingInputsValid();
}
private void ScriptLocationTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = !VerifyScriptLocation();

if ( e.Cancel )
{
WasScriptLocationVerified = false;
}
}

private void ScriptLocationTextBox_Validated(object sender, EventArgs e)
{
WasScriptLocationVerified = true;
}

private void ScriptEditingRawsLocationButton_MouseClick(object sender, MouseEventArgs e)
{
Expand All @@ -357,25 +403,44 @@ private void ScriptEditingRawsLocationButton_MouseClick(object sender, MouseEven
if ( rawsLocationDialog.ShowDialog() == CommonFileDialogResult.Ok )
{
ScriptEditingRawsLocationTextBox.Text = rawsLocationDialog.FileName;
WasEditingRawsLocationVerified = VerifyRawsLocation(ScriptEditingRawsLocationTextBox);
}
}
}

private void ScriptEditingRawsLocationTextBox_TextChanged(object sender, EventArgs e)
private void ScriptEditingRawsLocationTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
BeginScriptEditingButton.Enabled = AreScriptEditingInputsValid();
e.Cancel = !VerifyRawsLocation(ScriptEditingRawsLocationTextBox);

if ( e.Cancel )
{
WasEditingRawsLocationVerified = false;
}
}

private void BeginScriptEditingButton_MouseClick(object sender, MouseEventArgs e) => BeginScriptEditing();
private void ScriptEditingRawsLocationTextBox_Validated(object sender, EventArgs e)
{
WasEditingRawsLocationVerified = true;
}

private void BeginScriptEditingButton_MouseClick(object sender, MouseEventArgs e)
{
this.ValidateChildren();

if ( AreScriptEditingInputsValid() )
{
BeginScriptEditing();
}
}

private bool AreScriptEditingInputsValid()
{
if ( !VerifyScriptLocation() )
if ( !WasScriptLocationVerified )
{
return false;
}

if ( !VerifyRawsLocation(ScriptEditingRawsLocationTextBox) )
if ( !WasEditingRawsLocationVerified )
{
return false;
}
Expand Down Expand Up @@ -439,5 +504,9 @@ private void BeginScriptEditing()
this.Show();
}
#endregion




}
}
Loading

0 comments on commit 3a9b8af

Please sign in to comment.