Explorar el Código

Merge branch 'master' into binding-to-classes

Jumar Macato hace 4 años
padre
commit
b04fd7438e

+ 11 - 6
nukebuild/Build.cs

@@ -301,14 +301,19 @@ partial class Build : NukeBuild
         .Executes(() =>
         {
             var data = Parameters;
+            var pathToProjectSource = RootDirectory / "samples" / "ControlCatalog.NetCore";
+            var pathToPublish = pathToProjectSource / "bin" / data.Configuration / "publish";
+
+            DotNetPublish(c => c
+                .SetProject(pathToProjectSource / "ControlCatalog.NetCore.csproj")
+                .EnableNoBuild()
+                .SetConfiguration(data.Configuration)
+                .AddProperty("PackageVersion", data.Version)
+                .AddProperty("PublishDir", pathToPublish));
+
             Zip(data.ZipCoreArtifacts, data.BinRoot);
             Zip(data.ZipNuGetArtifacts, data.NugetRoot);
-            Zip(data.ZipTargetControlCatalogDesktopDir,
-                GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.dll").Concat(
-                    GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.config")).Concat(
-                    GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.so")).Concat(
-                    GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.dylib")).Concat(
-                    GlobFiles(data.ZipSourceControlCatalogDesktopDir, "*.exe")));
+            Zip(data.ZipTargetControlCatalogNetCoreDir, pathToPublish);
         });
 
     Target CreateIntermediateNugetPackages => _ => _

+ 2 - 5
nukebuild/BuildParameters.cs

@@ -58,8 +58,7 @@ public partial class Build
         public string FileZipSuffix { get; }
         public AbsolutePath ZipCoreArtifacts { get; }
         public AbsolutePath ZipNuGetArtifacts { get; }
-        public AbsolutePath ZipSourceControlCatalogDesktopDir { get; }
-        public AbsolutePath ZipTargetControlCatalogDesktopDir { get; }
+        public AbsolutePath ZipTargetControlCatalogNetCoreDir { get; }
 
 
         public BuildParameters(Build b)
@@ -129,9 +128,7 @@ public partial class Build
             FileZipSuffix = Version + ".zip";
             ZipCoreArtifacts = ZipRoot / ("Avalonia-" + FileZipSuffix);
             ZipNuGetArtifacts = ZipRoot / ("Avalonia-NuGet-" + FileZipSuffix);
-            ZipSourceControlCatalogDesktopDir =
-                RootDirectory / ("samples/ControlCatalog.Desktop/bin/" + DirSuffix + "/net461");
-            ZipTargetControlCatalogDesktopDir = ZipRoot / ("ControlCatalog.Desktop-" + FileZipSuffix);
+            ZipTargetControlCatalogNetCoreDir = ZipRoot / ("ControlCatalog.NetCore-" + FileZipSuffix);
         }
 
         string GetVersion()

+ 5 - 1
samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <OutputType>Exe</OutputType>
+    <OutputType>WinExe</OutputType>
     <TargetFramework>netcoreapp3.1</TargetFramework>
     <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
   </PropertyGroup>
@@ -15,6 +15,10 @@
     <PackageReference Include="Avalonia.Angle.Windows.Natives" Version="2.1.0.2020091801" />
   </ItemGroup>
 
+  <PropertyGroup>
+    <!-- For Microsoft.CodeAnalysis -->
+    <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
+  </PropertyGroup>
 
   <Import Project="..\..\build\SampleApp.props" />
   <Import Project="..\..\build\ReferenceCoreLibraries.props" />

+ 1 - 1
samples/ControlCatalog/ControlCatalog.csproj

@@ -27,6 +27,6 @@
     <ProjectReference Include="..\..\src\Avalonia.Controls.DataGrid\Avalonia.Controls.DataGrid.csproj" />
     <ProjectReference Include="..\MiniMvvm\MiniMvvm.csproj" />
   </ItemGroup>
-  
+
   <Import Project="..\..\build\BuildTargets.targets" />
 </Project>

+ 12 - 0
src/Avalonia.Build.Tasks/DeterministicIdGenerator.cs

@@ -0,0 +1,12 @@
+using System;
+using XamlX.Transform;
+
+namespace Avalonia.Build.Tasks
+{
+    public class DeterministicIdGenerator : IXamlIdentifierGenerator
+    {
+        private int _nextId = 1;
+        
+        public string GenerateIdentifierPart() => (_nextId++).ToString();
+    }
+}

+ 2 - 2
src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs

