mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 14:07:46 +08:00
Merge pull request #2919 from mRemoteNG/copilot/fix-empty-option-panel
Fix empty Options panel when Theme is canceled
This commit is contained in:
@@ -18,6 +18,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages
|
||||
|
||||
private readonly ThemeManager _themeManager;
|
||||
private readonly bool _oriActiveTheming;
|
||||
private ThemeInfo _oriActiveTheme;
|
||||
private readonly List<ThemeInfo> modifiedThemes = [];
|
||||
|
||||
#endregion
|
||||
@@ -65,6 +66,8 @@ namespace mRemoteNG.UI.Forms.OptionsPages
|
||||
// ReSharper disable once CoVariantArrayConversion
|
||||
cboTheme.Items.AddRange(_themeManager.LoadThemes().OrderBy(x => x.Name).ToArray());
|
||||
cboTheme.SelectedItem = _themeManager.ActiveTheme;
|
||||
// Store the original active theme for reverting
|
||||
_oriActiveTheme = _themeManager.ActiveTheme;
|
||||
cboTheme_SelectionChangeCommitted(this, new EventArgs());
|
||||
cboTheme.DisplayMember = "Name";
|
||||
|
||||
@@ -107,6 +110,20 @@ namespace mRemoteNG.UI.Forms.OptionsPages
|
||||
{
|
||||
base.RevertSettings();
|
||||
_themeManager.ThemingActive = _oriActiveTheming;
|
||||
|
||||
// Clear the modified themes list without saving
|
||||
modifiedThemes.Clear();
|
||||
|
||||
// Restore the original theme selection
|
||||
if (_oriActiveTheme != null)
|
||||
{
|
||||
_themeManager.ActiveTheme = _oriActiveTheme;
|
||||
// Reload the theme list to reflect the original state
|
||||
cboTheme.Items.Clear();
|
||||
cboTheme.Items.AddRange(_themeManager.LoadThemes().OrderBy(x => x.Name).ToArray());
|
||||
cboTheme.SelectedItem = _oriActiveTheme;
|
||||
cboTheme_SelectionChangeCommitted(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
#region Private Methods
|
||||
|
||||
@@ -79,7 +79,20 @@ namespace mRemoteNG.UI.Forms
|
||||
//ThemeManager.getInstance().ThemeChanged += ApplyTheme;
|
||||
lstOptionPages.SelectedIndexChanged += LstOptionPages_SelectedIndexChanged;
|
||||
lstOptionPages.SelectedIndex = 0;
|
||||
_isInitialized = true;
|
||||
|
||||
// Handle visibility changes to ensure panel is populated when form is shown
|
||||
this.VisibleChanged += FrmOptions_VisibleChanged;
|
||||
}
|
||||
|
||||
private void FrmOptions_VisibleChanged(object sender, EventArgs e)
|
||||
{
|
||||
// When the form becomes visible, ensure the panel is populated with the selected page
|
||||
if (this.Visible && pnlMain.Controls.Count == 0)
|
||||
{
|
||||
OptionsPage page = (OptionsPage)lstOptionPages.SelectedObject;
|
||||
if (page != null)
|
||||
pnlMain.Controls.Add(page);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyTheme()
|
||||
@@ -278,6 +291,11 @@ namespace mRemoteNG.UI.Forms
|
||||
|
||||
private void BtnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Revert settings for all pages when Cancel is clicked
|
||||
foreach (OptionsPage page in _optionPages)
|
||||
{
|
||||
page.RevertSettings();
|
||||
}
|
||||
this.Visible = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user