Skip to content

Commit 8fff66f

Browse files
committed
renaming folders
1 parent 66d5499 commit 8fff66f

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

SomethingNeedDoing/Config.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,26 @@ public string GetUniqueMacroName(string baseName, string? excludeMacroId = null)
342342
return name;
343343
}
344344

345+
/// <summary>
346+
/// Renames a folder by updating all macros in that folder.
347+
/// </summary>
348+
public void RenameFolder(string oldFolderPath, string newFolderPath)
349+
{
350+
if (string.IsNullOrWhiteSpace(oldFolderPath) || string.IsNullOrWhiteSpace(newFolderPath))
351+
return;
352+
353+
if (oldFolderPath == newFolderPath)
354+
return;
355+
356+
if (GetFolderPaths().Any(f => f == newFolderPath))
357+
return;
358+
359+
foreach (var macro in GetMacrosInFolder(oldFolderPath).ToList())
360+
macro.FolderPath = newFolderPath;
361+
362+
Save();
363+
}
364+
345365
/// <summary>
346366
/// Sets a property value by name.
347367
/// </summary>

SomethingNeedDoing/Gui/MainWindow.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public override void Draw()
7272
CreateMacroModal.DrawModal();
7373
CreateFolderModal.DrawModal();
7474
RenameModal.DrawModal();
75+
RenameFolderModal.DrawModal();
7576
MigrationModal.DrawModal();
7677
FirstTimeWarningModal.DrawModal();
7778
_versionHistoryModal.Draw();
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using Dalamud.Interface.Colors;
2+
using Dalamud.Interface.Utility.Raii;
3+
using ECommons.ImGuiMethods;
4+
5+
namespace SomethingNeedDoing.Gui.Modals;
6+
public static class RenameFolderModal
7+
{
8+
private static Vector2 Size = new(400, 150);
9+
private static bool IsOpen = false;
10+
11+
private static string _renameFolderBuffer = string.Empty;
12+
private static string _folderToRename = string.Empty;
13+
14+
public static void Open(string folderPath)
15+
{
16+
IsOpen = true;
17+
_renameFolderBuffer = folderPath;
18+
_folderToRename = folderPath;
19+
}
20+
21+
public static void Close()
22+
{
23+
IsOpen = false;
24+
ImGui.CloseCurrentPopup();
25+
}
26+
27+
public static void DrawModal()
28+
{
29+
if (!IsOpen) return;
30+
31+
ImGui.OpenPopup($"RenameFolderPopup##{nameof(RenameFolderModal)}");
32+
33+
ImGui.SetNextWindowPos(ImGui.GetMainViewport().GetCenter(), ImGuiCond.Appearing, new Vector2(0.5f, 0.5f));
34+
ImGui.SetNextWindowSize(Size);
35+
36+
using var style = ImRaii.PushStyle(ImGuiStyleVar.WindowPadding, new Vector2(15, 15));
37+
using var popup = ImRaii.PopupModal($"RenameFolderPopup##{nameof(RenameFolderModal)}", ref IsOpen, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoTitleBar);
38+
if (!popup) return;
39+
40+
ImGuiEx.Icon(FontAwesomeHelper.IconRename);
41+
ImGui.SameLine();
42+
ImGui.Text("Rename Folder");
43+
ImGui.Separator();
44+
ImGui.Spacing();
45+
46+
ImGui.Text("Enter new folder name:");
47+
ImGui.SetNextItemWidth(-1);
48+
ImGuiUtils.SetFocusIfAppearing();
49+
50+
var enterPressed = ImGui.IsKeyPressed(ImGuiKey.Enter) && ImGui.IsWindowFocused();
51+
52+
using (ImRaii.PushColor(ImGuiCol.FrameBg, new Vector4(0.15f, 0.15f, 0.15f, 1.0f)))
53+
ImGui.InputText("##RenameFolderInput", ref _renameFolderBuffer, 100);
54+
55+
ImGui.Spacing();
56+
ImGui.Separator();
57+
ImGui.Spacing();
58+
59+
var invalid = false;
60+
if (!string.IsNullOrEmpty(_renameFolderBuffer) && C.GetFolderPaths().Any(f => f == _renameFolderBuffer))
61+
{
62+
invalid = true;
63+
ImGuiEx.Text(ImGuiColors.DalamudRed, $"Folder name '{_renameFolderBuffer}' already exists.");
64+
}
65+
66+
var confirmed = false;
67+
using (ImRaii.Disabled(invalid))
68+
using (ImRaii.PushColor(ImGuiCol.Button, new Vector4(0.3f, 0.5f, 0.3f, 1.0f)).Push(ImGuiCol.ButtonHovered, new Vector4(0.4f, 0.6f, 0.4f, 1.0f)))
69+
confirmed = ImGui.Button("Rename", new Vector2(150, 0)) || enterPressed;
70+
71+
if (confirmed && !string.IsNullOrWhiteSpace(_renameFolderBuffer))
72+
{
73+
try
74+
{
75+
C.RenameFolder(_folderToRename, _renameFolderBuffer);
76+
Close();
77+
}
78+
catch (Exception ex)
79+
{
80+
Svc.Log.Error(ex, "Error renaming folder");
81+
}
82+
}
83+
84+
ImGui.SameLine();
85+
86+
using (ImRaii.PushColor(ImGuiCol.Button, new Vector4(0.5f, 0.3f, 0.3f, 1.0f)).Push(ImGuiCol.ButtonHovered, new Vector4(0.6f, 0.4f, 0.4f, 1.0f)))
87+
if (ImGui.Button("Cancel", new Vector2(150, 0)) || (ImGui.IsKeyPressed(ImGuiKey.Escape) && ImGui.IsWindowFocused()))
88+
Close();
89+
}
90+
}

SomethingNeedDoing/Gui/Tabs/MacrosTab.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ private void DrawFolderContextMenu(string folderPath)
220220
ImGui.TextColored(ImGuiColors.DalamudViolet, $"Folder: {folderPath}");
221221
ImGui.Separator();
222222

223+
if (ImGui.MenuItem("Rename Folder"))
224+
RenameFolderModal.Open(folderPath);
225+
223226
if (ImGui.MenuItem("Delete Folder"))
224227
{
225228
try

0 commit comments

Comments
 (0)