From e1f439534dc23bbe0ee299452d036c617b1bf1da Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Tue, 2 Apr 2024 13:00:57 +0100 Subject: [PATCH] Refactor text change notifications in NikseComboBox The previous implementation of the text change notifications and value change events in NikseComboBox was repetitive and cluttered. This commit streamlines that by introducing a new method, NotifyTextChanged(), that handles these events. The new approach contributes to code maintainability and readability. Signed-off-by: Ivandro Jao --- src/ui/Controls/NikseComboBox.cs | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/ui/Controls/NikseComboBox.cs b/src/ui/Controls/NikseComboBox.cs index b68b75bc2..6b068d1c0 100644 --- a/src/ui/Controls/NikseComboBox.cs +++ b/src/ui/Controls/NikseComboBox.cs @@ -107,12 +107,7 @@ namespace Nikse.SubtitleEdit.Controls _selectedIndex = value; _textBox.Text = string.Empty; - if (!_loading) - { - SelectedIndexChanged?.Invoke(this, EventArgs.Empty); - SelectedValueChanged?.Invoke(this, EventArgs.Empty); - TextChanged?.Invoke(this, EventArgs.Empty); - } + NotifyTextChanged(); if (!_skipPaint) { @@ -138,9 +133,7 @@ namespace Nikse.SubtitleEdit.Controls _listView.Items[_selectedIndex].Focused = true; } - SelectedIndexChanged?.Invoke(this, EventArgs.Empty); - SelectedValueChanged?.Invoke(this, EventArgs.Empty); - TextChanged?.Invoke(this, EventArgs.Empty); + NotifyTextChanged(); } if (!_skipPaint) @@ -1025,13 +1018,7 @@ namespace Nikse.SubtitleEdit.Controls Invalidate(); } - if (!_loading) - { - SelectedIndexChanged?.Invoke(this, EventArgs.Empty); - SelectedValueChanged?.Invoke(this, EventArgs.Empty); - TextChanged?.Invoke(this, EventArgs.Empty); - } - + NotifyTextChanged(); } else { @@ -1060,12 +1047,7 @@ namespace Nikse.SubtitleEdit.Controls _textBox.Focus(); _textBox.SelectionLength = 0; - if (!_loading) - { - SelectedIndexChanged?.Invoke(this, EventArgs.Empty); - SelectedValueChanged?.Invoke(this, EventArgs.Empty); - TextChanged?.Invoke(this, EventArgs.Empty); - } + NotifyTextChanged(); return; }