mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Fix Options dialog freezing when opening/closing multiple times
- Add _isInitialized flag to prevent multiple event subscriptions - Skip re-initialization in FrmOptions_Load when form is reused - Properly clean up Application.Idle handler in FormClosing - Add test to verify form can be shown/hidden multiple times Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,7 @@ namespace mRemoteNG.UI.Forms
|
||||
private string _pageName;
|
||||
private readonly DisplayProperties _display = new();
|
||||
private readonly List<string> _optionPageObjectNames;
|
||||
private bool _isInitialized = false;
|
||||
|
||||
public FrmOptions() : this(Language.StartupExit)
|
||||
{
|
||||
@@ -57,6 +58,13 @@ namespace mRemoteNG.UI.Forms
|
||||
|
||||
private void FrmOptions_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Only initialize once to prevent multiple event subscriptions and page reloading
|
||||
if (_isInitialized)
|
||||
{
|
||||
this.Visible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this.Visible = true;
|
||||
FontOverrider.FontOverride(this);
|
||||
SetActivatedPage();
|
||||
@@ -71,6 +79,7 @@ namespace mRemoteNG.UI.Forms
|
||||
//ThemeManager.getInstance().ThemeChanged += ApplyTheme;
|
||||
lstOptionPages.SelectedIndexChanged += LstOptionPages_SelectedIndexChanged;
|
||||
lstOptionPages.SelectedIndex = 0;
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
private void ApplyTheme()
|
||||
@@ -274,6 +283,9 @@ namespace mRemoteNG.UI.Forms
|
||||
|
||||
private void FrmOptions_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
// Ensure Application.Idle handler is removed if still attached
|
||||
Application.Idle -= Application_Idle;
|
||||
|
||||
e.Cancel = true;
|
||||
this.Visible = false;
|
||||
}
|
||||
|
||||
@@ -33,5 +33,32 @@ namespace mRemoteNGTests.UI.Forms
|
||||
ListViewTester listViewTester = new("lstOptionPages", _optionsForm);
|
||||
Assert.That(listViewTester.Items.Count, Is.EqualTo(12));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FormCanBeHiddenAndShownMultipleTimes()
|
||||
{
|
||||
// First show (already done in Setup)
|
||||
Assert.That(_optionsForm.Visible, Is.True);
|
||||
|
||||
// Hide the form
|
||||
_optionsForm.Hide();
|
||||
Assert.That(_optionsForm.Visible, Is.False);
|
||||
|
||||
// Show it again
|
||||
_optionsForm.Show();
|
||||
Assert.That(_optionsForm.Visible, Is.True);
|
||||
|
||||
// Verify pages are still loaded correctly
|
||||
ListViewTester listViewTester = new("lstOptionPages", _optionsForm);
|
||||
Assert.That(listViewTester.Items.Count, Is.EqualTo(12));
|
||||
|
||||
// Hide and show one more time
|
||||
_optionsForm.Hide();
|
||||
_optionsForm.Show();
|
||||
Assert.That(_optionsForm.Visible, Is.True);
|
||||
|
||||
// Verify pages are still there
|
||||
Assert.That(listViewTester.Items.Count, Is.EqualTo(12));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user