@@ -22,7 +22,6 @@ using XamlX.IL;
 
 namespace Avalonia.Build.Tasks
 {
-    
     public static partial class XamlCompilerTaskExecutor
     {
         static bool CheckXamlName(IResource r) => r.Name.ToLowerInvariant().EndsWith(".xaml")
@@ -99,7 +98,8 @@ namespace Avalonia.Build.Tasks
                 XamlXmlnsMappings.Resolve(typeSystem, xamlLanguage),
                 AvaloniaXamlIlLanguage.CustomValueConverter,
                 new XamlIlClrPropertyInfoEmitter(typeSystem.CreateTypeBuilder(clrPropertiesDef)),
-                new XamlIlPropertyInfoAccessorFactoryEmitter(typeSystem.CreateTypeBuilder(indexerAccessorClosure)));
+                new XamlIlPropertyInfoAccessorFactoryEmitter(typeSystem.CreateTypeBuilder(indexerAccessorClosure)),
+                new DeterministicIdGenerator());
 
 
             var contextDef = new TypeDefinition("CompiledAvaloniaXaml", "XamlIlContext", 

+ 1 - 0
src/Avalonia.Controls/ApiCompatBaseline.txt

@@ -3,6 +3,7 @@ InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Control
 InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.INativeMenuExporterEventsImplBridge.RaiseOpening()' is present in the implementation but not in the contract.
 MembersMustExist : Member 'public void Avalonia.Controls.Embedding.Offscreen.OffscreenTopLevelImplBase.SetCursor(Avalonia.Platform.IPlatformHandle)' does not exist in the implementation but it does exist in the contract.
 MembersMustExist : Member 'public Avalonia.AvaloniaProperty Avalonia.AvaloniaProperty Avalonia.Controls.Notifications.NotificationCard.CloseOnClickProperty' does not exist in the implementation but it does exist in the contract.
+EnumValuesMustMatch : Enum value 'Avalonia.Platform.ExtendClientAreaChromeHints Avalonia.Platform.ExtendClientAreaChromeHints.Default' is (System.Int32)2 in the implementation but (System.Int32)1 in the contract.
 InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.ICursorImpl)' is present in the implementation but not in the contract.
 InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.IPlatformHandle)' is present in the contract but not in the implementation.
 MembersMustExist : Member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.IPlatformHandle)' does not exist in the implementation but it does exist in the contract.

+ 45 - 28
src/Avalonia.Controls/Chrome/CaptionButtons.cs

