diff --git a/src/ImportFileControl.cs b/src/ImportFileControl.cs index 6bb9639fafb73a17b39d5b62d46d829a3d8658db..4b7326be3a391727caf4559442a51906f6ce70e9 100644 --- a/src/ImportFileControl.cs +++ b/src/ImportFileControl.cs @@ -14,7 +14,10 @@ namespace TournamentManager.src } } - public Delegate TbChangedDelegate; + public event EventHandler LoadFileSelected; + + protected void OnTbTextChanged(EventArgs e) => LoadFileSelected?.Invoke(this, e); + public ImportFileControl() { InitializeComponent(); @@ -31,9 +34,9 @@ namespace TournamentManager.src SelectedPath = dialog.FileName; } - private void tbPath_TextChanged(object sender, System.EventArgs e) + private void tbPath_TextChanged(object sender, EventArgs e) { - TbChangedDelegate.DynamicInvoke(); + OnTbTextChanged(e); } } } \ No newline at end of file diff --git a/src/LoadFileForm.cs b/src/LoadFileForm.cs index 91dcf423d234b154f89842d27d5da72cabd70314..4f177e94901995494ad47f4645d96efed97d9ac6 100644 --- a/src/LoadFileForm.cs +++ b/src/LoadFileForm.cs @@ -9,19 +9,13 @@ namespace TournamentManager.src { public string PathToFile { get; private set; } private readonly string _relativeLocalPath; - - public delegate void Functional(); - - private event Functional TbChangedEvent; public LoadFileForm(string relativeLocalPath) { InitializeComponent(); _relativeLocalPath = relativeLocalPath; - - TbChangedEvent += new Functional(LoadFileChosen); - importFileControl.TbChangedDelegate = TbChangedEvent; + importFileControl.LoadFileSelected += HandleLoadFileSelected; var directoryInfo = new DirectoryInfo(_relativeLocalPath); foreach (var file in directoryInfo.GetFiles("*.json")) @@ -31,6 +25,16 @@ namespace TournamentManager.src btnLoad.Enabled = false; } + private void HandleLoadFileSelected(object sender, EventArgs e) + { + if (importFileControl.SelectedPath.Length > 0 || cbSavedTournaments.SelectedIndex > -1) + { + btnLoad.Enabled = true; + return; + } + btnLoad.Enabled = false; + } + private void btnCancel_Click(object sender, System.EventArgs e) { DialogResult = DialogResult.Cancel; @@ -57,17 +61,7 @@ namespace TournamentManager.src private void cbSavedTournaments_SelectedIndexChanged(object sender, EventArgs e) { - TbChangedEvent?.Invoke(); - } - - private void LoadFileChosen() - { - if (importFileControl.SelectedPath.Length > 0 || cbSavedTournaments.SelectedIndex > -1) - { - btnLoad.Enabled = true; - return; - } - btnLoad.Enabled = false; + HandleLoadFileSelected(this, e); } } } \ No newline at end of file