Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 authored Jan 10, 2021
2 parents a05842a + b292daa commit 40a5f40
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
12 changes: 11 additions & 1 deletion native/Avalonia.Native/src/OSX/rendertarget.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ -(void) dealloc
if(_renderbuffer != 0)
glDeleteRenderbuffers(1, &_renderbuffer);
}
CFRelease(surface);

if(surface != nullptr)
{
CFRelease(surface);
}
}
@end

Expand Down Expand Up @@ -145,6 +149,12 @@ - (CALayer *)layer {
}

- (void)resize:(AvnPixelSize)size withScale: (float) scale{

if(size.Height <= 0)
size.Height = 1;
if(size.Width <= 0)
size.Width = 1;

@synchronized (lock) {
if(surface == nil
|| surface->size.Width != size.Width
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T>
/// <summary>
/// Opens the menu.
/// </summary>
public override void Open() => throw new NotSupportedException();
public override void Open() => Open(null);

/// <summary>
/// Opens a context menu on the specified control.
Expand Down
49 changes: 49 additions & 0 deletions tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,55 @@ public void Opening_Raises_Single_Opened_Event()
}
}

[Fact]
public void Open_Should_Use_Default_Control()
{
using (Application())
{
var sut = new ContextMenu();
var target = new Panel
{
ContextMenu = sut
};

var window = new Window { Content = target };
window.ApplyTemplate();
window.Presenter.ApplyTemplate();

bool opened = false;

sut.MenuOpened += (sender, args) =>
{
opened = true;
};

sut.Open();

Assert.True(opened);
}
}

[Fact]
public void Open_Should_Raise_Exception_If_AlreadyDetached()
{
using (Application())
{
var sut = new ContextMenu();
var target = new Panel
{
ContextMenu = sut
};

var window = new Window { Content = target };
window.ApplyTemplate();
window.Presenter.ApplyTemplate();

target.ContextMenu = null;

Assert.ThrowsAny<Exception>(()=> sut.Open());
}
}

[Fact]
public void Closing_Raises_Single_Closed_Event()
{
Expand Down

0 comments on commit 40a5f40

Please sign in to comment.