Merge branch 'main' into dean/extrachat-input-channels
This commit is contained in:
+89
-24
@@ -86,6 +86,11 @@ public sealed class PayloadHandler {
|
||||
drawn = true;
|
||||
break;
|
||||
}
|
||||
case URIPayload uri: {
|
||||
DrawUriPopup(uri);
|
||||
drawn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ContextFooter(drawn, chunk);
|
||||
@@ -100,11 +105,10 @@ public sealed class PayloadHandler {
|
||||
if (registered.Count == 0) {
|
||||
return;
|
||||
}
|
||||
ImGui.Separator();
|
||||
|
||||
var contentId = chunk.Message?.ContentId ?? 0;
|
||||
var sender = chunk.Message?.Sender
|
||||
.Select(chunk => chunk.Link)
|
||||
.FirstOrDefault(chunk => chunk is PlayerPayload) as PlayerPayload;
|
||||
var sender = chunk.Message?.Sender.Select(c => c.Link).FirstOrDefault(p => p is PlayerPayload) as PlayerPayload;
|
||||
|
||||
if (ImGui.BeginMenu(Language.Context_Integrations)) {
|
||||
var cursor = ImGui.GetCursorPos();
|
||||
@@ -127,13 +131,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);
|
||||
@@ -143,21 +152,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<TextChunk>()
|
||||
.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];
|
||||
@@ -172,7 +176,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) {
|
||||
@@ -215,6 +232,11 @@ public sealed class PayloadHandler {
|
||||
DoHover(() => HoverItem(item), hoverSize);
|
||||
break;
|
||||
}
|
||||
case URIPayload uri:
|
||||
{
|
||||
DoHover(() => HoverURI(uri), hoverSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,6 +356,11 @@ public sealed class PayloadHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void HoverURI(URIPayload uri) {
|
||||
ImGui.TextUnformatted(string.Format(Language.Context_URLDomain, uri.Uri.Authority));
|
||||
ImGuiUtil.WarningText(Language.Context_URLWarning);
|
||||
}
|
||||
|
||||
private void LeftClickPayload(Chunk chunk, Payload? payload) {
|
||||
switch (payload) {
|
||||
case MapLinkPayload map: {
|
||||
@@ -372,6 +399,10 @@ public sealed class PayloadHandler {
|
||||
|
||||
break;
|
||||
}
|
||||
case URIPayload uri: {
|
||||
TryOpenURI(uri.Uri);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,4 +656,38 @@ public sealed class PayloadHandler {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void DrawUriPopup(URIPayload uri)
|
||||
{
|
||||
ImGui.TextUnformatted(string.Format(Language.Context_URLDomain, uri.Uri.Authority));
|
||||
ImGuiUtil.WarningText(Language.Context_URLWarning, false);
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.Selectable(Language.Context_OpenInBrowser))
|
||||
{
|
||||
TryOpenURI(uri.Uri);
|
||||
}
|
||||
|
||||
if (ImGui.Selectable(Language.Context_CopyLink))
|
||||
{
|
||||
ImGui.SetClipboardText(uri.Uri.ToString());
|
||||
WrapperUtil.AddNotification(Language.Context_CopyLinkNotification, NotificationType.Info);
|
||||
}
|
||||
}
|
||||
|
||||
private void TryOpenURI(Uri uri)
|
||||
{
|
||||
new Thread(() => {
|
||||
try
|
||||
{
|
||||
Plugin.Log.Debug($"Opening URI {uri} in default browser");
|
||||
Dalamud.Utility.Util.OpenLink(uri.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Plugin.Log.Error($"Error opening URI: {ex}");
|
||||
WrapperUtil.AddNotification(Language.Context_OpenInBrowserError, NotificationType.Error);
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user