Edit the function key messages as their file
The messages were twelve boxes in a dialog, which meant no labels, no search-and-pounce set, and no way to read a file somebody published. They are now the file itself: right-click any function key button under the entry window, or the two buttons in Config ▸ Keyer and messages, and the text of an N1MM .mc file opens in a plain editor with Import, Export and Back to the defaults. MessageFile reads that format by N1MM's rules. A line starting with # is a comment; every other line is a label, a comma and the message, with && standing for one & in a label. Which key a line belongs to is decided by where it is and nothing else: the first twelve lines are F1 to F12 while running, the next twelve the same keys while searching, and a file that stops part way through the second twelve leaves the rest sending what they send while running. A blank line in the middle is a key with nothing in it, which is what the manual says; the newline that ends the last line is not, which it does not say, but no .mc file in the world means its final newline as a message. Two things fall out of this. The buttons now say what the file says, and they change when the operator moves between running and searching, so the labels are the documentation N1MM's manual suggests writing them as. And the search set is real: ESM's F2 while searching can be a different message from the one it sends while running, which is how the file was always meant to be used. Settings keep the file text and carry the twelve stored messages into it on first read, with the labels this program used then, so nobody loses what they had typed. The editor is deliberately a text box rather than a grid of fields: importing, exporting and editing are then the same thing, and the comments an operator writes in the file survive being edited here. The telnet window's buttons can use the same editor later. Running it caught two: Save as the default button ate the Enter key that a multi-line editor needs, and the button labels did not follow the move between run and search until they were redrawn rather than only rebuilt. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
82
src/Nonemm.App/Dialogs/MessagesDialog.axaml.cs
Normal file
82
src/Nonemm.App/Dialogs/MessagesDialog.axaml.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Nonemm.Core;
|
||||
|
||||
namespace Nonemm.App.Dialogs;
|
||||
|
||||
/// The function key messages as the text of an N1MM `.mc` file. Editing them as
|
||||
/// the file rather than as twelve boxes is what makes import and export the
|
||||
/// same thing as what is on the screen.
|
||||
///
|
||||
/// It closes with the text, or with null when nothing is to be changed.
|
||||
public sealed partial class MessagesDialog : Window
|
||||
{
|
||||
private static readonly FilePickerFileType MessageFiles = new("Function key files")
|
||||
{
|
||||
Patterns = ["*.mc"],
|
||||
};
|
||||
|
||||
private readonly ModeCategory mode;
|
||||
|
||||
public MessagesDialog(ModeCategory mode, string text, string what = "Function key messages")
|
||||
{
|
||||
this.mode = mode;
|
||||
InitializeComponent();
|
||||
Title = $"{what} — {(mode == ModeCategory.Phone ? "phone" : "CW")}";
|
||||
TextArea.Text = text.Trim().Length > 0 ? text : Messages.DefaultFor(mode);
|
||||
}
|
||||
|
||||
private async void OnImport(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
IReadOnlyList<IStorageFile> files = await StorageProvider.OpenFilePickerAsync(
|
||||
new FilePickerOpenOptions
|
||||
{
|
||||
Title = "Import a function key file",
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = [MessageFiles],
|
||||
});
|
||||
if (files.FirstOrDefault()?.TryGetLocalPath() is not { } path)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
TextArea.Text = await File.ReadAllTextAsync(path);
|
||||
}
|
||||
catch (Exception error) when (error is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
TextArea.Text = $"# {path} could not be read: {error.Message}\n{TextArea.Text}";
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnExport(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
IStorageFile? file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
||||
{
|
||||
Title = "Export the function key file",
|
||||
SuggestedFileName = mode == ModeCategory.Phone ? "phone.mc" : "cw.mc",
|
||||
DefaultExtension = "mc",
|
||||
FileTypeChoices = [MessageFiles],
|
||||
});
|
||||
if (file?.TryGetLocalPath() is not { } path)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(path, TextArea.Text ?? "");
|
||||
}
|
||||
catch (Exception error) when (error is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
TextArea.Text = $"# {path} could not be written: {error.Message}\n{TextArea.Text}";
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDefaults(object? sender, RoutedEventArgs e) =>
|
||||
TextArea.Text = Messages.DefaultFor(mode);
|
||||
|
||||
private void OnSave(object? sender, RoutedEventArgs e) => Close(TextArea.Text ?? "");
|
||||
|
||||
private void OnCancel(object? sender, RoutedEventArgs e) => Close(null);
|
||||
}
|
||||
Reference in New Issue
Block a user