diff --git a/I18N Commander/UI WinForms/Components/Setting.Designer.cs b/I18N Commander/UI WinForms/Components/Setting.Designer.cs index 7548387..f183b05 100644 --- a/I18N Commander/UI WinForms/Components/Setting.Designer.cs +++ b/I18N Commander/UI WinForms/Components/Setting.Designer.cs @@ -1,6 +1,6 @@ namespace UI_WinForms.Components { - partial class Setting + partial class Setting { /// /// Required designer variable. @@ -29,7 +29,6 @@ private void InitializeComponent() { this.tableLayout = new System.Windows.Forms.TableLayoutPanel(); - this.buttonSave = new System.Windows.Forms.Button(); this.labelExplanation = new System.Windows.Forms.Label(); this.labelSettingName = new System.Windows.Forms.Label(); this.labelIcon = new System.Windows.Forms.Label(); @@ -38,13 +37,12 @@ // // tableLayout // - this.tableLayout.ColumnCount = 5; + this.tableLayout.ColumnCount = 4; this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 66F)); this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 250F)); this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 220F)); this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 120F)); - this.tableLayout.Controls.Add(this.buttonSave, 4, 0); + this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayout.Controls.Add(this.labelExplanation, 3, 0); this.tableLayout.Controls.Add(this.labelSettingName, 1, 0); this.tableLayout.Controls.Add(this.labelIcon, 0, 0); @@ -57,24 +55,13 @@ this.tableLayout.Size = new System.Drawing.Size(1264, 70); this.tableLayout.TabIndex = 0; // - // buttonSave - // - this.buttonSave.Dock = System.Windows.Forms.DockStyle.Fill; - this.buttonSave.Location = new System.Drawing.Point(1147, 3); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(114, 64); - this.buttonSave.TabIndex = 0; - this.buttonSave.Text = "Save"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); - // // labelExplanation // this.labelExplanation.AutoSize = true; this.labelExplanation.Dock = System.Windows.Forms.DockStyle.Fill; this.labelExplanation.Location = new System.Drawing.Point(539, 0); this.labelExplanation.Name = "labelExplanation"; - this.labelExplanation.Size = new System.Drawing.Size(602, 70); + this.labelExplanation.Size = new System.Drawing.Size(722, 70); this.labelExplanation.TabIndex = 1; this.labelExplanation.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // @@ -115,7 +102,6 @@ #endregion private TableLayoutPanel tableLayout; - private Button buttonSave; private Label labelExplanation; private Label labelSettingName; private Label labelIcon; diff --git a/I18N Commander/UI WinForms/Components/Setting.cs b/I18N Commander/UI WinForms/Components/Setting.cs index 9d0f92e..0a06612 100644 --- a/I18N Commander/UI WinForms/Components/Setting.cs +++ b/I18N Commander/UI WinForms/Components/Setting.cs @@ -4,45 +4,35 @@ using UI_WinForms.Resources; namespace UI_WinForms.Components; -public partial class Setting : UserControl +public partial class Setting : UserControl { - private readonly SettingUIData settingData; - public Setting() { this.InitializeComponent(); } - private Setting(SettingUIData settingData) + private Setting(SettingUIData settingMetaData) { this.InitializeComponent(); - this.settingData = settingData; - this.labelIcon.Image = settingData.Icon; - this.labelSettingName.Text = settingData.SettingName(); - this.labelExplanation.Text = settingData.SettingExplanation(); + this.labelIcon.Image = settingMetaData.Icon; + this.labelSettingName.Text = settingMetaData.SettingName(); + this.labelExplanation.Text = settingMetaData.SettingExplanation(); - var dataControl = this.settingData.SetupDataControl(); + var dataControl = settingMetaData.SetupDataControl(); this.tableLayout.Controls.Add(dataControl, 2, 0); } - private void buttonSave_Click(object sender, EventArgs e) - { - } - - private readonly record struct SettingUIData( + private readonly record struct SettingUIData( Bitmap Icon, Func SettingName, Func SettingExplanation, - Func SetupDataControl, - Func GetCurrentSetting, - Func SaveSetting + Func SetupDataControl ); - public static async Task> ShowDeepLSettingAsync() + public static async Task ShowDeepLSettingAsync() { var currentSetting = await AppSettings.GetDeepLMode(); - - var settingData = new Setting.SettingUIData( + var settingData = new Setting.SettingUIData( Icon: Icons.deepl_logo_icon_170284, SettingName: () => "DeepL Service", SettingExplanation: () => "DeepL is a translation service that offers a wide range of translation services. This setting allows you to choose between the free and pro version of DeepL.", @@ -57,21 +47,34 @@ public partial class Setting : UserControl SettingDeepL.DISABLED => 0, SettingDeepL.USE_FREE_ACCOUNT => 1, SettingDeepL.USE_PRO_ACCOUNT => 2, - + _ => 0, }; - - // Apply the desired design: + + // Setup the change event handler: + dropdown.SelectedValueChanged += async (sender, args) => + { + var newSetting = dropdown.SelectedIndex switch + { + 0 => SettingDeepL.DISABLED, + 1 => SettingDeepL.USE_FREE_ACCOUNT, + 2 => SettingDeepL.USE_PRO_ACCOUNT, + + _ => SettingDeepL.DISABLED, + }; + + await AppSettings.SetDeepLMode(newSetting); + }; + + // Apply the desired layout: dropdown.Dock = DockStyle.Fill; dropdown.DropDownStyle = ComboBoxStyle.DropDownList; return dropdown; - }, - - GetCurrentSetting: () => currentSetting, - SaveSetting: async setting => await AppSettings.SetDeepLMode(setting)); - - return new Setting(settingData) + } + ); + + return new Setting(settingData) { Dock = DockStyle.Top, }; diff --git a/I18N Commander/UI WinForms/Components/Settings.cs b/I18N Commander/UI WinForms/Components/Settings.cs index 106ade4..c04e767 100644 --- a/I18N Commander/UI WinForms/Components/Settings.cs +++ b/I18N Commander/UI WinForms/Components/Settings.cs @@ -7,7 +7,7 @@ public partial class Settings : UserControl this.InitializeComponent(); this.Load += async (sender, args) => { - var deepL = await Setting.ShowDeepLSettingAsync(); + var deepL = await Setting.ShowDeepLSettingAsync(); this.panelSettings.Controls.Add(deepL); }; }