diff --git a/I18N Commander/Processor/AppSettings.cs b/I18N Commander/Processor/AppSettings.cs index 5c177ae..8987196 100644 --- a/I18N Commander/Processor/AppSettings.cs +++ b/I18N Commander/Processor/AppSettings.cs @@ -418,4 +418,40 @@ public static class AppSettings #endregion #endregion + + #region Auto-Export Settings + + #region Auto-Export Enabled/Disabled + + public static async Task 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 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 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 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 } \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Components/Setting.cs b/I18N Commander/UI WinForms/Components/Setting.cs index 0d248b0..5256be2 100644 --- a/I18N Commander/UI WinForms/Components/Setting.cs +++ b/I18N Commander/UI WinForms/Components/Setting.cs @@ -685,9 +685,155 @@ public sealed partial class Setting : UserControl return new Setting(settingData); } + + private static async Task 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 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 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 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> 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 ShowGeneratorGodotEnabledSettingAsync(); yield return ShowGeneratorDotnetDefaultCultureSettingAsync(); @@ -695,6 +841,7 @@ public sealed partial class Setting : UserControl yield return ShowGeneratorDotnetDestinationPathSettingAsync(); yield return ShowGeneratorDotnetEnabledSettingAsync(); yield return ShowGeneratorModeSettingAsync(); + yield return ShowDeepLSourceCultureSettingAsync(); foreach (var setting in ShowCultureSettingsAsync()) yield return setting;