Merge pull request #3 from deansheather/dean/copy-to-clipboard
feat: copy directly to clipboard, add copy content option
This commit is contained in:
+33
-19
@@ -106,6 +106,7 @@ public sealed class PayloadHandler {
|
|||||||
if (registered.Count == 0) {
|
if (registered.Count == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ImGui.Separator();
|
||||||
|
|
||||||
var contentId = chunk.Message?.ContentId ?? 0;
|
var contentId = chunk.Message?.ContentId ?? 0;
|
||||||
var sender = chunk.Message?.Sender.Select(c => c.Link).FirstOrDefault(p => p is PlayerPayload) as PlayerPayload;
|
var sender = chunk.Message?.Sender.Select(c => c.Link).FirstOrDefault(p => p is PlayerPayload) as PlayerPayload;
|
||||||
@@ -131,14 +132,19 @@ public sealed class PayloadHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ContextFooter(bool separator, Chunk chunk) {
|
private void ContextFooter(bool didCustomContext, Chunk chunk) {
|
||||||
if (separator) {
|
if (didCustomContext) {
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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)) {
|
if (!ImGui.BeginMenu(Plugin.PluginName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.Checkbox(Language.Context_ScreenshotMode, ref LogWindow.ScreenshotMode);
|
ImGui.Checkbox(Language.Context_ScreenshotMode, ref LogWindow.ScreenshotMode);
|
||||||
|
|
||||||
@@ -147,21 +153,16 @@ public sealed class PayloadHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (chunk.Message is { } message) {
|
if (chunk.Message is { } message) {
|
||||||
if (ImGui.BeginMenu(Language.Context_Copy)) {
|
if (ImGui.Selectable(Language.Context_Copy)) {
|
||||||
var text = message.Sender
|
ImGui.SetClipboardText(StringifyMessage(message, true));
|
||||||
.Concat(message.Content)
|
WrapperUtil.AddNotification(Language.Context_CopySuccess, NotificationType.Info);
|
||||||
.Where(chunk => chunk is TextChunk)
|
}
|
||||||
.Cast<TextChunk>()
|
|
||||||
.Select(text => text.Content)
|
// Only show a separate "Copy content" option if the message has
|
||||||
.Aggregate(string.Concat);
|
// Sender chunks so it doesn't show for system messages.
|
||||||
ImGui.InputTextMultiline(
|
if (message.Sender.Count > 0 && ImGui.Selectable(Language.Context_CopyContent)) {
|
||||||
"##chat2-copy",
|
ImGui.SetClipboardText(StringifyMessage(message, false));
|
||||||
ref text,
|
WrapperUtil.AddNotification(Language.Context_CopyContentSuccess, NotificationType.Info);
|
||||||
(uint) text.Length,
|
|
||||||
new Vector2(350, 100) * ImGuiHelpers.GlobalScale,
|
|
||||||
ImGuiInputTextFlags.ReadOnly
|
|
||||||
);
|
|
||||||
ImGui.EndMenu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var col = ImGui.GetStyle().Colors[(int) ImGuiCol.TextDisabled];
|
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<TextChunk>()
|
||||||
|
.Select(text => text.Content)
|
||||||
|
.Aggregate(string.Concat);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Click(Chunk chunk, Payload? payload, ImGuiMouseButton button) {
|
internal void Click(Chunk chunk, Payload? payload, ImGuiMouseButton button) {
|
||||||
|
|||||||
Generated
+26
@@ -1031,6 +1031,24 @@ namespace ChatTwo.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Copy content.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Context_CopyContent {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Context_CopyContent", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Copied message content to clipboard.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Context_CopyContentSuccess {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Context_CopyContentSuccess", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Copy Item Name.
|
/// Looks up a localized string similar to Copy Item Name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1041,6 +1059,14 @@ namespace ChatTwo.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Copied message to clipboard.
|
||||||
|
/// </summary>
|
||||||
|
internal static string Context_CopySuccess {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Context_CopySuccess", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Looks up a localized string similar to Copy link to clipboard.
|
/// Looks up a localized string similar to Copy link to clipboard.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string Context_CopyLink {
|
internal static string Context_CopyLink {
|
||||||
|
|||||||
@@ -859,18 +859,28 @@
|
|||||||
<data name="Migration_Line4">
|
<data name="Migration_Line4">
|
||||||
<value>Do not close FFXIV, unload Dalamud, or turn off your computer during this time.</value>
|
<value>Do not close FFXIV, unload Dalamud, or turn off your computer during this time.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Context_AdventurerPlate" xml:space="preserve">
|
<data name="Context_AdventurerPlate">
|
||||||
<value>View Adventurer Plate</value>
|
<value>View Adventurer Plate</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Context_AdventurerPlateError" xml:space="preserve">
|
<data name="Context_AdventurerPlateError">
|
||||||
<value>Unable to open adventurer plate at this moment</value>
|
<value>Unable to open adventurer plate at this moment</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Options_TooltipOffset_Name" xml:space="preserve">
|
<data name="Options_TooltipOffset_Name">
|
||||||
<value>Tooltip offset </value>
|
<value>Tooltip offset </value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Options_TooltipOffset_Desc" xml:space="preserve">
|
<data name="Options_TooltipOffset_Desc">
|
||||||
<value>Use this option if you experience cut-off tooltips.</value>
|
<value>Use this option if you experience cut-off tooltips.</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
<data name="Context_CopyContent">
|
||||||
|
<value>Copy content</value>
|
||||||
|
</data>
|
||||||
|
<data name="Context_CopyContentSuccess">
|
||||||
|
<value>Copied message content to clipboard</value>
|
||||||
|
</data>
|
||||||
|
<data name="Context_CopySuccess">
|
||||||
|
<value>Copied message to clipboard</value>
|
||||||
|
</data>
|
||||||
<data name="Context_CopyLink" xml:space="preserve">
|
<data name="Context_CopyLink" xml:space="preserve">
|
||||||
<value>Copy link to clipboard</value>
|
<value>Copy link to clipboard</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
Reference in New Issue
Block a user