Remove error timeouts, have input validated on each change

This commit is contained in:
Eauldane 2025-12-03 22:03:34 +00:00
parent bfe338e991
commit e518cf6e32
2 changed files with 36 additions and 20 deletions

View file

@ -187,8 +187,6 @@ internal sealed class SettingsWindow : Window
{ {
this.Save(); this.Save();
hasInvalidEntries = this.tabs.Any(x => x.Entries.Any(y => !y.IsValid));
if (!hasInvalidEntries && !ImGui.IsKeyDown(ImGuiKey.ModShift)) if (!hasInvalidEntries && !ImGui.IsKeyDown(ImGuiKey.ModShift))
this.IsOpen = false; this.IsOpen = false;
} }

View file

@ -181,29 +181,34 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
ImGui.SetNextItemWidth(-1); ImGui.SetNextItemWidth(-1);
var url = thirdRepoSetting.Url; var url = thirdRepoSetting.Url;
if (ImGui.InputText($"##thirdRepoInput", ref url, 65535, ImGuiInputTextFlags.EnterReturnsTrue)) if (ImGui.InputText($"##thirdRepoInput", ref url, 65535))
{ {
this.IsValid = true; var trimmedUrl = url.Trim();
var contains = this.thirdRepoList.Select(repo => repo.Url).Contains(url); if (string.Equals(thirdRepoSetting.Url, trimmedUrl, StringComparison.InvariantCultureIgnoreCase))
if (thirdRepoSetting.Url == url)
{ {
// no change. this.thirdRepoAddError = string.Empty;
this.IsValid = true;
} }
else if (contains && thirdRepoSetting.Url != url) else if (this.thirdRepoList
.Where(repo => !string.Equals(repo.Url, thirdRepoSetting.Url, StringComparison.InvariantCultureIgnoreCase))
.Select(repo => repo.Url)
.Contains(trimmedUrl))
{ {
this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoExists", "Repo already exists."); this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoExists", "Repo already exists.");
Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty); this.IsValid = false;
} }
else if (!ValidThirdPartyRepoUrl(url)) else if (!ValidThirdPartyRepoUrl(trimmedUrl))
{ {
this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoNotUrl", "The entered address is not a valid URL.\nDid you mean to enter it as a DevPlugin in the fields above instead?"); this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoNotUrl", "The entered address is not a valid URL.\nDid you mean to enter it as a DevPlugin in the fields above instead?");
Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty); this.IsValid = false;
} }
else else
{ {
this.thirdRepoListChanged = thirdRepoSetting.Url != url; this.thirdRepoAddError = string.Empty;
thirdRepoSetting.Url = url; this.thirdRepoListChanged = !string.Equals(thirdRepoSetting.Url, trimmedUrl, StringComparison.InvariantCultureIgnoreCase);
thirdRepoSetting.Url = trimmedUrl;
this.IsValid = true;
} }
} }
@ -244,7 +249,7 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
ImGui.SetNextItemWidth(-1); ImGui.SetNextItemWidth(-1);
if (ImGui.InputText("##thirdRepoUrlInput"u8, ref this.thirdRepoTempUrl, 300)) if (ImGui.InputText("##thirdRepoUrlInput"u8, ref this.thirdRepoTempUrl, 300))
{ {
this.IsValid = true; this.ValidateTempRepoInput();
} }
ImGui.NextColumn(); ImGui.NextColumn();
@ -267,16 +272,20 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
=> Uri.TryCreate(url, UriKind.Absolute, out var uriResult) => Uri.TryCreate(url, UriKind.Absolute, out var uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttps || uriResult.Scheme == Uri.UriSchemeHttp); && (uriResult.Scheme == Uri.UriSchemeHttps || uriResult.Scheme == Uri.UriSchemeHttp);
private bool TryAddTempRepo() private bool ValidateTempRepoInput()
{ {
if (string.IsNullOrWhiteSpace(this.thirdRepoTempUrl))
return false;
this.thirdRepoTempUrl = this.thirdRepoTempUrl.Trim(); this.thirdRepoTempUrl = this.thirdRepoTempUrl.Trim();
if (string.IsNullOrEmpty(this.thirdRepoTempUrl))
{
this.thirdRepoAddError = string.Empty;
this.IsValid = true;
return false;
}
if (this.thirdRepoList.Any(r => string.Equals(r.Url, this.thirdRepoTempUrl, StringComparison.InvariantCultureIgnoreCase))) if (this.thirdRepoList.Any(r => string.Equals(r.Url, this.thirdRepoTempUrl, StringComparison.InvariantCultureIgnoreCase)))
{ {
this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoExists", "Repo already exists."); this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoExists", "Repo already exists.");
Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty);
this.IsValid = false; this.IsValid = false;
return false; return false;
} }
@ -284,11 +293,20 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
if (!ValidThirdPartyRepoUrl(this.thirdRepoTempUrl)) if (!ValidThirdPartyRepoUrl(this.thirdRepoTempUrl))
{ {
this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoNotUrl", "The entered address is not a valid URL.\nDid you mean to enter it as a DevPlugin in the fields above instead?"); this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoNotUrl", "The entered address is not a valid URL.\nDid you mean to enter it as a DevPlugin in the fields above instead?");
Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty);
this.IsValid = false; this.IsValid = false;
return false; return false;
} }
this.thirdRepoAddError = string.Empty;
this.IsValid = true;
return true;
}
private bool TryAddTempRepo()
{
if (!this.ValidateTempRepoInput())
return false;
this.thirdRepoList.Add(new ThirdPartyRepoSettings this.thirdRepoList.Add(new ThirdPartyRepoSettings
{ {
Url = this.thirdRepoTempUrl, Url = this.thirdRepoTempUrl,