fix: handle template errors better
This commit is contained in:
parent
28b994e0ab
commit
49c6c1307a
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue