Fix window closing if there's an invalid repo URL added.

This commit is contained in:
Eauldane 2025-11-30 20:11:39 +00:00
parent efa8f06dc7
commit b461ad845d
2 changed files with 21 additions and 6 deletions

View file

@ -175,17 +175,21 @@ internal sealed class SettingsWindow : Window
{ {
if (buttonChild) if (buttonChild)
{ {
using var disabled = ImRaii.Disabled(this.tabs.Any(x => x.Entries.Any(y => !y.IsValid)));
using (ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 100f)) using (ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 100f))
{ {
using var font = ImRaii.PushFont(InterfaceManager.IconFont); using var font = ImRaii.PushFont(InterfaceManager.IconFont);
var hasInvalidEntries = this.tabs.Any(x => x.Entries.Any(y => !y.IsValid));
using var disabled = ImRaii.Disabled(hasInvalidEntries);
if (ImGui.Button(FontAwesomeIcon.Save.ToIconString(), new Vector2(40))) if (ImGui.Button(FontAwesomeIcon.Save.ToIconString(), new Vector2(40)))
{ {
this.Save(); this.Save();
if (!ImGui.IsKeyDown(ImGuiKey.ModShift)) hasInvalidEntries = this.tabs.Any(x => x.Entries.Any(y => !y.IsValid));
if (!hasInvalidEntries && !ImGui.IsKeyDown(ImGuiKey.ModShift))
this.IsOpen = false; this.IsOpen = false;
} }
} }

View file

@ -42,6 +42,7 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
this.thirdRepoList = this.thirdRepoList =
[.. Service<DalamudConfiguration>.Get().ThirdRepoList.Select(x => x.Clone())]; [.. Service<DalamudConfiguration>.Get().ThirdRepoList.Select(x => x.Clone())];
this.thirdRepoListChanged = false; this.thirdRepoListChanged = false;
this.IsValid = true;
} }
public override void Save() public override void Save()
@ -50,9 +51,12 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
var addedPendingRepo = this.TryAddTempRepo(); var addedPendingRepo = this.TryAddTempRepo();
if (!addedPendingRepo && hasPendingRepo) if (!addedPendingRepo && hasPendingRepo)
{ {
this.IsValid = false;
return; return;
} }
this.IsValid = true;
Service<DalamudConfiguration>.Get().ThirdRepoList = Service<DalamudConfiguration>.Get().ThirdRepoList =
[.. this.thirdRepoList.Select(x => x.Clone())]; [.. this.thirdRepoList.Select(x => x.Clone())];
@ -179,6 +183,8 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
var url = thirdRepoSetting.Url; var url = thirdRepoSetting.Url;
if (ImGui.InputText($"##thirdRepoInput", ref url, 65535, ImGuiInputTextFlags.EnterReturnsTrue)) if (ImGui.InputText($"##thirdRepoInput", ref url, 65535, ImGuiInputTextFlags.EnterReturnsTrue))
{ {
this.IsValid = true;
var contains = this.thirdRepoList.Select(repo => repo.Url).Contains(url); var contains = this.thirdRepoList.Select(repo => repo.Url).Contains(url);
if (thirdRepoSetting.Url == url) if (thirdRepoSetting.Url == url)
{ {
@ -196,8 +202,8 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
} }
else else
{ {
this.thirdRepoListChanged = thirdRepoSetting.Url != url;
thirdRepoSetting.Url = url; thirdRepoSetting.Url = url;
this.thirdRepoListChanged = url != thirdRepoSetting.Url;
} }
} }
@ -236,8 +242,10 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
ImGui.Text(repoNumber.ToString()); ImGui.Text(repoNumber.ToString());
ImGui.NextColumn(); ImGui.NextColumn();
ImGui.SetNextItemWidth(-1); ImGui.SetNextItemWidth(-1);
ImGui.InputText("##thirdRepoUrlInput"u8, ref this.thirdRepoTempUrl, 300); if (ImGui.InputText("##thirdRepoUrlInput"u8, ref this.thirdRepoTempUrl, 300))
ImGui.NextColumn(); {
this.IsValid = true;
} ImGui.NextColumn();
// Enabled button // Enabled button
ImGui.NextColumn(); ImGui.NextColumn();
if (!string.IsNullOrEmpty(this.thirdRepoTempUrl) && ImGuiComponents.IconButton(FontAwesomeIcon.Plus)) if (!string.IsNullOrEmpty(this.thirdRepoTempUrl) && ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
@ -267,6 +275,7 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
{ {
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); Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty);
this.IsValid = false;
return false; return false;
} }
@ -274,6 +283,7 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
{ {
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); Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty);
this.IsValid = false;
return false; return false;
} }
@ -284,6 +294,7 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
}); });
this.thirdRepoListChanged = true; this.thirdRepoListChanged = true;
this.thirdRepoTempUrl = string.Empty; this.thirdRepoTempUrl = string.Empty;
this.IsValid = true;
return true; return true;
} }