mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: add clipboard image handling for pasting and staging attachments
This commit is contained in:
@@ -87,6 +87,18 @@ public sealed partial class MainWindow : Runnable
|
||||
/// </summary>
|
||||
public event Action<string, string>? OnMessageSubmitted;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when local files arrive via paste or drag-and-drop to be staged as attachments.
|
||||
/// Parameters: channel name, absolute paths of existing files.
|
||||
/// </summary>
|
||||
public event Action<string, IReadOnlyList<string>>? OnFilesStaged;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when raw image data is pasted from the clipboard (e.g. copied from a browser or a
|
||||
/// screenshot tool). Parameters: channel name, PNG-encoded image bytes.
|
||||
/// </summary>
|
||||
public event Action<string, byte[]>? OnImagePasted;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when the user requests to connect via the menu.
|
||||
/// </summary>
|
||||
@@ -744,11 +756,15 @@ public sealed partial class MainWindow : Runnable
|
||||
}
|
||||
else if (e.KeyCode == CtrlVKey.KeyCode || e.KeyCode == CtrlYKey.KeyCode)
|
||||
{
|
||||
// If a file was copied in the OS file manager, the clipboard holds a file list
|
||||
// (not text) — attach it. Otherwise paste text. This is the reliable path on
|
||||
// Windows Terminal, which never pastes copied files as text.
|
||||
// Discord-style paste priority. Copied files in the OS file manager put a file
|
||||
// list (not text) on the clipboard — attach them all. Copied image data (browser
|
||||
// right-click copy, screenshot tools) is attached as a PNG. Otherwise paste text.
|
||||
// Terminals never deliver either of the first two as text, so this is the only path.
|
||||
if (ClipboardFiles.TryGetFiles(out var pastedFiles))
|
||||
StageFiles(pastedFiles);
|
||||
else if (!string.IsNullOrEmpty(_messageManager.CurrentChannel)
|
||||
&& ClipboardImage.TryGetPng(out var pastedPng))
|
||||
OnImagePasted?.Invoke(_messageManager.CurrentChannel, pastedPng);
|
||||
else
|
||||
GuardedClipboardAction(() => _inputField.Paste(), "paste");
|
||||
e.Handled = true;
|
||||
@@ -872,17 +888,16 @@ public sealed partial class MainWindow : Runnable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Routes files (from a drop or a file-clipboard paste) through the /send pipeline, which
|
||||
/// stages them; the next Enter sends them with any typed caption.
|
||||
/// Stages files (from a drop or a file-clipboard paste) as attachments in one batch; the
|
||||
/// next Enter sends them with any typed caption.
|
||||
/// </summary>
|
||||
private void StageFiles(IEnumerable<string> files)
|
||||
private void StageFiles(IReadOnlyList<string> files)
|
||||
{
|
||||
var channel = _messageManager.CurrentChannel;
|
||||
if (string.IsNullOrEmpty(channel))
|
||||
return;
|
||||
|
||||
foreach (var file in files)
|
||||
OnMessageSubmitted?.Invoke(channel, $"/send \"{file}\"");
|
||||
OnFilesStaged?.Invoke(channel, files);
|
||||
}
|
||||
|
||||
private void OnChatViewportChanged()
|
||||
|
||||
Reference in New Issue
Block a user