Browse Source

Merge branch 'Dashes' of https://github.com/MaoqingWang/Avalonia into Dashes

pull/9710/head
wangmaotsing 4 years ago
parent
commit
eaa15d6cc3
  1. 24
      src/Avalonia.Build.Tasks/GenerateAvaloniaResourcesTask.cs
  2. 4
      src/Avalonia.Controls/Selection/SelectedItems.cs
  3. 19
      tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs

24
src/Avalonia.Build.Tasks/GenerateAvaloniaResourcesTask.cs

@ -7,7 +7,7 @@ using System.Text;
using Avalonia.Markup.Xaml.PortableXaml;
using Avalonia.Utilities;
using Microsoft.Build.Framework;
using SPath=System.IO.Path;
using SPath = System.IO.Path;
namespace Avalonia.Build.Tasks
{
public class GenerateAvaloniaResourcesTask : ITask
@ -30,12 +30,17 @@ namespace Avalonia.Build.Tasks
private byte[] _data;
private string _sourcePath;
public Source(string relativePath, string root)
public Source(ITaskItem avaloniaResourceItem, string root)
{
root = SPath.GetFullPath(root);
Path = "/" + relativePath.Replace('\\', '/');
var relativePath = avaloniaResourceItem.ItemSpec;
_sourcePath = SPath.Combine(root, relativePath);
Size = (int)new FileInfo(_sourcePath).Length;
var link = avaloniaResourceItem.GetMetadata("Link");
var path = !string.IsNullOrEmpty(link)
? link
: relativePath;
Path = "/" + path.Replace('\\', '/');
}
public string SystemPath => _sourcePath ?? Path;
@ -65,8 +70,7 @@ namespace Avalonia.Build.Tasks
List<Source> BuildResourceSources()
=> Resources.Select(r =>
{
var src = new Source(r.ItemSpec, Root);
var src = new Source(r, Root);
BuildEngine.LogMessage(FormattableString.Invariant($"avares -> name:{src.Path}, path: {src.SystemPath}, size:{src.Size}, ItemSpec:{r.ItemSpec}"), _reportImportance);
return src;
}).ToList();
@ -93,15 +97,15 @@ namespace Avalonia.Build.Tasks
ms.CopyTo(output);
foreach (var s in sources)
{
using(var input = s.Open())
using (var input = s.Open())
input.CopyTo(output);
}
}
private bool PreProcessXamlFiles(List<Source> sources)
{
var typeToXamlIndex = new Dictionary<string, string>();
var typeToXamlIndex = new Dictionary<string, string>();
foreach (var s in sources.ToArray())
{
if (s.Path.ToLowerInvariant().EndsWith(".xaml") || s.Path.ToLowerInvariant().EndsWith(".paml") || s.Path.ToLowerInvariant().EndsWith(".axaml"))
@ -111,7 +115,7 @@ namespace Avalonia.Build.Tasks
{
info = XamlFileInfo.Parse(s.ReadAsString());
}
catch(Exception e)
catch (Exception e)
{
BuildEngine.LogError(BuildEngineErrorCode.InvalidXAML, s.SystemPath, "File doesn't contain valid XAML: " + e);
return false;
@ -121,7 +125,7 @@ namespace Avalonia.Build.Tasks
{
if (typeToXamlIndex.ContainsKey(info.XClass))
{
BuildEngine.LogError(BuildEngineErrorCode.DuplicateXClass, s.SystemPath,
$"Duplicate x:Class directive, {info.XClass} is already used in {typeToXamlIndex[info.XClass]}");
return false;

4
src/Avalonia.Controls/Selection/SelectedItems.cs

@ -35,9 +35,9 @@ namespace Avalonia.Controls.Selection
{
return _owner.SelectedItem;
}
else if (Items is object)
else if (Items is not null && Ranges is not null)
{
return Items[index];
return Items[IndexRange.GetAt(Ranges, index)];
}
else
{

19
tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Selection;
using Avalonia.Controls.Utils;
@ -1144,6 +1145,24 @@ namespace Avalonia.Controls.UnitTests.Selection
Assert.Equal(new[] { "foo" }, target.SelectedItems);
Assert.Equal(0, target.AnchorIndex);
}
[Fact]
public void SelectedItems_Indexer_Is_Correct()
{
// Issue #7974
var target = CreateTarget();
var raised = 0;
target.SelectionChanged += (s, e) =>
{
Assert.Equal("bar", e.SelectedItems.First());
Assert.Equal("bar", e.SelectedItems[0]);
++raised;
};
target.Select(1);
Assert.Equal(1, raised);
}
}
public class BatchUpdate

Loading…
Cancel
Save