From d9d1e9acf6d24decfb687cba97b6efd8d66f5318 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Sat, 15 Jan 2022 14:34:31 -0500 Subject: [PATCH] feat: add /clearlog2 --- ChatTwo/Configuration.cs | 6 ++++++ ChatTwo/Ui/ChatLog.cs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 246d77d..669a822 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -73,6 +73,12 @@ internal class Tab { } } + internal void Clear() { + this.MessagesMutex.WaitOne(); + this.Messages.Clear(); + this.MessagesMutex.ReleaseMutex(); + } + internal Tab Clone() { return new Tab { Name = this.Name, diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index ac71347..164f8d4 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -1,6 +1,7 @@ using System.Numerics; using ChatTwo.Code; using ChatTwo.Util; +using Dalamud.Game.Command; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface; using ImGuiNET; @@ -26,6 +27,9 @@ internal sealed class ChatLog : IUiComponent { internal ChatLog(PluginUi ui) { this.Ui = ui; this.PayloadHandler = new PayloadHandler(this.Ui, this); + this.Ui.Plugin.CommandManager.AddHandler("/clearlog2", new CommandInfo(this.ClearLog) { + HelpMessage = "Clears the Chat 2 chat log", + }); this._fontIcon = this.Ui.Plugin.DataManager.GetImGuiTexture("common/font/fonticon_ps5.tex"); @@ -35,6 +39,7 @@ internal sealed class ChatLog : IUiComponent { public void Dispose() { this.Ui.Plugin.Functions.Chat.Activated -= this.Activated; this._fontIcon?.Dispose(); + this.Ui.Plugin.CommandManager.RemoveHandler("/clearlog2"); } private void Activated(string? input) { @@ -44,6 +49,33 @@ internal sealed class ChatLog : IUiComponent { } } + private void ClearLog(string command, string arguments) { + switch (arguments) { + case "all": + using (var messages = this.Ui.Plugin.Store.GetMessages()) { + messages.Messages.Clear(); + } + + foreach (var tab in this.Ui.Plugin.Config.Tabs) { + tab.Clear(); + } + + break; + case "help": + this.Ui.Plugin.ChatGui.Print("- /clearlog2: clears the active tab's log"); + this.Ui.Plugin.ChatGui.Print("- /clearlog2 all: clears all tabs' logs and the global history"); + this.Ui.Plugin.ChatGui.Print("- /clearlog2 help: shows this help"); + + break; + default: + if (this._lastTab > -1 && this._lastTab < this.Ui.Plugin.Config.Tabs.Count) { + this.Ui.Plugin.Config.Tabs[this._lastTab].Clear(); + } + + break; + } + } + private void AddBacklog(string message) { for (var i = 0; i < this._inputBacklog.Count; i++) { if (this._inputBacklog[i] != message) {