fix: handle template errors better

This commit is contained in:
Anna 2024-02-18 00:13:55 -05:00
parent 28b994e0ab
commit 49c6c1307a
Signed by: anna
GPG Key ID: D0943384CD9F87D1
1 changed files with 18 additions and 4 deletions

View File

@ -60,6 +60,9 @@ internal class PluginUi : IDisposable {
return;
}
ImGui.PushTextWrapPos();
using var popTextWrapPos = new OnDispose(ImGui.PopTextWrapPos);
var anyChanged = false;
anyChanged |= this.DrawScreenshotsFolderInput();
@ -93,12 +96,23 @@ internal class PluginUi : IDisposable {
ImGui.SetNextItemWidth(-1);
anyChanged |= ImGui.InputText("##filename-format", ref this.Plugin.Config.SaveFileNameFormat, 1024);
try {
ImGui.TextUnformatted(this.Plugin.Config.SaveFileNameTemplate.Render(this.Metadata));
} catch (Exception ex) {
ImGui.TextUnformatted($"Invalid template: {ex.Message}");
var template = this.Plugin.Config.SaveFileNameTemplate;
if (template.HasErrors) {
ImGui.TextUnformatted("Invalid template");
foreach (var error in template.Messages) {
ImGui.Bullet();
ImGui.SameLine();
ImGui.TextUnformatted(error.Message);
}
} else {
try {
ImGui.TextUnformatted(this.Plugin.Config.SaveFileNameTemplate.Render(this.Metadata));
} catch (Exception ex) {
ImGui.TextUnformatted($"Failed to evaluate: {ex.Message}");
}
}
if (anyChanged) {
this.Plugin.SaveConfig();
}