@using LANCommander.Data.Enums; @using LANCommander.Models @using LANCommander.Services @inject ISnackbar Snackbar @inject IDialogService DialogService @inject ScriptService ScriptService @foreach (var group in Snippets.Select(s => s.Group).Distinct()) { @foreach (var snippet in Snippets.Where(s => s.Group == group)) { @snippet.Name } } @foreach (ScriptType type in Enum.GetValues(typeof(ScriptType))) { @type } Save @code { [CascadingParameter] MudDialogInstance MudDialog { get; set; } [Parameter] public Script Script { get; set; } IEnumerable Snippets { get; set; } StandaloneCodeEditor Editor; private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor) { return new StandaloneEditorConstructionOptions { AutomaticLayout = true, Language = "powershell", Value = Script.Contents, Theme = "vs-dark", }; } protected override async Task OnInitializedAsync() { MudDialog.Options.MaxWidth = MaxWidth.ExtraLarge; MudDialog.Options.FullWidth = true; MudDialog.Options.CloseButton = true; MudDialog.Options.CloseOnEscapeKey = false; MudDialog.Options.DisableBackdropClick = true; MudDialog.SetOptions(MudDialog.Options); Snippets = ScriptService.GetSnippets(); if (Script == null) Script = new Script(); } private async Task Save() { var value = await Editor.GetValue(); ScriptService.Update(Script); Snackbar.Add("Script saved!", Severity.Success); MudDialog.Close(); } private async void InsertSnippet(Snippet snippet) { Editor.Trigger("keyboard", "type", new { text = snippet.Content }); } private async void BrowseForPath() { var parameters = new DialogParameters { ["ArchiveId"] = Script.Game.Archives.OrderByDescending(a => a.CreatedOn).First().Id }; var dialog = await DialogService.ShowAsync("File Selector", parameters); var result = await dialog.Result; if (!result.Canceled) { var path = result.Data as string; Editor.Trigger("keyboard", "type", new { text = $"$InstallDir\\{path.Replace('/', '\\')}" }); StateHasChanged(); } } }