From e005c31cb21b3cff6c9eaf2072d0b3cf54150de5 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 3 Jun 2023 19:15:45 +0200 Subject: [PATCH] PckManager - Prevented re-creating same panel --- PCK-Studio/Features/PckManager.Designer.cs | 2 +- PCK-Studio/Features/PckManager.cs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/PCK-Studio/Features/PckManager.Designer.cs b/PCK-Studio/Features/PckManager.Designer.cs index 9d06e8dc..61f06c53 100644 --- a/PCK-Studio/Features/PckManager.Designer.cs +++ b/PCK-Studio/Features/PckManager.Designer.cs @@ -76,7 +76,7 @@ this.supportedPlatformComboBox.TabIndex = 0; this.supportedPlatformComboBox.Theme = MetroFramework.MetroThemeStyle.Dark; this.supportedPlatformComboBox.UseSelectable = true; - this.supportedPlatformComboBox.SelectedIndexChanged += new System.EventHandler(this.supportedPlatformComboBox_SelectedIndexChanged); + this.supportedPlatformComboBox.SelectionChangeCommitted += new System.EventHandler(this.supportedPlatformComboBox_SelectionChangeCommitted); // // mainPanel // diff --git a/PCK-Studio/Features/PckManager.cs b/PCK-Studio/Features/PckManager.cs index a533ba84..41f72ac8 100644 --- a/PCK-Studio/Features/PckManager.cs +++ b/PCK-Studio/Features/PckManager.cs @@ -23,6 +23,7 @@ namespace PckStudio.Features public partial class PckManager : MetroFramework.Forms.MetroForm { private Control currentlyShowingControl; + private string currentlyShowingControlName; private const string CemU = "Cemu"; // TODO: Implement these Panels @@ -49,22 +50,22 @@ namespace PckStudio.Features currentlyShowingControl?.Focus(); } - private void supportedPlatformComboBox_SelectedIndexChanged(object sender, EventArgs e) + private void supportedPlatformComboBox_SelectionChangeCommitted(object sender, EventArgs e) { - mainPanel.Controls.Remove(currentlyShowingControl); - if (supportedPlatformComboBox.SelectedIndex > -1) + if (!supportedPlatformComboBox.SelectedItem.Equals(currentlyShowingControlName)) { - string text = supportedPlatformComboBox.Items[supportedPlatformComboBox.SelectedIndex].ToString(); + mainPanel.Controls.Remove(currentlyShowingControl); + currentlyShowingControlName = supportedPlatformComboBox.Items[supportedPlatformComboBox.SelectedIndex].ToString(); try { - currentlyShowingControl = text switch + currentlyShowingControl = currentlyShowingControlName switch { CemU => new CemuPanel(), //WiiU => new WiiUPanel(), //PS3 => throw new NotImplementedException($"{text}-Panel is currently not implemented."), //PSVita => throw new NotImplementedException($"{text}-Panel is currently not implemented."), //RPCS3 => throw new NotImplementedException($"{text}-Panel is currently not implemented."), - _ => throw new Exception($"No Panel found for: {text}"), + _ => throw new Exception($"No Panel found for: {currentlyShowingControlName}"), }; currentlyShowingControl.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right; mainPanel.SetColumnSpan(currentlyShowingControl, 2);