Skip to content

Commit

Permalink
[feat] Hold CTRL to Delete | [chore] More Raii
Browse files Browse the repository at this point in the history
  • Loading branch information
DueDine committed Jan 6, 2025
1 parent 3735edc commit 3bb38c2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions ContactsTracker/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public sealed class Plugin : IDalamudPlugin
[PluginService] internal static IDataManager DataManager { get; private set; } = null!;
[PluginService] internal static IPluginLog Logger { get; private set; } = null!;
[PluginService] internal static IPartyList PartyList { get; private set; } = null!;
[PluginService] internal static IKeyState KeyState { get; private set; } = null!;

private const string CommandName = "/ctracker";

Expand Down
52 changes: 29 additions & 23 deletions ContactsTracker/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Dalamud.Game.ClientState.Keys;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing;
Expand Down Expand Up @@ -34,24 +35,29 @@ public void Dispose() { }

public override void Draw()
{
if (ImGui.BeginTabBar("MainTabBar"))
using var tabBar = ImRaii.TabBar("MainTabBar");
if (!tabBar) return;

using (var activeTab = ImRaii.TabItem("Active"))
{
if (ImGui.BeginTabItem("Active"))
if (activeTab)
{
DrawActiveTab();
ImGui.EndTabItem();
}
if (ImGui.BeginTabItem("History"))
}
using (var historyTab = ImRaii.TabItem("History"))
{
if (historyTab)
{
DrawHistoryTab();
ImGui.EndTabItem();
}
if (ImGui.BeginTabItem("Settings"))
}
using (var settingsTab = ImRaii.TabItem("Settings"))
{
if (settingsTab)
{
DrawSettingsTab();
ImGui.EndTabItem();
}
ImGui.EndTabBar();
}
}

Expand Down Expand Up @@ -242,28 +248,28 @@ private void DrawHistoryTab()

if (ImGui.Button("Delete Entry"))
{
ImGui.OpenPopup("Confirm Deletion"); // Double check
}

if (ImGui.BeginPopupModal("Confirm Deletion"))
{
ImGuiHelpers.SafeTextWrapped("Are you sure you want to delete this entry?");
ImGui.Separator();

if (ImGui.Button("Yes"))
if (Plugin.KeyState[VirtualKey.CONTROL])
{
entries.RemoveAt(selectedTab);
Database.Save();

selectedTab = Math.Max(0, selectedTab - 1); // Avoid out of range
ImGui.CloseCurrentPopup();
if (selectedTab >= entries.Count)
{
selectedTab = Math.Max(-1, entries.Count - 1);
}
}
}

if (ImGui.IsItemHovered())
{
if (!Plugin.KeyState[VirtualKey.CONTROL])
{
ImGui.SetTooltip("Hold CTRL to Delete.");
}
ImGui.SameLine();
if (ImGui.Button("No"))
else
{
ImGui.CloseCurrentPopup();
ImGui.SetTooltip("This action is irreversible.");
}
ImGui.EndPopup();
}
}

Expand Down

0 comments on commit 3bb38c2

Please sign in to comment.