Added auto-export settings

This commit is contained in:
Thorsten Sommer 2023-01-22 13:02:08 +01:00
parent 5978614845
commit a19720f98d
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 183 additions and 0 deletions

View File

@ -418,4 +418,40 @@ public static class AppSettings
#endregion #endregion
#endregion #endregion
#region Auto-Export Settings
#region Auto-Export Enabled/Disabled
public static async Task<bool> GetAutoExportEnabled() => await AppSettings.GetSetting(SettingNames.AUTO_EXPORT_ENABLED, false);
public static async Task SetAutoExportEnabled(bool enabled) => await AppSettings.SetSetting(SettingNames.AUTO_EXPORT_ENABLED, enabled);
#endregion
#region Auto-Export Destination Path
public static async Task<string> GetAutoExportDestinationPath() => await AppSettings.GetSetting(SettingNames.AUTO_EXPORT_DESTINATION_PATH, string.Empty);
public static async Task SetAutoExportDestinationPath(string path) => await AppSettings.SetSetting(SettingNames.AUTO_EXPORT_DESTINATION_PATH, path);
#endregion
#region Auto-Export Filename
public static async Task<string> GetAutoExportFilename() => await AppSettings.GetSetting(SettingNames.AUTO_EXPORT_FILENAME, "I18NCommander.json");
public static async Task SetAutoExportFilename(string filename) => await AppSettings.SetSetting(SettingNames.AUTO_EXPORT_FILENAME, filename);
#endregion
#region Auto-Export Sensitive Data
public static async Task<bool> GetAutoExportSensitiveData() => await AppSettings.GetSetting(SettingNames.AUTO_EXPORT_SENSITIVE_DATA, false);
public static async Task SetAutoExportSensitiveData(bool enabled) => await AppSettings.SetSetting(SettingNames.AUTO_EXPORT_SENSITIVE_DATA, enabled);
#endregion
#endregion
} }

View File

