1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-25 17:59:24 +01:00

Added TextField.OnCopyPasteException to allow handling exceptions thrown by TextCopy

This commit is contained in:
Ell 2022-12-22 11:39:07 +01:00
parent df2b9cc10e
commit 73abfb2dc3
2 changed files with 24 additions and 1 deletions

View file

@ -67,6 +67,7 @@ Improvements
- Added trimming and AOT annotations and made MLEM.Ui trimmable
- Ensure paragraphs display up-to-date versions of their text callbacks
- Set cornflower blue as the default link color
- Added TextField.OnCopyPasteException to allow handling exceptions thrown by TextCopy
Fixes
- Fixed parents of elements that prevent spill not being notified properly

View file

@ -1,3 +1,4 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
@ -32,6 +33,14 @@ namespace MLEM.Ui.Elements {
/// <inheritdoc cref="TextInput.FileNames"/>
public static readonly Rule FileNames = (field, add) => TextInput.FileNames(field.textInput, add);
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
/// <summary>
/// An event that is raised when an exception is thrown while trying to copy or paste clipboard contents using TextCopy.
/// If no event handlers are added, the exception is ignored.
/// </summary>
public static event Action<Exception> OnCopyPasteException;
#endif
/// <summary>
/// The color that this text field's text should display with
/// </summary>
@ -147,7 +156,20 @@ namespace MLEM.Ui.Elements {
public TextField(Anchor anchor, Vector2 size, Rule rule = null, GenericFont font = null, string text = null, bool multiline = false) : base(anchor, size) {
this.textInput = new TextInput(null, Vector2.Zero, 1
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
, null, ClipboardService.SetText, ClipboardService.GetText
, null, s => {
try {
ClipboardService.SetText(s);
} catch (Exception e) {
TextField.OnCopyPasteException?.Invoke(e);
}
}, () => {
try {
return ClipboardService.GetText();
} catch (Exception e) {
TextField.OnCopyPasteException?.Invoke(e);
return null;
}
}
#endif
) {
OnTextChange = (i, s) => this.OnTextChange?.Invoke(this, s),