mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 18:59:47 +00:00
Added component to let the user choose a directory
This commit is contained in:
parent
e9f4d5fecd
commit
3f22380410
16
app/MindWork AI Studio/Components/SelectDirectory.razor
Normal file
16
app/MindWork AI Studio/Components/SelectDirectory.razor
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<MudStack Row="@true" Spacing="3" Class="mb-3" StretchItems="StretchItems.None" AlignItems="AlignItems.Center">
|
||||||
|
<MudTextField
|
||||||
|
T="string"
|
||||||
|
Text="@this.Directory"
|
||||||
|
Label="@this.Label"
|
||||||
|
ReadOnly="@true"
|
||||||
|
Adornment="Adornment.Start"
|
||||||
|
AdornmentIcon="@Icons.Material.Filled.Folder"
|
||||||
|
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<MudButton StartIcon="@Icons.Material.Filled.FolderOpen" Variant="Variant.Outlined" Color="Color.Primary" Disabled="this.Disabled" OnClick="@this.OpenDirectoryDialog">
|
||||||
|
Choose Directory
|
||||||
|
</MudButton>
|
||||||
|
</MudStack>
|
60
app/MindWork AI Studio/Components/SelectDirectory.razor.cs
Normal file
60
app/MindWork AI Studio/Components/SelectDirectory.razor.cs
Normal file
@ -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<string> 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<SelectDirectory> Logger { get; init; } = null!;
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, object?> 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user