2022-07-30 21:34:45 +00:00
|
|
|
|
using Processor;
|
|
|
|
|
|
|
|
|
|
namespace UI_WinForms.Components;
|
2022-07-26 17:08:47 +00:00
|
|
|
|
|
|
|
|
|
public partial class Settings : UserControl
|
|
|
|
|
{
|
|
|
|
|
public Settings()
|
|
|
|
|
{
|
|
|
|
|
this.InitializeComponent();
|
2022-07-30 21:34:45 +00:00
|
|
|
|
this.Load += async (sender, args) => await this.LoadAllSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadAllSettings()
|
|
|
|
|
{
|
|
|
|
|
this.panelSettings.Controls.Clear();
|
|
|
|
|
foreach (var setting in Setting.GetAllSettings())
|
|
|
|
|
this.panelSettings.Controls.Add(await setting);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 19:36:45 +00:00
|
|
|
|
public bool NeedRestart()
|
|
|
|
|
{
|
|
|
|
|
// Iterate through all settings and check if any of them need a restart:
|
|
|
|
|
return this.panelSettings.Controls.Cast<Setting>().Any(setting => setting.NeedRestart);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-30 21:34:45 +00:00
|
|
|
|
private async void buttonAddCulture_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2022-08-02 18:41:55 +00:00
|
|
|
|
// Get the current indices of cultures:
|
|
|
|
|
var cultureIndices = await AppSettings.GetCultureIndices();
|
2022-07-30 21:34:45 +00:00
|
|
|
|
|
|
|
|
|
// Add a new culture:
|
2022-08-02 18:41:55 +00:00
|
|
|
|
await AppSettings.SetCultureCode(cultureIndices.Max() + 1, string.Empty);
|
2022-07-30 21:34:45 +00:00
|
|
|
|
|
|
|
|
|
// Reload all settings:
|
|
|
|
|
await this.LoadAllSettings();
|
2022-07-26 17:08:47 +00:00
|
|
|
|
}
|
2022-08-02 18:43:58 +00:00
|
|
|
|
|
|
|
|
|
private async void buttonDeleteCulture_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Read all cultures:
|
|
|
|
|
var cultures = await AppSettings.GetCultureInfos();
|
|
|
|
|
|
|
|
|
|
// Populate the delete button's menu strip with all cultures:
|
|
|
|
|
this.contextMenuDelete.Items.Clear();
|
|
|
|
|
foreach (var culture in cultures)
|
|
|
|
|
{
|
|
|
|
|
var item = new ToolStripMenuItem($"{culture.Index}. Culture: {culture.Code}");
|
|
|
|
|
item.Tag = culture.Index;
|
|
|
|
|
item.Click += async (senderObj, args) =>
|
|
|
|
|
{
|
|
|
|
|
if (senderObj is not ToolStripMenuItem toolStripMenuItem)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Delete the culture:
|
|
|
|
|
await AppSettings.DeleteCulture((int)toolStripMenuItem.Tag);
|
|
|
|
|
|
|
|
|
|
// Reload all settings:
|
|
|
|
|
await this.LoadAllSettings();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.contextMenuDelete.Items.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.contextMenuDelete.Show((Button)sender, new Point(0, (this.contextMenuDelete.Height + this.buttonDeleteCulture.Height / 2) * -1));
|
|
|
|
|
}
|
2022-07-26 17:08:47 +00:00
|
|
|
|
}
|