From abe5505734601fbc7e9d71f5c38508c3768de50b Mon Sep 17 00:00:00 2001 From: CakeAndBanana Date: Tue, 9 Sep 2025 06:25:11 +0200 Subject: [PATCH] Fixed deleting of syncshell tags --- .../ServerConfigurationManager.cs | 76 +++++++------------ .../DrawGroupedSyncshellTagFolder.cs | 7 +- 2 files changed, 30 insertions(+), 53 deletions(-) diff --git a/LightlessSync/Services/ServerConfiguration/ServerConfigurationManager.cs b/LightlessSync/Services/ServerConfiguration/ServerConfigurationManager.cs index 205b517..1aebde3 100644 --- a/LightlessSync/Services/ServerConfiguration/ServerConfigurationManager.cs +++ b/LightlessSync/Services/ServerConfiguration/ServerConfigurationManager.cs @@ -347,10 +347,7 @@ public class ServerConfigurationManager _syncshellTagConfig.Save(); } - internal bool ContainsOpenPairTag(string tag) - { - return CurrentPairTagStorage().OpenPairTags.Contains(tag); - } + internal bool ContainsOpenPairTag(string tag) => CurrentPairTagStorage().OpenPairTags.Contains(tag); internal bool ContainsPairTag(string uid, string tag) { @@ -405,40 +402,19 @@ public class ServerConfigurationManager return null; } - internal HashSet GetServerAvailablePairTags() - { - return CurrentPairTagStorage().ServerAvailablePairTags; - } + internal HashSet GetServerAvailablePairTags() => CurrentPairTagStorage().ServerAvailablePairTags; - internal HashSet GetServerAvailableSyncshellTags() - { - return CurrentSyncshellTagStorage().ServerAvailableSyncshellTags; - } + internal HashSet GetServerAvailableSyncshellTags() => CurrentSyncshellTagStorage().ServerAvailableSyncshellTags; - internal Dictionary> GetUidServerPairedUserTags() - { - return CurrentPairTagStorage().UidServerPairedUserTags; - } + internal Dictionary> GetUidServerPairedUserTags() => CurrentPairTagStorage().UidServerPairedUserTags; - internal HashSet GetUidsForPairTag(string tag) - { - return CurrentPairTagStorage().UidServerPairedUserTags.Where(p => p.Value.Contains(tag, StringComparer.Ordinal)).Select(p => p.Key).ToHashSet(StringComparer.Ordinal); - } + internal HashSet GetUidsForPairTag(string tag) => CurrentPairTagStorage().UidServerPairedUserTags.Where(p => p.Value.Contains(tag, StringComparer.Ordinal)).Select(p => p.Key).ToHashSet(StringComparer.Ordinal); - internal HashSet GetNamesForSyncshellTag(string tag) - { - return CurrentSyncshellTagStorage().SyncshellPairedTags.Where(p => p.Value.Contains(tag, StringComparer.Ordinal)).Select(p => p.Key).ToHashSet(StringComparer.Ordinal); - } + internal HashSet GetNamesForSyncshellTag(string tag) => CurrentSyncshellTagStorage().SyncshellPairedTags.Where(p => p.Value.Contains(tag, StringComparer.Ordinal)).Select(p => p.Key).ToHashSet(StringComparer.Ordinal); - internal bool HasPairTags(string uid) - { - return CurrentPairTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags) && tags.Count != 0; - } + internal bool HasPairTags(string uid) => CurrentPairTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags) && tags.Count != 0; - internal bool HasSyncshellTags(string name) - { - return CurrentSyncshellTagStorage().SyncshellPairedTags.TryGetValue(name, out var tags) && tags.Count != 0; - } + internal bool HasSyncshellTags(string name) => CurrentSyncshellTagStorage().SyncshellPairedTags.TryGetValue(name, out var tags) && tags.Count != 0; internal void RemoveCharacterFromServer(int serverSelectionIndex, Authentication item) { @@ -468,18 +444,29 @@ public class ServerConfigurationManager internal void RemoveSyncshellTag(string tag) { - RemoveTag(CurrentSyncshellTagStorage().ServerAvailableSyncshellTags, tag); + RemoveTag(CurrentSyncshellTagStorage().ServerAvailableSyncshellTags, tag, true); _syncshellTagConfig.Save(); _lightlessMediator.Publish(new RefreshUiMessage()); } - internal void RemoveTag(HashSet storage, string tag) + internal void RemoveTag(HashSet storage, string tag, bool syncshell = false) { - CurrentPairTagStorage().ServerAvailablePairTags.Remove(tag); - foreach (var uid in GetUidsForPairTag(tag)) + storage.Remove(tag); + if (syncshell) { - RemoveTagForUid(uid, tag, save: false); + foreach (var uid in GetNamesForSyncshellTag(tag)) + { + RemoveTagForSyncshell(uid, tag, save: false); + } } + else + { + foreach (var uid in GetUidsForPairTag(tag)) + { + RemoveTagForUid(uid, tag, save: false); + } + } + } internal void RemoveTagForUid(string uid, string tagName, bool save = true) @@ -510,15 +497,9 @@ public class ServerConfigurationManager } } - internal void RenamePairTag(string oldName, string newName) - { - RenameTag(CurrentPairTagStorage().UidServerPairedUserTags, CurrentPairTagStorage().ServerAvailablePairTags, oldName, newName); - } + internal void RenamePairTag(string oldName, string newName) => RenameTag(CurrentPairTagStorage().UidServerPairedUserTags, CurrentPairTagStorage().ServerAvailablePairTags, oldName, newName); - internal void RenameSyncshellTag(string oldName, string newName) - { - RenameTag(CurrentSyncshellTagStorage().SyncshellPairedTags, CurrentSyncshellTagStorage().ServerAvailableSyncshellTags, oldName, newName); - } + internal void RenameSyncshellTag(string oldName, string newName) => RenameTag(CurrentSyncshellTagStorage().SyncshellPairedTags, CurrentSyncshellTagStorage().ServerAvailableSyncshellTags, oldName, newName); internal void RenameTag(Dictionary> tags, HashSet storage, string oldName, string newName) { @@ -532,10 +513,7 @@ public class ServerConfigurationManager _lightlessMediator.Publish(new RefreshUiMessage()); } - internal void SaveNotes() - { - _notesConfig.Save(); - } + internal void SaveNotes() => _notesConfig.Save(); internal void SetNoteForGid(string gid, string note, bool save = true) { diff --git a/LightlessSync/UI/Components/DrawGroupedSyncshellTagFolder.cs b/LightlessSync/UI/Components/DrawGroupedSyncshellTagFolder.cs index 221f453..8401e9a 100644 --- a/LightlessSync/UI/Components/DrawGroupedSyncshellTagFolder.cs +++ b/LightlessSync/UI/Components/DrawGroupedSyncshellTagFolder.cs @@ -40,7 +40,7 @@ public class DrawGroupedSyncshellTagFolder : IDrawFolder string _id = $"__folder_{_tag}"; using var id = ImRaii.PushId(_id); var color = ImRaii.PushColor(ImGuiCol.ChildBg, ImGui.GetColorU32(ImGuiCol.FrameBgHovered), _wasHovered); - using (ImRaii.Child("folder__" + _id, new System.Numerics.Vector2(UiSharedService.GetWindowContentRegionWidth() - ImGui.GetCursorPosX(), ImGui.GetFrameHeight()))) + using (ImRaii.Child("folder__" + _id, new Vector2(UiSharedService.GetWindowContentRegionWidth() - ImGui.GetCursorPosX(), ImGui.GetFrameHeight()))) { ImGui.Dummy(new Vector2(0f, ImGui.GetFrameHeight())); using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, new Vector2(0f, 0f))) @@ -122,9 +122,8 @@ public class DrawGroupedSyncshellTagFolder : IDrawFolder } if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Syncshell Group", menuWidth, isInPopup: true) && UiSharedService.CtrlPressed()) { - _tagHandler.RemovePairTag(_tag); + _tagHandler.RemoveSyncshellTag(_tag); } - UiSharedService.AttachToolTip("Hold CTRL to remove this Group permanently." + Environment.NewLine + - "Note: this will not unpair with users in this Group."); + UiSharedService.AttachToolTip("Hold CTRL to remove this Group permanently."); } }