diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index 4f8aac6..4452d09 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -106,6 +106,7 @@ public sealed class PayloadHandler { if (registered.Count == 0) { return; } + ImGui.Separator(); var contentId = chunk.Message?.ContentId ?? 0; var sender = chunk.Message?.Sender.Select(c => c.Link).FirstOrDefault(p => p is PlayerPayload) as PlayerPayload; @@ -131,13 +132,18 @@ public sealed class PayloadHandler { } } - private void ContextFooter(bool separator, Chunk chunk) { - if (separator) { + private void ContextFooter(bool didCustomContext, Chunk chunk) { + if (didCustomContext) { ImGui.Separator(); - } - if (!ImGui.BeginMenu(Plugin.PluginName)) { - return; + // Only place these menu items in a submenu if we've already drawn + // custom context menu items based on the payload. + // + // It makes it much more convenient in the majority of cases to + // copy the message content without having to open a submenu. + if (!ImGui.BeginMenu(Plugin.PluginName)) { + return; + } } ImGui.Checkbox(Language.Context_ScreenshotMode, ref LogWindow.ScreenshotMode); @@ -147,21 +153,16 @@ public sealed class PayloadHandler { } if (chunk.Message is { } message) { - if (ImGui.BeginMenu(Language.Context_Copy)) { - var text = message.Sender - .Concat(message.Content) - .Where(chunk => chunk is TextChunk) - .Cast() - .Select(text => text.Content) - .Aggregate(string.Concat); - ImGui.InputTextMultiline( - "##chat2-copy", - ref text, - (uint) text.Length, - new Vector2(350, 100) * ImGuiHelpers.GlobalScale, - ImGuiInputTextFlags.ReadOnly - ); - ImGui.EndMenu(); + if (ImGui.Selectable(Language.Context_Copy)) { + ImGui.SetClipboardText(StringifyMessage(message, true)); + WrapperUtil.AddNotification(Language.Context_CopySuccess, NotificationType.Info); + } + + // Only show a separate "Copy content" option if the message has + // Sender chunks so it doesn't show for system messages. + if (message.Sender.Count > 0 && ImGui.Selectable(Language.Context_CopyContent)) { + ImGui.SetClipboardText(StringifyMessage(message, false)); + WrapperUtil.AddNotification(Language.Context_CopyContentSuccess, NotificationType.Info); } var col = ImGui.GetStyle().Colors[(int) ImGuiCol.TextDisabled]; @@ -176,7 +177,20 @@ public sealed class PayloadHandler { } } - ImGui.EndMenu(); + if (didCustomContext) ImGui.EndMenu(); + } + + internal static string StringifyMessage(Message message, bool withSender = false) + { + if (message == null) + return string.Empty; + + var chunks = withSender ? message.Sender.Concat(message.Content) : message.Content; + return chunks + .Where(chunk => chunk is TextChunk) + .Cast() + .Select(text => text.Content) + .Aggregate(string.Concat); } internal void Click(Chunk chunk, Payload? payload, ImGuiMouseButton button) { diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index deda984..8696c23 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -1031,6 +1031,24 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to Copy content. + /// + internal static string Context_CopyContent { + get { + return ResourceManager.GetString("Context_CopyContent", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Copied message content to clipboard. + /// + internal static string Context_CopyContentSuccess { + get { + return ResourceManager.GetString("Context_CopyContentSuccess", resourceCulture); + } + } + /// /// Looks up a localized string similar to Copy Item Name. /// @@ -1041,6 +1059,14 @@ namespace ChatTwo.Resources { } /// + /// Looks up a localized string similar to Copied message to clipboard. + /// + internal static string Context_CopySuccess { + get { + return ResourceManager.GetString("Context_CopySuccess", resourceCulture); + } + } + /// Looks up a localized string similar to Copy link to clipboard. /// internal static string Context_CopyLink { diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index 69cda28..374e688 100644 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -859,18 +859,28 @@ Do not close FFXIV, unload Dalamud, or turn off your computer during this time. - + View Adventurer Plate - + Unable to open adventurer plate at this moment - + Tooltip offset - + Use this option if you experience cut-off tooltips. + + + Copy content + + + Copied message content to clipboard + + + Copied message to clipboard + Copy link to clipboard