mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Merge pull request #2921 from mRemoteNG/copilot/fix-options-freezing-issue
[WIP] Fix freezing issue when opening and closing Options
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;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace mRemoteNG.UI.Window
|
||||
public partial class OptionsWindow : BaseWindow
|
||||
{
|
||||
private FrmOptions _optionsForm;
|
||||
private bool _isInitialized = false;
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -34,8 +35,14 @@ namespace mRemoteNG.UI.Window
|
||||
|
||||
private void Options_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Only subscribe to ThemeChanged once to prevent multiple subscriptions
|
||||
if (!_isInitialized)
|
||||
{
|
||||
ThemeManager.getInstance().ThemeChanged += ApplyTheme;
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
ApplyTheme();
|
||||
ThemeManager.getInstance().ThemeChanged += ApplyTheme;
|
||||
ApplyLanguage();
|
||||
LoadOptionsForm();
|
||||
}
|
||||
|
||||
@@ -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