@ -686,8 +686,154 @@ public sealed partial class Setting : UserControl
return new Setting(settingData); return new Setting(settingData);
} }
private static async Task<Setting> ShowGeneratorAutoExportEnabledSettingAsync()
{
var currentSetting = await AppSettings.GetAutoExportEnabled();
var settingData = new SettingUIData(
Icon: Icons.icons8_git_svg,
SettingName: () => "Git (JSON) Auto-Export: Enabled",
ChangeNeedsRestart: true,
SettingExplanation: () => "When enabled, all changes are automatically exported into a Git repository as JSON file.",
SettingExplanationLink: () => (string.Empty, string.Empty),
SetupDataControl: (changeTrigger) =>
{
// Set up an checkbox:
var checkbox = new CheckBox();
checkbox.Checked = currentSetting;
checkbox.CheckedChanged += async (sender, args) => await AppSettings.SetAutoExportEnabled(checkbox.Checked);
checkbox.CheckedChanged += (sender, args) => changeTrigger();
checkbox.Text = "Enable Git (JSON) Auto-Export";
// Apply the desired layout:
checkbox.Dock = DockStyle.Fill;
return checkbox;
}
);
return new Setting(settingData);
}
private static async Task<Setting> ShowGeneratorAutoExportDestinationPathSettingAsync()
{
var currentSetting = await AppSettings.GetAutoExportDestinationPath();
var settingData = new SettingUIData(
Icon: Icons.icons8_git_svg,
SettingName: () => "Git (JSON) Auto-Export: Destination Path",
ChangeNeedsRestart: true,
SettingExplanation: () => "The destination path for the Git repository. You might use environment variables like %USERPROFILE%.",
SettingExplanationLink: () => (string.Empty, string.Empty),
SetupDataControl: (changeTrigger) =>
{
// Set up a horizontal layout:
var layout = new TableLayoutPanel();
layout.ColumnCount = 2;
layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
layout.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 66F));
layout.RowCount = 1;
layout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
layout.Dock = DockStyle.Fill;
// Set up a textbox:
var textbox = new TextBox();
textbox.Text = currentSetting;
textbox.TextChanged += async (sender, args) => await AppSettings.SetAutoExportDestinationPath(textbox.Text);
textbox.TextChanged += (sender, args) => changeTrigger();
textbox.Dock = DockStyle.Fill;
textbox.Margin = new Padding(0, 13, 0, 13);
layout.Controls.Add(textbox, 0, 0);
// Set up a button:
var button = new Button();
button.Text = string.Empty;
button.Image = Icons.icons8_folder_tree_512;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
button.BackColor = Color.Empty;
button.UseVisualStyleBackColor = true;
button.Size = new Size(60, 60);
button.Click += (sender, args) =>
{
var dialog = new FolderBrowserDialog();
dialog.SelectedPath = textbox.Text;
dialog.InitialDirectory = textbox.Text;
dialog.Description = "Select the destination path for the Git repository.";
dialog.ShowNewFolderButton = true;
if (dialog.ShowDialog() == DialogResult.OK)
textbox.Text = dialog.SelectedPath;
};
button.Dock = DockStyle.Fill;
layout.Controls.Add(button, 1, 0);
return layout;
}
);
return new Setting(settingData);
}
private static async Task<Setting> ShowGeneratorAutoExportFilenameSettingAsync()
{
var currentSetting = await AppSettings.GetAutoExportFilename();
var settingData = new SettingUIData(
Icon: Icons.icons8_git_svg,
SettingName: () => "Git (JSON) Auto-Export: Filename",
ChangeNeedsRestart: true,
SettingExplanation: () => "The filename used for the Git export. You might use environment variables like %USERPROFILE%.",
SettingExplanationLink: () => (string.Empty, string.Empty),
SetupDataControl: (changeTrigger) =>
{
var textbox = new TextBox();
textbox.Text = currentSetting;
textbox.TextChanged += async (sender, args) => await AppSettings.SetAutoExportFilename(textbox.Text);
textbox.TextChanged += (sender, args) => changeTrigger();
textbox.Dock = DockStyle.Fill;
textbox.Margin = new Padding(0, 13, 0, 13);
return textbox;
}
);
return new Setting(settingData);
}
private static async Task<Setting> ShowGeneratorAutoExportExportSensitiveDataSettingAsync()
{
var currentSetting = await AppSettings.GetAutoExportSensitiveData();
var settingData = new SettingUIData(
Icon: Icons.icons8_git_svg,
SettingName: () => "Git (JSON) Auto-Export: Export Sensitive Data",
ChangeNeedsRestart: true,
SettingExplanation: () => "When enabled, sensitive data like API tokens are exported into the Git repository. This is not recommended!",
SettingExplanationLink: () => (string.Empty, string.Empty),
SetupDataControl: (changeTrigger) =>
{
// Set up an checkbox:
var checkbox = new CheckBox();
checkbox.Checked = currentSetting;
checkbox.CheckedChanged += async (sender, args) => await AppSettings.SetAutoExportSensitiveData(checkbox.Checked);
checkbox.CheckedChanged += (sender, args) => changeTrigger();
checkbox.Text = "Export Sensitive Data";
// Apply the desired layout:
checkbox.Dock = DockStyle.Fill;
return checkbox;
}
);
return new Setting(settingData);
}
public static IEnumerable<Task<Setting>> GetAllSettings() public static IEnumerable<Task<Setting>> GetAllSettings()
{ {
//
// Remember: The reverse order is the order in the UI!
//
yield return ShowGeneratorAutoExportFilenameSettingAsync();
yield return ShowGeneratorAutoExportDestinationPathSettingAsync();
yield return ShowGeneratorAutoExportExportSensitiveDataSettingAsync();
yield return ShowGeneratorAutoExportEnabledSettingAsync();
yield return ShowGeneratorGodotDestinationPathSettingAsync(); yield return ShowGeneratorGodotDestinationPathSettingAsync();
yield return ShowGeneratorGodotEnabledSettingAsync(); yield return ShowGeneratorGodotEnabledSettingAsync();
yield return ShowGeneratorDotnetDefaultCultureSettingAsync(); yield return ShowGeneratorDotnetDefaultCultureSettingAsync();
@ -695,6 +841,7 @@ public sealed partial class Setting : UserControl
yield return ShowGeneratorDotnetDestinationPathSettingAsync(); yield return ShowGeneratorDotnetDestinationPathSettingAsync();
yield return ShowGeneratorDotnetEnabledSettingAsync(); yield return ShowGeneratorDotnetEnabledSettingAsync();
yield return ShowGeneratorModeSettingAsync(); yield return ShowGeneratorModeSettingAsync();
yield return ShowDeepLSourceCultureSettingAsync(); yield return ShowDeepLSourceCultureSettingAsync();
foreach (var setting in ShowCultureSettingsAsync()) foreach (var setting in ShowCultureSettingsAsync())
yield return setting; yield return setting;