@@ -14,17 +14,21 @@ namespace Avalonia.Controls.Chrome
     public class CaptionButtons : TemplatedControl
     {
         private CompositeDisposable? _disposables;
-        private Window? _hostWindow;
 
-        public void Attach(Window hostWindow)
+        /// <summary>
+        /// Currently attached window.
+        /// </summary>
+        protected Window? HostWindow { get; private set; }
+
+        public virtual void Attach(Window hostWindow)
         {
             if (_disposables == null)
             {
-                _hostWindow = hostWindow;
+                HostWindow = hostWindow;
 
                 _disposables = new CompositeDisposable
                 {
-                    _hostWindow.GetObservable(Window.WindowStateProperty)
+                    HostWindow.GetObservable(Window.WindowStateProperty)
                     .Subscribe(x =>
                     {
                         PseudoClasses.Set(":minimized", x == WindowState.Minimized);
@@ -36,14 +40,45 @@ namespace Avalonia.Controls.Chrome
             }
         }
 
-        public void Detach()
+        public virtual void Detach()
         {
             if (_disposables != null)
             {
                 _disposables.Dispose();
                 _disposables = null;
 
-                _hostWindow = null;
+                HostWindow = null;
+            }
+        }
+
+        protected virtual void OnClose()
+        {
+            HostWindow?.Close();
+        }
+
+        protected virtual void OnRestore()
+        {
+            if (HostWindow != null)
+            {
+                HostWindow.WindowState = HostWindow.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
+            }
+        }
+
+        protected virtual void OnMinimize()
+        {
+            if (HostWindow != null)
+            {
+                HostWindow.WindowState = WindowState.Minimized;
+            }
+        }
+
+        protected virtual void OnToggleFullScreen()
+        {
+            if (HostWindow != null)
+            {
+                HostWindow.WindowState = HostWindow.WindowState == WindowState.FullScreen
+                    ? WindowState.Normal
+                    : WindowState.FullScreen;
             }
         }
 
@@ -56,31 +91,13 @@ namespace Avalonia.Controls.Chrome
             var minimiseButton = e.NameScope.Get<Panel>("PART_MinimiseButton");
             var fullScreenButton = e.NameScope.Get<Panel>("PART_FullScreenButton");
 
-            closeButton.PointerReleased += (sender, e) => _hostWindow?.Close();
+            closeButton.PointerReleased += (sender, e) => OnClose();
 
-            restoreButton.PointerReleased += (sender, e) =>
-            {
-                if (_hostWindow != null)
-                {
-                    _hostWindow.WindowState = _hostWindow.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
-                }
-            };
+            restoreButton.PointerReleased += (sender, e) => OnRestore();
 
-            minimiseButton.PointerReleased += (sender, e) =>
-            {
-                if (_hostWindow != null)
-                {
-                    _hostWindow.WindowState = WindowState.Minimized;
-                }
-            };
+            minimiseButton.PointerReleased += (sender, e) => OnMinimize();
 
-            fullScreenButton.PointerReleased += (sender, e) =>
-            {
-                if (_hostWindow != null)
-                {
-                    _hostWindow.WindowState = _hostWindow.WindowState == WindowState.FullScreen ? WindowState.Normal : WindowState.FullScreen;
-                }
-            };
+            fullScreenButton.PointerReleased += (sender, e) => OnToggleFullScreen();
         }
     }
 }

+ 4 - 18
src/Avalonia.Controls/NativeControlHost.cs

@@ -16,30 +16,16 @@ namespace Avalonia.Controls
         private bool _queuedForDestruction;
         private bool _queuedForMoveResize;
         private readonly List<Visual> _propertyChangedSubscriptions = new List<Visual>();
-        private readonly EventHandler<AvaloniaPropertyChangedEventArgs> _propertyChangedHandler;
-        static NativeControlHost()
-        {
-            IsVisibleProperty.Changed.AddClassHandler<NativeControlHost>(OnVisibleChanged);
-        }
-
-        public NativeControlHost()
-        {
-            _propertyChangedHandler = PropertyChangedHandler;
-        }
-
-        private static void OnVisibleChanged(NativeControlHost host, AvaloniaPropertyChangedEventArgs arg2)
-            => host.UpdateHost();
 
         protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
         {
             _currentRoot = e.Root as TopLevel;
             var visual = (IVisual)this;
-            while (visual != _currentRoot)
+            while (visual != null)
             {
-
                 if (visual is Visual v)
                 {
-                    v.PropertyChanged += _propertyChangedHandler;
+                    v.PropertyChanged += PropertyChangedHandler;
                     _propertyChangedSubscriptions.Add(v);
                 }
 
@@ -51,7 +37,7 @@ namespace Avalonia.Controls
 
         private void PropertyChangedHandler(object sender, AvaloniaPropertyChangedEventArgs e)
         {
-            if (e.IsEffectiveValueChange && e.Property == BoundsProperty)
+            if (e.IsEffectiveValueChange && (e.Property == BoundsProperty || e.Property == IsVisibleProperty))
                 EnqueueForMoveResize();
         }
 
@@ -61,7 +47,7 @@ namespace Avalonia.Controls
             if (_propertyChangedSubscriptions != null)
             {
                 foreach (var v in _propertyChangedSubscriptions)
-                    v.PropertyChanged -= _propertyChangedHandler;
+                    v.PropertyChanged -= PropertyChangedHandler;
                 _propertyChangedSubscriptions.Clear();
             }
             UpdateHost();

+ 1 - 1
src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs

@@ -16,7 +16,7 @@ namespace Avalonia.Platform
         /// <summary>
         /// The default for the platform.
         /// </summary>
-        Default = SystemChrome,
+        Default = PreferSystemChrome,
 
         /// <summary>
         /// Use SystemChrome

+ 3 - 1
src/Avalonia.Controls/Slider.cs

@@ -341,7 +341,9 @@ namespace Avalonia.Controls
 
             var pointNum = orient ? x.Position.X : x.Position.Y;
             var logicalPos = MathUtilities.Clamp(pointNum / pointDen, 0.0d, 1.0d);
-            var invert = orient ? 0 : 1;
+            var invert = orient ? 
+                IsDirectionReversed ? 1 : 0 :
+                IsDirectionReversed ? 0 : 1;
             var calcVal = Math.Abs(invert - logicalPos);
             var range = Maximum - Minimum;
             var finalValue = calcVal * range + Minimum;

+ 11 - 1
src/Avalonia.Diagnostics/DevToolsExtensions.cs

@@ -15,7 +15,7 @@ namespace Avalonia
         /// <param name="root">The window to attach DevTools to.</param>
         public static void AttachDevTools(this TopLevel root)
         {
-            DevTools.Attach(root, new KeyGesture(Key.F12));
+            DevTools.Attach(root, new DevToolsOptions());
         }
 
         /// <summary>
@@ -27,5 +27,15 @@ namespace Avalonia
         {
             DevTools.Attach(root, gesture);
         }
+
+        /// <summary>
+        /// Attaches DevTools to a window, to be opened with the specified options.
+        /// </summary>
+        /// <param name="root">The window to attach DevTools to.</param>
+        /// <param name="options">Additional settings of DevTools.</param>
+        public static void AttachDevTools(this TopLevel root, DevToolsOptions options)
+        {
+            DevTools.Attach(root, options);
+        }
     }
 }

+ 18 - 6
src/Avalonia.Diagnostics/Diagnostics/DevTools.cs

@@ -6,6 +6,8 @@ using Avalonia.Diagnostics.Views;
 using Avalonia.Input;
 using Avalonia.Interactivity;
 
+#nullable enable 
+
 namespace Avalonia.Diagnostics
 {
     public static class DevTools
@@ -13,12 +15,20 @@ namespace Avalonia.Diagnostics
         private static readonly Dictionary<TopLevel, Window> s_open = new Dictionary<TopLevel, Window>();
 
         public static IDisposable Attach(TopLevel root, KeyGesture gesture)
+        {
+            return Attach(root, new DevToolsOptions()
+            {
+                Gesture = gesture,
+            });
+        }
+
+        public static IDisposable Attach(TopLevel root, DevToolsOptions options)
         {
             void PreviewKeyDown(object sender, KeyEventArgs e)
             {
-                if (gesture.Matches(e))
+                if (options.Gesture.Matches(e))
                 {
-                    Open(root);
+                    Open(root, options);
                 }
             }
 
@@ -28,7 +38,9 @@ namespace Avalonia.Diagnostics
                 RoutingStrategies.Tunnel);
         }
 
-        public static IDisposable Open(TopLevel root)
+        public static IDisposable Open(TopLevel root) => Open(root, new DevToolsOptions());
+
+        public static IDisposable Open(TopLevel root, DevToolsOptions options)
         {
             if (s_open.TryGetValue(root, out var window))
             {
@@ -38,15 +50,15 @@ namespace Avalonia.Diagnostics
             {
                 window = new MainWindow
                 {
-                    Width = 1024,
-                    Height = 512,
                     Root = root,
+                    Width = options.Size.Width,
+                    Height = options.Size.Height,
                 };
 
                 window.Closed += DevToolsClosed;
                 s_open.Add(root, window);
 
-                if (root is Window inspectedWindow)
+                if (options.ShowAsChildWindow && root is Window inspectedWindow)
                 {
                     window.Show(inspectedWindow);
                 }

+ 26 - 0
src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs

@@ -0,0 +1,26 @@
+using Avalonia.Input;
+
+namespace Avalonia.Diagnostics
+{
+    /// <summary>
+    /// Describes options used to customize DevTools.
+    /// </summary>
+    public class DevToolsOptions
+    {
+        /// <summary>
+        /// Gets or sets the key gesture used to open DevTools.
+        /// </summary>
+        public KeyGesture Gesture { get; set; } = new KeyGesture(Key.F12);
+
+        /// <summary>
+        /// Gets or sets a value indicating whether DevTools should be displayed as a child window
+        /// of the window being inspected. The default value is true.
+        /// </summary>
+        public bool ShowAsChildWindow { get; set; } = true;
+
+        /// <summary>
+        /// Gets or sets the initial size of the DevTools window. The default value is 1024x512.
+        /// </summary>
+        public Size Size { get; set; } = new Size(1024, 512);
+    }
+}

+ 1 - 1
src/Avalonia.Native/avn.idl

@@ -397,7 +397,7 @@ enum AvnExtendClientAreaChromeHints
     AvnSystemChrome = 0x01,
     AvnPreferSystemChrome = 0x02,
     AvnOSXThickTitleBar = 0x08,
-    AvnDefaultChrome = AvnSystemChrome,
+    AvnDefaultChrome = AvnPreferSystemChrome,
 }
 
 [uuid(809c652e-7396-11d2-9771-00a0c9b4d50c)]

+ 3 - 2
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs

@@ -14,8 +14,9 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions
             XamlXmlnsMappings xmlnsMappings,
             XamlValueConverter customValueConverter,
             XamlIlClrPropertyInfoEmitter clrPropertyEmitter,
-            XamlIlPropertyInfoAccessorFactoryEmitter accessorFactoryEmitter)
-            : base(typeSystem, defaultAssembly, typeMappings, xmlnsMappings, customValueConverter)
+            XamlIlPropertyInfoAccessorFactoryEmitter accessorFactoryEmitter,
+            IXamlIdentifierGenerator identifierGenerator = null)
+            : base(typeSystem, defaultAssembly, typeMappings, xmlnsMappings, customValueConverter, identifierGenerator)
         {
             ClrPropertyEmitter = clrPropertyEmitter;
             AccessorFactoryEmitter = accessorFactoryEmitter;