diff --git a/PKHeX.WinForms/Subforms/SettingsEditor.Designer.cs b/PKHeX.WinForms/Subforms/SettingsEditor.Designer.cs index 314e98013..3d9cbca53 100644 --- a/PKHeX.WinForms/Subforms/SettingsEditor.Designer.cs +++ b/PKHeX.WinForms/Subforms/SettingsEditor.Designer.cs @@ -1,3 +1,6 @@ +using System.Windows.Forms; +using PKHeX.WinForms.Controls; + namespace PKHeX.WinForms { partial class SettingsEditor @@ -28,22 +31,28 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - FLP_Blank = new System.Windows.Forms.FlowLayoutPanel(); - L_Blank = new System.Windows.Forms.Label(); - CB_Blank = new System.Windows.Forms.ComboBox(); - tabControl1 = new System.Windows.Forms.TabControl(); - B_Reset = new System.Windows.Forms.Button(); + FLP_Blank = new FlowLayoutPanel(); + L_Blank = new Label(); + CB_Blank = new ComboBox(); + B_Reset = new Button(); + LB_Tabs = new ListBox(); + splitContainer1 = new SplitContainer(); + PG_Editor = new PropertyGrid(); FLP_Blank.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); + splitContainer1.Panel1.SuspendLayout(); + splitContainer1.Panel2.SuspendLayout(); + splitContainer1.SuspendLayout(); SuspendLayout(); // // FLP_Blank // FLP_Blank.Controls.Add(L_Blank); FLP_Blank.Controls.Add(CB_Blank); - FLP_Blank.Dock = System.Windows.Forms.DockStyle.Top; + FLP_Blank.Dock = DockStyle.Top; FLP_Blank.Location = new System.Drawing.Point(0, 0); FLP_Blank.Name = "FLP_Blank"; - FLP_Blank.Size = new System.Drawing.Size(494, 27); + FLP_Blank.Size = new System.Drawing.Size(584, 27); FLP_Blank.TabIndex = 1; // // L_Blank @@ -51,61 +60,91 @@ private void InitializeComponent() L_Blank.AutoSize = true; L_Blank.Location = new System.Drawing.Point(3, 0); L_Blank.Name = "L_Blank"; - L_Blank.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0); - L_Blank.Size = new System.Drawing.Size(107, 21); + L_Blank.Padding = new Padding(0, 6, 0, 0); + L_Blank.Size = new System.Drawing.Size(119, 23); L_Blank.TabIndex = 0; L_Blank.Text = "Blank Save Version:"; // // CB_Blank // - CB_Blank.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; - CB_Blank.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; + CB_Blank.AutoCompleteMode = AutoCompleteMode.SuggestAppend; + CB_Blank.AutoCompleteSource = AutoCompleteSource.ListItems; CB_Blank.FormattingEnabled = true; - CB_Blank.Location = new System.Drawing.Point(116, 3); + CB_Blank.Location = new System.Drawing.Point(128, 3); CB_Blank.Name = "CB_Blank"; - CB_Blank.Size = new System.Drawing.Size(180, 23); + CB_Blank.Size = new System.Drawing.Size(180, 25); CB_Blank.TabIndex = 1; // - // tabControl1 - // - tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; - tabControl1.Location = new System.Drawing.Point(0, 27); - tabControl1.Multiline = true; - tabControl1.Name = "tabControl1"; - tabControl1.SelectedIndex = 0; - tabControl1.Size = new System.Drawing.Size(494, 309); - tabControl1.SizeMode = System.Windows.Forms.TabSizeMode.FillToRight; - tabControl1.TabIndex = 3; - // // B_Reset // - B_Reset.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; - B_Reset.Location = new System.Drawing.Point(416, 2); + B_Reset.Anchor = AnchorStyles.Top | AnchorStyles.Right; + B_Reset.Location = new System.Drawing.Point(506, 2); B_Reset.Name = "B_Reset"; B_Reset.Size = new System.Drawing.Size(75, 23); B_Reset.TabIndex = 4; B_Reset.Text = "Reset All"; B_Reset.UseVisualStyleBackColor = true; // + // LB_Tabs + // + LB_Tabs.Dock = DockStyle.Fill; + LB_Tabs.FormattingEnabled = true; + LB_Tabs.Location = new System.Drawing.Point(0, 0); + LB_Tabs.Name = "LB_Tabs"; + LB_Tabs.Size = new System.Drawing.Size(194, 354); + LB_Tabs.TabIndex = 5; + LB_Tabs.SelectedIndexChanged += LB_Tabs_SelectedIndexChanged; + // + // splitContainer1 + // + splitContainer1.Dock = DockStyle.Fill; + splitContainer1.FixedPanel = FixedPanel.Panel1; + splitContainer1.Location = new System.Drawing.Point(0, 27); + splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + splitContainer1.Panel1.Controls.Add(LB_Tabs); + // + // splitContainer1.Panel2 + // + splitContainer1.Panel2.Controls.Add(PG_Editor); + splitContainer1.Size = new System.Drawing.Size(584, 354); + splitContainer1.SplitterDistance = 194; + splitContainer1.TabIndex = 6; + // + // PG_Editor + // + PG_Editor.BackColor = System.Drawing.SystemColors.Control; + PG_Editor.Dock = DockStyle.Fill; + PG_Editor.Location = new System.Drawing.Point(0, 0); + PG_Editor.Name = "PG_Editor"; + PG_Editor.Size = new System.Drawing.Size(386, 354); + PG_Editor.TabIndex = 0; + // // SettingsEditor // - AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; - ClientSize = new System.Drawing.Size(494, 336); + AutoScaleMode = AutoScaleMode.Inherit; + ClientSize = new System.Drawing.Size(584, 381); + Controls.Add(splitContainer1); Controls.Add(B_Reset); - Controls.Add(tabControl1); Controls.Add(FLP_Blank); - FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; + FormBorderStyle = FormBorderStyle.SizableToolWindow; Icon = Properties.Resources.Icon; KeyPreview = true; MaximizeBox = false; MinimizeBox = false; MinimumSize = new System.Drawing.Size(510, 375); Name = "SettingsEditor"; - StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + StartPosition = FormStartPosition.CenterParent; Text = "Settings"; KeyDown += SettingsEditor_KeyDown; FLP_Blank.ResumeLayout(false); FLP_Blank.PerformLayout(); + splitContainer1.Panel1.ResumeLayout(false); + splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); + splitContainer1.ResumeLayout(false); ResumeLayout(false); } @@ -114,7 +153,9 @@ private void InitializeComponent() private System.Windows.Forms.FlowLayoutPanel FLP_Blank; private System.Windows.Forms.Label L_Blank; private System.Windows.Forms.ComboBox CB_Blank; - private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.Button B_Reset; + private ListBox LB_Tabs; + private SplitContainer splitContainer1; + private PropertyGrid PG_Editor; } } diff --git a/PKHeX.WinForms/Subforms/SettingsEditor.cs b/PKHeX.WinForms/Subforms/SettingsEditor.cs index 26f75cafb..d2d15daea 100644 --- a/PKHeX.WinForms/Subforms/SettingsEditor.cs +++ b/PKHeX.WinForms/Subforms/SettingsEditor.cs @@ -13,7 +13,9 @@ public partial class SettingsEditor : Form public bool BlankChanged { get; private set; } // Remember the last settings tab for the remainder of the session. - private static string? Last; + private static string? _last; + + private readonly List _settingsPages = []; public SettingsEditor(object obj) { @@ -44,19 +46,24 @@ public SettingsEditor(object obj) B_Reset.Visible = false; } - if (Last is not null && tabControl1.Controls[Last] is TabPage tab) - tabControl1.SelectedTab = tab; - tabControl1.SelectedIndexChanged += (_, _) => Last = tabControl1.SelectedTab?.Name; + // Set the split container width based on the longest tab name, with a minimum width of 120 pixels. + var longestTabName = _settingsPages.Max(z => TextRenderer.MeasureText(z.Name, LB_Tabs.Font).Width); + splitContainer1.SplitterDistance = Math.Max(longestTabName + SystemInformation.VerticalScrollBarWidth + 2, 120); + + LB_Tabs.DisplayMember = nameof(SettingItem.Name); + LB_Tabs.ValueMember = nameof(SettingItem.Item); + LB_Tabs.DataSource = _settingsPages; + + if (_last is not null && _settingsPages.Find(z => z.Name == _last) is { } find) + LB_Tabs.SelectedItem = find; this.CenterToForm(FindForm()); } private void LoadSettings(object obj) { - var pages = new List(); var type = obj.GetType(); - var props = ReflectUtil.GetPropertiesCanWritePublicDeclared(type) - ; + var props = ReflectUtil.GetPropertiesCanWritePublicDeclared(type); foreach (var p in props) { var state = ReflectUtil.GetValue(obj, p); @@ -65,19 +72,12 @@ private void LoadSettings(object obj) var key = WinFormsTranslator.GetKey(nameof(SettingsEditor), p); var text = WinFormsTranslator.TranslateText(key, p, Main.CurrentLanguage); - var tab = new TabPage(text) { Name = $"Tab_{p}" }; - - var pg = new PropertyGrid { Dock = DockStyle.Fill }; - PropertyGridLocalization.Apply(pg, state, Main.CurrentLanguage); - tab.Controls.Add(pg); - pg.ExpandAllGridItems(); - - pages.Add(tab); + _settingsPages.Add(new SettingItem { Name = text, Item = state }); } - pages.Sort(static (a, b) => string.Compare(a.Text, b.Text, StringComparison.CurrentCulture)); - foreach (var tab in pages) - tabControl1.TabPages.Add(tab); + _settingsPages.Sort(static (a, b) => string.Compare(a.Name, b.Name, StringComparison.CurrentCulture)); + foreach (var page in _settingsPages) + LB_Tabs.Items.Add(page.Name); } private void SettingsEditor_KeyDown(object sender, KeyEventArgs e) @@ -104,4 +104,26 @@ private static void DeleteSettings() WinFormsUtil.Error("Failed to delete settings.", ex.Message); } } + + private void LB_Tabs_SelectedIndexChanged(object sender, EventArgs e) + { + var state = LB_Tabs.SelectedItem; + if (state is not SettingItem { Item: { } obj } item) + { + _last = null; + PG_Editor.Visible = false; + return; + } + + PropertyGridLocalization.Apply(PG_Editor, obj, Main.CurrentLanguage); + PG_Editor.ExpandAllGridItems(); + _last = item.Name; + PG_Editor.Visible = true; + } + + private class SettingItem + { + public required string Name { get; init; } + public required object Item { get; init; } + } }