Browse Source

Merge branch 'master' into master

pull/8260/head
Max Katz 4 years ago
committed by GitHub
parent
commit
27480ae6b4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      native/Avalonia.Native/src/OSX/AvnWindow.mm
  2. 6
      src/Avalonia.Base/Reactive/TypedBindingAdapter.cs
  3. 7
      src/Avalonia.Controls/Button.cs
  4. 74
      tests/Avalonia.Controls.UnitTests/ButtonTests.cs

8
native/Avalonia.Native/src/OSX/AvnWindow.mm

@ -284,6 +284,14 @@
- (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification
{
_parent->BringToFront();
dispatch_async(dispatch_get_main_queue(), ^{
@try {
[self invalidateShadow];
}
@finally{
}
});
}
- (void)windowDidMiniaturize:(NSNotification *_Nonnull)notification

6
src/Avalonia.Base/Reactive/TypedBindingAdapter.cs

@ -30,13 +30,15 @@ namespace Avalonia.Reactive
}
catch (InvalidCastException e)
{
var unwrappedValue = value.HasValue ? value.Value : null;
Logger.TryGet(LogEventLevel.Error, LogArea.Binding)?.Log(
_target,
"Binding produced invalid value for {$Property} ({$PropertyType}): {$Value} ({$ValueType})",
_property.Name,
_property.PropertyType,
value.Value,
value.Value?.GetType());
unwrappedValue,
unwrappedValue?.GetType());
PublishNext(BindingValue<T>.BindingError(e));
}
}

7
src/Avalonia.Controls/Button.cs

@ -232,6 +232,13 @@ namespace Avalonia.Controls
StopListeningForDefault(inputElement);
}
}
if (IsCancel)
{
if (e.Root is IInputElement inputElement)
{
StopListeningForCancel(inputElement);
}
}
}
/// <inheritdoc/>

74
tests/Avalonia.Controls.UnitTests/ButtonTests.cs

@ -309,6 +309,80 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(0, raised);
}
[Fact]
public void Button_IsDefault_Works()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var raised = 0;
var target = new Button();
var window = new Window { Content = target };
window.Show();
target.Click += (s, e) => ++raised;
target.IsDefault = false;
window.RaiseEvent(CreateKeyDownEvent(Key.Enter));
Assert.Equal(0, raised);
target.IsDefault = true;
window.RaiseEvent(CreateKeyDownEvent(Key.Enter));
Assert.Equal(1, raised);
target.IsDefault = false;
window.RaiseEvent(CreateKeyDownEvent(Key.Enter));
Assert.Equal(1, raised);
target.IsDefault = true;
window.RaiseEvent(CreateKeyDownEvent(Key.Enter));
Assert.Equal(2, raised);
window.Content = null;
// To check if handler was raised on the button, when it's detached, we need to pass it as a source manually.
window.RaiseEvent(CreateKeyDownEvent(Key.Enter, target));
Assert.Equal(2, raised);
}
}
[Fact]
public void Button_IsCancel_Works()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var raised = 0;
var target = new Button();
var window = new Window { Content = target };
window.Show();
target.Click += (s, e) => ++raised;
target.IsCancel = false;
window.RaiseEvent(CreateKeyDownEvent(Key.Escape));
Assert.Equal(0, raised);
target.IsCancel = true;
window.RaiseEvent(CreateKeyDownEvent(Key.Escape));
Assert.Equal(1, raised);
target.IsCancel = false;
window.RaiseEvent(CreateKeyDownEvent(Key.Escape));
Assert.Equal(1, raised);
target.IsCancel = true;
window.RaiseEvent(CreateKeyDownEvent(Key.Escape));
Assert.Equal(2, raised);
window.Content = null;
window.RaiseEvent(CreateKeyDownEvent(Key.Escape, target));
Assert.Equal(2, raised);
}
}
private KeyEventArgs CreateKeyDownEvent(Key key, IInteractive source = null)
{
return new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = key, Source = source };
}
private class TestButton : Button, IRenderRoot
{

Loading…
Cancel
Save