Merge pull request '#9: Added validation on saving/creation of folders on name check.' (#22) from folders-name-limit into 1.11.6

Reviewed-on: #22
Reviewed-by: defnotken <defnotken@noreply.git.lightless-sync.org>
This commit was merged in pull request #22.
This commit is contained in:
2025-09-11 01:32:19 +02:00
5 changed files with 38 additions and 18 deletions

View File

@@ -3,7 +3,6 @@ using LightlessSync.API.Routes;
using LightlessSync.LightlessConfiguration;
using LightlessSync.LightlessConfiguration.Models;
using LightlessSync.Services.Mediator;
using LightlessSync.UI.Components;
using LightlessSync.WebAPI;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.Extensions.Logging;
@@ -26,6 +25,7 @@ public class ServerConfigurationManager
private readonly NotesConfigService _notesConfig;
private readonly PairTagConfigService _pairTagConfig;
private readonly SyncshellTagConfigService _syncshellTagConfig;
private readonly int _maxCharactersFolder = 20;
public ServerConfigurationManager(ILogger<ServerConfigurationManager> logger, ServerConfigService configService,
PairTagConfigService pairTagConfig, SyncshellTagConfigService syncshellTagConfig, NotesConfigService notesConfig, DalamudUtilService dalamudUtil,
@@ -299,16 +299,30 @@ public class ServerConfigurationManager
internal void AddPairTag(string tag)
{
CurrentPairTagStorage().ServerAvailablePairTags.Add(tag);
_pairTagConfig.Save();
_lightlessMediator.Publish(new RefreshUiMessage());
if (tag.Length > _maxCharactersFolder)
{
CurrentPairTagStorage().ServerAvailablePairTags.Add(tag);
_pairTagConfig.Save();
_lightlessMediator.Publish(new RefreshUiMessage());
}
else
{
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", tag);
}
}
internal void AddSyncshellTag(string tag)
{
CurrentSyncshellTagStorage().ServerAvailableSyncshellTags.Add(tag);
_syncshellTagConfig.Save();
_lightlessMediator.Publish(new RefreshUiMessage());
if (tag.Length > _maxCharactersFolder)
{
CurrentSyncshellTagStorage().ServerAvailableSyncshellTags.Add(tag);
_syncshellTagConfig.Save();
_lightlessMediator.Publish(new RefreshUiMessage());
}
else
{
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", tag);
}
}
internal void AddTagForUid(string uid, string tagName)
@@ -454,7 +468,6 @@ public class ServerConfigurationManager
RemoveTagForUid(uid, tag, save: false);
}
}
}
internal void RemoveTagForUid(string uid, string tagName, bool save = true)
@@ -491,14 +504,21 @@ public class ServerConfigurationManager
internal void RenameTag(Dictionary<string, List<string>> tags, HashSet<string> storage, string oldName, string newName)
{
storage.Remove(oldName);
storage.Add(newName);
foreach (var existingTags in tags.Select(k => k.Value))
if (newName.Length > _maxCharactersFolder)
{
if (existingTags.Remove(oldName))
existingTags.Add(newName);
storage.Remove(oldName);
storage.Add(newName);
foreach (var existingTags in tags.Select(k => k.Value))
{
if (existingTags.Remove(oldName))
existingTags.Add(newName);
}
_lightlessMediator.Publish(new RefreshUiMessage());
}
else
{
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", newName);
}
_lightlessMediator.Publish(new RefreshUiMessage());
}
internal void SaveNotes() => _notesConfig.Save();

View File

@@ -48,7 +48,7 @@ public class RenamePairTagUi
{
ImGui.TextUnformatted($"Renaming {_tag}");
ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 255, ImGuiInputTextFlags.None);
ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 20, ImGuiInputTextFlags.None);
using (ImRaii.Disabled(string.IsNullOrEmpty(_desiredName)))
{
if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Rename Group"))

View File

@@ -48,7 +48,7 @@ public class RenameSyncshellTagUi
{
ImGui.TextUnformatted($"Renaming {_tag}");
ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 255, ImGuiInputTextFlags.None);
ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 20, ImGuiInputTextFlags.None);
using (ImRaii.Disabled(string.IsNullOrEmpty(_desiredName)))
{
if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Rename Group"))

View File

@@ -80,7 +80,7 @@ public class SelectTagForPairUi
HandleAddTag();
}
ImGui.SameLine();
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40);
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 20);
if (ImGui.IsKeyDown(ImGuiKey.Enter))
{
HandleAddTag();

View File

@@ -78,7 +78,7 @@ public class SelectTagForSyncshellUi
HandleAddTag();
}
ImGui.SameLine();
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40);
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 20);
if (ImGui.IsKeyDown(ImGuiKey.Enter))
{
HandleAddTag();