I18NCommander/I18N Commander/UI WinForms/Components/Settings.cs

67 lines
2.2 KiB
C#
Raw Normal View History

using Processor;
namespace UI_WinForms.Components;
2022-07-26 17:08:47 +00:00
public partial class Settings : UserControl
{
public Settings()
{
this.InitializeComponent();
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);
}
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);
}
private async void buttonAddCulture_Click(object sender, EventArgs e)
{
// Get the current indices of cultures:
var cultureIndices = await AppSettings.GetCultureIndices();
// Add a new culture:
await AppSettings.SetCultureCode(cultureIndices.Max() + 1, string.Empty);
// Reload all settings:
await this.LoadAllSettings();
2022-07-26 17:08:47 +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
}