diff --git a/app/MindWork AI Studio/Components/SelectDirectory.razor b/app/MindWork AI Studio/Components/SelectDirectory.razor new file mode 100644 index 00000000..95f09d69 --- /dev/null +++ b/app/MindWork AI Studio/Components/SelectDirectory.razor @@ -0,0 +1,16 @@ + + + + + Choose Directory + + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/SelectDirectory.razor.cs b/app/MindWork AI Studio/Components/SelectDirectory.razor.cs new file mode 100644 index 00000000..ec4f6cd3 --- /dev/null +++ b/app/MindWork AI Studio/Components/SelectDirectory.razor.cs @@ -0,0 +1,60 @@ +using AIStudio.Settings; + +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Components; + +public partial class SelectDirectory : ComponentBase +{ + [Parameter] + public string Directory { get; set; } = string.Empty; + + [Parameter] + public EventCallback DirectoryChanged { get; set; } + + [Parameter] + public bool Disabled { get; set; } + + [Parameter] + public string Label { get; set; } = string.Empty; + + [Parameter] + public string DirectoryDialogTitle { get; set; } = "Select Directory"; + + [Inject] + private SettingsManager SettingsManager { get; init; } = null!; + + [Inject] + public RustService RustService { get; set; } = null!; + + [Inject] + protected ILogger Logger { get; init; } = null!; + + private static readonly Dictionary SPELLCHECK_ATTRIBUTES = new(); + + #region Overrides of ComponentBase + + protected override async Task OnInitializedAsync() + { + // Configure the spellchecking for the instance name input: + this.SettingsManager.InjectSpellchecking(SPELLCHECK_ATTRIBUTES); + await base.OnInitializedAsync(); + } + + #endregion + + private void InternalDirectoryChanged(string directory) + { + this.Directory = directory; + this.DirectoryChanged.InvokeAsync(directory); + } + + private async Task OpenDirectoryDialog() + { + var response = await this.RustService.SelectDirectory(this.DirectoryDialogTitle, string.IsNullOrWhiteSpace(this.Directory) ? null : this.Directory); + this.Logger.LogInformation($"The user selected the directory '{response.SelectedDirectory}'."); + + if (!response.UserCancelled) + this.InternalDirectoryChanged(response.SelectedDirectory); + } +} \ No newline at end of file