diff --git a/app/MindWork AI Studio/Assistants/I18N/allTexts.lua b/app/MindWork AI Studio/Assistants/I18N/allTexts.lua index 9944939c..cb462174 100644 --- a/app/MindWork AI Studio/Assistants/I18N/allTexts.lua +++ b/app/MindWork AI Studio/Assistants/I18N/allTexts.lua @@ -3403,6 +3403,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIDENCEINFO::T847071819"] = "Shows and -- This feature is managed by your organization and has therefore been disabled. UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIGURATIONBASE::T1416426626"] = "This feature is managed by your organization and has therefore been disabled." +-- Choose Directory +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIGURATIONDIRECTORY::T4256489763"] = "Choose Directory" + -- Choose File UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIGURATIONFILE::T4285779702"] = "Choose File" @@ -6487,6 +6490,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGBATCHPROCESSING::T15 -- Default prompt UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGBATCHPROCESSING::T1750564968"] = "Default prompt" +-- Select the default input folder +UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGBATCHPROCESSING::T1776900205"] = "Select the default input folder" + -- Batch processing options are preselected UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGBATCHPROCESSING::T1893713430"] = "Batch processing options are preselected" @@ -6565,6 +6571,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGBATCHPROCESSING::T48 -- Default output mode UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGBATCHPROCESSING::T601648878"] = "Default output mode" +-- Select the default output folder +UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGBATCHPROCESSING::T602371388"] = "Select the default output folder" + -- Load default Markdown instructions file UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGBATCHPROCESSING::T626322240"] = "Load default Markdown instructions file" diff --git a/app/MindWork AI Studio/Components/ConfigurationDirectory.razor b/app/MindWork AI Studio/Components/ConfigurationDirectory.razor new file mode 100644 index 00000000..c04d24d7 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationDirectory.razor @@ -0,0 +1,27 @@ +@inherits ConfigurationBaseCore + + + + + + @T("Choose Directory") + + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ConfigurationDirectory.razor.cs b/app/MindWork AI Studio/Components/ConfigurationDirectory.razor.cs new file mode 100644 index 00000000..2863c197 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationDirectory.razor.cs @@ -0,0 +1,133 @@ +using AIStudio.Tools.Services; + +using Microsoft.AspNetCore.Components; + +using Timer = System.Timers.Timer; + +namespace AIStudio.Components; + +public partial class ConfigurationDirectory : ConfigurationBaseCore +{ + /// + /// The text used for the textfield. + /// + [Parameter] + public Func Text { get; set; } = () => string.Empty; + + /// + /// An action which is called when the text was changed. + /// + [Parameter] + public Action TextUpdate { get; set; } = _ => { }; + + /// + /// The icon to display next to the textfield. + /// + [Parameter] + public string Icon { get; set; } = Icons.Material.Filled.Folder; + + /// + /// The color of the icon to use. + /// + [Parameter] + public Color IconColor { get; set; } = Color.Default; + + /// + /// The title of the directory selection dialog. + /// + [Parameter] + public string DirectoryDialogTitle { get; set; } = "Select Directory"; + + [Inject] + private RustService RustService { get; init; } = null!; + + private string internalText = string.Empty; + private bool isDirectoryDialogOpen; + + private readonly Timer timer = new(TimeSpan.FromMilliseconds(500)) + { + AutoReset = false + }; + + #region Overrides of ConfigurationBase + + /// + protected override bool Stretch => true; + + protected override Variant Variant => Variant.Outlined; + + protected override string Label => this.OptionDescription; + + #endregion + + #region Overrides of ComponentBase + + protected override async Task OnInitializedAsync() + { + this.timer.Elapsed += async (_, _) => await this.InvokeAsync(async () => await this.OptionChanged(this.internalText)); + await base.OnInitializedAsync(); + } + + protected override async Task OnParametersSetAsync() + { + this.internalText = this.Text(); + await base.OnParametersSetAsync(); + } + + #endregion + + private void InternalUpdate(string text) + { + this.timer.Stop(); + this.internalText = text; + this.timer.Start(); + } + + private async Task OpenDirectoryDialog() + { + if (this.isDirectoryDialogOpen) + return; + + this.isDirectoryDialogOpen = true; + try + { + var response = await this.RustService.SelectDirectory(this.DirectoryDialogTitle, string.IsNullOrWhiteSpace(this.internalText) ? null : this.internalText); + if (response.UserCancelled) + return; + + this.timer.Stop(); + this.internalText = response.SelectedDirectory; + await this.OptionChanged(response.SelectedDirectory); + } + finally + { + this.isDirectoryDialogOpen = false; + } + } + + private async Task OptionChanged(string updatedText) + { + this.TextUpdate(updatedText); + await this.SettingsManager.StoreSettings(); + await this.InformAboutChange(); + } + + #region Overrides of MSGComponentBase + + protected override void DisposeResources() + { + try + { + this.timer.Stop(); + this.timer.Dispose(); + } + catch + { + // ignore + } + + base.DisposeResources(); + } + + #endregion +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Dialogs/Settings/SettingsDialogBatchProcessing.razor b/app/MindWork AI Studio/Dialogs/Settings/SettingsDialogBatchProcessing.razor index 8da310ed..22a25b00 100644 --- a/app/MindWork AI Studio/Dialogs/Settings/SettingsDialogBatchProcessing.razor +++ b/app/MindWork AI Studio/Dialogs/Settings/SettingsDialogBatchProcessing.razor @@ -16,7 +16,7 @@ @T("Input") - + @@ -48,7 +48,7 @@ } - + @T("AI selection")