Skip to content

Commit

Permalink
Merge branch 'master' into fix-win32-right-modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
MarchingCube authored Dec 9, 2019
2 parents c674a8b + 5b029f8 commit ff4e412
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 10 deletions.
18 changes: 15 additions & 3 deletions src/Avalonia.Input/FocusManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Avalonia.Interactivity;
using Avalonia.VisualTree;

Expand All @@ -17,8 +18,8 @@ public class FocusManager : IFocusManager
/// <summary>
/// The focus scopes in which the focus is currently defined.
/// </summary>
private readonly Dictionary<IFocusScope, IInputElement> _focusScopes =
new Dictionary<IFocusScope, IInputElement>();
private readonly ConditionalWeakTable<IFocusScope, IInputElement> _focusScopes =
new ConditionalWeakTable<IFocusScope, IInputElement>();

/// <summary>
/// Initializes a new instance of the <see cref="FocusManager"/> class.
Expand Down Expand Up @@ -110,7 +111,18 @@ public void SetFocusedElement(
{
Contract.Requires<ArgumentNullException>(scope != null);

_focusScopes[scope] = element;
if (_focusScopes.TryGetValue(scope, out IInputElement existingElement))
{
if (element != existingElement)
{
_focusScopes.Remove(scope);
_focusScopes.Add(scope, element);
}
}
else
{
_focusScopes.Add(scope, element);
}

if (Scope == scope)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public IXamlIlAstNode Transform(XamlIlAstTransformationContext context, IXamlIlA

if ((tt?.Values.FirstOrDefault() is XamlIlTypeExtensionNode tn))
{
targetType = tn.Type;
targetType = tn.Value;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github
23 changes: 18 additions & 5 deletions tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,23 @@ public void ControlTemplate_With_Nested_Child_Is_Operational()
Assert.Equal("child", child.Name);
}

[Fact]
public void ControlTemplate_With_TargetType_Is_Operational()
{
var xaml = @"
<ControlTemplate xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
TargetType='{x:Type ContentControl}'>
<ContentPresenter Content='{TemplateBinding Content}' />
</ControlTemplate>
";
var template = AvaloniaXamlLoader.Parse<ControlTemplate>(xaml);

Assert.Equal(typeof(ContentControl), template.TargetType);

Assert.IsType(typeof(ContentPresenter), template.Build(new ContentControl()).Control);
}

[Fact]
public void ControlTemplate_With_Panel_Children_Are_Added()
{
Expand Down Expand Up @@ -704,11 +721,7 @@ public void Named_Control_Is_Added_To_NameScope()
}
}


[Fact(Skip =
@"Doesn't work with Portable.xaml, it's working in different creation order -
Handled in test 'Control_Is_Added_To_Parent_Before_Final_EndInit'
do we need it?")]
[Fact]
public void Control_Is_Added_To_Parent_Before_Properties_Are_Set()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
Expand Down
52 changes: 52 additions & 0 deletions tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Controls;
using Avalonia.Markup.Data;
using Avalonia.Markup.Xaml.Styling;
using Avalonia.Markup.Xaml.Templates;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.UnitTests;
Expand Down Expand Up @@ -38,6 +39,57 @@ public void Color_Can_Be_Added_To_Style_Resources()
}
}

[Fact]
public void DataTemplate_Can_Be_Added_To_Style_Resources()
{
using (UnitTestApplication.Start(TestServices.MockPlatformWrapper))
{
var xaml = @"
<UserControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<UserControl.Styles>
<Style>
<Style.Resources>
<DataTemplate x:Key='dataTemplate'><TextBlock/></DataTemplate>
</Style.Resources>
</Style>
</UserControl.Styles>
</UserControl>";
var loader = new AvaloniaXamlLoader();
var userControl = (UserControl)loader.Load(xaml);
var dataTemplate = (DataTemplate)((Style)userControl.Styles[0]).Resources["dataTemplate"];

Assert.NotNull(dataTemplate);
}
}

[Fact]
public void ControlTemplate_Can_Be_Added_To_Style_Resources()
{
using (UnitTestApplication.Start(TestServices.MockPlatformWrapper))
{
var xaml = @"
<UserControl xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<UserControl.Styles>
<Style>
<Style.Resources>
<ControlTemplate x:Key='controlTemplate' TargetType='{x:Type Button}'>
<ContentPresenter Content='{TemplateBinding Content}'/>
</ControlTemplate>
</Style.Resources>
</Style>
</UserControl.Styles>
</UserControl>";
var loader = new AvaloniaXamlLoader();
var userControl = (UserControl)loader.Load(xaml);
var controlTemplate = (ControlTemplate)((Style)userControl.Styles[0]).Resources["controlTemplate"];

Assert.NotNull(controlTemplate);
Assert.Equal(typeof(Button), controlTemplate.TargetType);
}
}

[Fact]
public void SolidColorBrush_Can_Be_Added_To_Style_Resources()
{
Expand Down

0 comments on commit ff4e412

Please sign in to comment.