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

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

@ -35,9 +35,9 @@ namespace Avalonia.Controls.Selection
{ {
return _owner.SelectedItem; 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 else
{ {

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

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq;
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Controls.Selection; using Avalonia.Controls.Selection;
using Avalonia.Controls.Utils; using Avalonia.Controls.Utils;
@ -1144,6 +1145,24 @@ namespace Avalonia.Controls.UnitTests.Selection
Assert.Equal(new[] { "foo" }, target.SelectedItems); Assert.Equal(new[] { "foo" }, target.SelectedItems);
Assert.Equal(0, target.AnchorIndex); 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 public class BatchUpdate

Loading…
Cancel
Save