mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
Added TextField.OnCopyPasteException to allow handling exceptions thrown by TextCopy
This commit is contained in:
parent
df2b9cc10e
commit
73abfb2dc3
2 changed files with 24 additions and 1 deletions
|
@ -67,6 +67,7 @@ Improvements
|
||||||
- Added trimming and AOT annotations and made MLEM.Ui trimmable
|
- Added trimming and AOT annotations and made MLEM.Ui trimmable
|
||||||
- Ensure paragraphs display up-to-date versions of their text callbacks
|
- Ensure paragraphs display up-to-date versions of their text callbacks
|
||||||
- Set cornflower blue as the default link color
|
- Set cornflower blue as the default link color
|
||||||
|
- Added TextField.OnCopyPasteException to allow handling exceptions thrown by TextCopy
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed parents of elements that prevent spill not being notified properly
|
- Fixed parents of elements that prevent spill not being notified properly
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MLEM.Font;
|
using MLEM.Font;
|
||||||
|
@ -32,6 +33,14 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <inheritdoc cref="TextInput.FileNames"/>
|
/// <inheritdoc cref="TextInput.FileNames"/>
|
||||||
public static readonly Rule FileNames = (field, add) => TextInput.FileNames(field.textInput, add);
|
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>
|
/// <summary>
|
||||||
/// The color that this text field's text should display with
|
/// The color that this text field's text should display with
|
||||||
/// </summary>
|
/// </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) {
|
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
|
this.textInput = new TextInput(null, Vector2.Zero, 1
|
||||||
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
|
#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
|
#endif
|
||||||
) {
|
) {
|
||||||
OnTextChange = (i, s) => this.OnTextChange?.Invoke(this, s),
|
OnTextChange = (i, s) => this.OnTextChange?.Invoke(this, s),
|
||||||
|
|
Loading…
Reference in a new issue