template editor

This commit is contained in:
EugeneTes
2026-02-05 08:42:02 +01:00
parent 1fcaaa040b
commit 1c0c95842a
4 changed files with 131 additions and 7 deletions

View File

@@ -7,18 +7,19 @@
@using Inspectron.Epson.PrintServer.Printers
@using Inspectron.Epson.TemplateEngine
@using Inspectron.PrintServer.TemplateEditor.Services
@implements IDisposable
@inject IJSRuntime JSRuntime
<div class="editor-container">
<div class="toolbar">
<button class="toolbar-btn" title="New" @onclick="NewFileAsync">New</button>
<button class="toolbar-btn" title="Open" @onclick="OpenFileAsync">Open</button>
<button class="toolbar-btn" title="Save" @onclick="SaveFileAsync">Save</button>
<button class="toolbar-btn" title="New (Ctrl+N)" @onclick="NewFileAsync">New</button>
<button class="toolbar-btn" title="Open (Ctrl+O)" @onclick="OpenFileAsync">Open</button>
<button class="toolbar-btn" title="Save (Ctrl+S)" @onclick="SaveFileAsync">Save</button>
<span class="file-indicator" title="@(_currentFilePath ?? "Untitled")">
@FileDisplayName@(HasUnsavedChanges ? " *" : "")
</span>
<div class="toolbar-separator"></div>
<button class="toolbar-btn" title="Load JSON data file for expression completions" @onclick="LoadJsonAsync">Load JSON</button>
<button class="toolbar-btn" title="Load JSON (Ctrl+J)" @onclick="LoadJsonAsync">Load JSON</button>
@if (!string.IsNullOrEmpty(_loadedJsonFile))
{
<span class="json-indicator" title="@_loadedJsonFile">@_loadedJsonFile</span>
@@ -66,6 +67,7 @@
private string? _previewError;
private string _selectedPrinterModel = "TM-T30III";
private CancellationTokenSource? _debounceCts;
private DotNetObjectReference<Home>? _dotNetRef;
private bool HasUnsavedChanges => _editorContent != _savedContent;
@@ -101,6 +103,30 @@
"receipt-xml",
_completionProvider.ProvideCompletionItems,
_completionProvider.ResolveCompletionItem);
// Register global hotkeys
_dotNetRef = DotNetObjectReference.Create(this);
await JSRuntime.InvokeVoidAsync("registerHotkeys", _dotNetRef);
}
[JSInvokable]
public async Task OnHotkeyAsync(string action)
{
switch (action)
{
case "New": await NewFileAsync(); break;
case "Open": await OpenFileAsync(); break;
case "Save": await SaveFileAsync(); break;
case "LoadJson": await LoadJsonAsync(); break;
}
StateHasChanged();
}
public void Dispose()
{
_debounceCts?.Cancel();
_debounceCts?.Dispose();
_dotNetRef?.Dispose();
}
private async Task OnContentChanged(ModelContentChangedEvent e)