address box functionality improved according to
MODIFY
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
@@ -11,84 +11,132 @@ using System.Threading.Tasks;
namespace WalletWasabi.Gui.Behaviors
{
+
internal class PasteAddressOnClickBehavior : Behavior<TextBox>
{
private CompositeDisposable _disposables = new CompositeDisposable();
- public void PasteClipboardContentIfBitcoinAddress()
+ protected internal enum TextBoxState
+ {
+ None,
+ NormalTextBoxOperation,
+ AddressInsert,
+ SelectAll,
+ }
+
+ private TextBoxState MyTextBoxState
+ { get => _textBoxState;
+ set
+ {
+ _textBoxState = value;
+ switch (value)
{
- if(IsThereABitcoinAddressOnTheClipboard(out string address))
+ case TextBoxState.NormalTextBoxOperation:
{
- if(string.IsNullOrWhiteSpace(AssociatedObject.Text) )
- AssociatedObject.Text = address;
+ ToolTip.SetTip(AssociatedObject, _originalToolTipText);
+ ToolTip.SetIsOpen(AssociatedObject, false);
}
+ break;
+ case TextBoxState.AddressInsert:
+ {
+ ToolTip.SetTip(AssociatedObject, "Click to paste address from clipboard");
}
-
- public bool IsThereABitcoinAddressOnTheClipboard(out string address)
+ break;
+ case TextBoxState.SelectAll:
{
- address = string.Empty;
+ ToolTip.SetTip(AssociatedObject, "Click to select all");
+ }
+ break;
- var clipboard = (IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard));
- // TODO: fix this
- var clipboardTask = clipboard.GetTextAsync();
- Task.WaitAny(Task.Delay(10), clipboardTask);
- if(!clipboardTask.IsCompleted)
- {
- return false;
}
+ }
+ }
+ private string _originalToolTipText;
+ private string _addressToPaste;
+ private TextBoxState _textBoxState = TextBoxState.None;
- var text = clipboardTask.Result;
+ public async Task<(bool isAddress, string address)> IsThereABitcoinAddressOnTheClipboardAsync()
+ {
+ var clipboard = (IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard));
+ Task<string> clipboardTask = clipboard.GetTextAsync();
+ string text = await clipboardTask;
+ if (text.Length > 50) return (false, null);
+ text = text.Trim();
try
{
var bitcoinAddress = BitcoinAddress.Create(text, Global.Network);
- address = text;
- return bitcoinAddress is BitcoinWitPubKeyAddress;
+ return (bitcoinAddress is BitcoinWitPubKeyAddress, text);
}
catch (FormatException)
{
- return false;
+ return (false, null);
}
}
protected override void OnAttached()
{
+ _originalToolTipText = (string)ToolTip.GetTip(AssociatedObject);
_disposables = new CompositeDisposable
{
AssociatedObject.GetObservable(TextBox.IsFocusedProperty).Subscribe(focused =>
{
- if(focused)
- {
- if(string.IsNullOrWhiteSpace(AssociatedObject.Text))
- {
- PasteClipboardContentIfBitcoinAddress();
- }
- }
+ if (!focused)
+ MyTextBoxState = TextBoxState.None;
})
};
+
+
_disposables.Add(
AssociatedObject.GetObservable(TextBox.PointerReleasedEvent).Subscribe(pointer =>
{
- if(!string.IsNullOrWhiteSpace(AssociatedObject.Text))
+ switch (MyTextBoxState)
{
+ case TextBoxState.AddressInsert:
+ {
+ AssociatedObject.Text = _addressToPaste;
+ MyTextBoxState = TextBoxState.NormalTextBoxOperation;
+ var labeltextbox = AssociatedObject.Parent.FindControl<TextBox>("LabelTextBox");
+ if (labeltextbox != null) labeltextbox.Focus();
+ }
+ break;
+ case TextBoxState.SelectAll:
AssociatedObject.SelectionStart = 0;
- AssociatedObject.SelectionEnd = AssociatedObject.Text?.Length ?? 0;
+ AssociatedObject.SelectionEnd = AssociatedObject.Text.Length;
+ MyTextBoxState = TextBoxState.NormalTextBoxOperation;
+ break;
}
+
})
);
_disposables.Add(
- AssociatedObject.GetObservable(TextBox.PointerEnterEvent).Subscribe(pointerEnter =>
+ AssociatedObject.GetObservable(TextBox.PointerEnterEvent).Subscribe(async pointerEnter =>
+ {
+ if (MyTextBoxState == TextBoxState.NormalTextBoxOperation) return;
+ _addressToPaste = null;
+
+ if (string.IsNullOrEmpty(AssociatedObject.Text))
{
- if(IsThereABitcoinAddressOnTheClipboard(out string address))
+ var result = await IsThereABitcoinAddressOnTheClipboardAsync();
+ if (result.isAddress)
{
- ToolTip.SetTip(AssociatedObject, "Click to paste address from clipboard");
+ _addressToPaste = result.address;
+ MyTextBoxState = TextBoxState.AddressInsert;
+ ToolTip.SetIsOpen(AssociatedObject, true);
+ }
+ else
+ {
+ MyTextBoxState = TextBoxState.NormalTextBoxOperation;
+ }
}
else
{
- ToolTip.SetTip(AssociatedObject, "");
+ MyTextBoxState = TextBoxState.SelectAll;
}
+
+
})
);

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabView.xaml
WalletWasabi.Gui/Controls/WalletExplorer/SendTabView.xaml
<behaviors:PasteAddressOnClickBehavior />
</i:Interaction.Behaviors>
</controls:ExtendedTextBox>
- <controls:ExtendedTextBox Text="{Binding Label}" Watermark="Label" UseFloatingWatermark="True">
+ <controls:ExtendedTextBox x:Name="LabelTextBox" Text="{Binding Label}" Watermark="Label" UseFloatingWatermark="True">
<ToolTip.Tip>
Start labelling today and your privacy will thank you tomorrow!
</ToolTip.Tip>

address box functionality improved according to
https://gist.github.com/nopara73/322dbd263a5c45267da87cffc36de6f6