ClipboardTextOperations.cs 871 B

1234567891011121314151617181920212223242526272829303132
  1. namespace PicView.Avalonia.Clipboard;
  2. /// <summary>
  3. /// Handles clipboard operations related to text
  4. /// </summary>
  5. public static class ClipboardTextOperations
  6. {
  7. /// <summary>
  8. /// Copies text to the clipboard
  9. /// </summary>
  10. /// <param name="text">The text to copy</param>
  11. /// <returns>A task representing the asynchronous operation</returns>
  12. public static async Task<bool> CopyTextToClipboard(string text)
  13. {
  14. if (string.IsNullOrWhiteSpace(text))
  15. {
  16. return false;
  17. }
  18. var clipboard = ClipboardService.GetClipboard();
  19. if (clipboard == null)
  20. {
  21. return false;
  22. }
  23. return await ClipboardService.ExecuteClipboardOperation(async () =>
  24. {
  25. await clipboard.SetTextAsync(text);
  26. return true;
  27. }, showAnimation: true);
  28. }
  29. }