Implemented the save function
This commit is contained in:
parent
62b8bb24d0
commit
83cc7644d1
@ -1,6 +1,6 @@
|
||||
namespace UI_WinForms.Components
|
||||
{
|
||||
partial class Setting<TSetting>
|
||||
partial class Setting
|
||||
{
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
@ -4,45 +4,35 @@ using UI_WinForms.Resources;
|
||||
|
||||
namespace UI_WinForms.Components;
|
||||
|
||||
public partial class Setting<TSetting> : UserControl
|
||||
public partial class Setting : UserControl
|
||||
{
|
||||
private readonly SettingUIData<TSetting> settingData;
|
||||
|
||||
public Setting()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private Setting(SettingUIData<TSetting> 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<TInnerSetting>(
|
||||
private readonly record struct SettingUIData(
|
||||
Bitmap Icon,
|
||||
Func<string> SettingName,
|
||||
Func<string> SettingExplanation,
|
||||
Func<Control> SetupDataControl,
|
||||
Func<TInnerSetting> GetCurrentSetting,
|
||||
Func<TInnerSetting, Task> SaveSetting
|
||||
Func<Control> SetupDataControl
|
||||
);
|
||||
|
||||
public static async Task<Setting<SettingDeepL>> ShowDeepLSettingAsync()
|
||||
public static async Task<Setting> ShowDeepLSettingAsync()
|
||||
{
|
||||
var currentSetting = await AppSettings.GetDeepLMode();
|
||||
|
||||
var settingData = new Setting<SettingDeepL>.SettingUIData<SettingDeepL>(
|
||||
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.",
|
||||
@ -61,17 +51,30 @@ public partial class Setting<TSetting> : UserControl
|
||||
_ => 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<SettingDeepL>(settingData)
|
||||
return new Setting(settingData)
|
||||
{
|
||||
Dock = DockStyle.Top,
|
||||
};
|
||||
|
@ -7,7 +7,7 @@ public partial class Settings : UserControl
|
||||
this.InitializeComponent();
|
||||
this.Load += async (sender, args) =>
|
||||
{
|
||||
var deepL = await Setting<bool>.ShowDeepLSettingAsync();
|
||||
var deepL = await Setting.ShowDeepLSettingAsync();
|
||||
this.panelSettings.Controls.Add(deepL);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user