Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 11.0.0-rc1.1 #183

Merged
merged 15 commits into from
Jun 2, 2023
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<MSBuildEnableWorkloadResolver>false</MSBuildEnableWorkloadResolver>
</PropertyGroup>
<PropertyGroup>
<AvaloniaVersion>11.0.0-preview8</AvaloniaVersion>
<AvaloniaVersion>11.0.0-rc1.1</AvaloniaVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion build/SharedVersion.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Product>Avalonia.Controls.TreeDataGrid</Product>
<Version>11.0.0-preview8</Version>
<Version>11.0.0-rc1.1</Version>
<Copyright>Copyright © AvaloniaUI 2022</Copyright>
<Authors>Steven Kirk</Authors>
<Company>AvaloniaUI</Company>
Expand Down
11 changes: 11 additions & 0 deletions samples/TreeDataGridDemo/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@
<FluentTheme/>
<StyleInclude Source="avares://Avalonia.Controls.TreeDataGrid/Themes/Fluent.axaml"/>
</Application.Styles>
<!-- Uncomment to override resources -->
<!-- <Application.Resources> -->
<!-- <SolidColorBrush x:Key="TreeDataGridGridLinesBrush" Color="Yellow" /> -->
<!-- <SolidColorBrush x:Key="TreeDataGridSelectedCellBackgroundBrush" Color="Green" Opacity="0.4" /> -->
<!-- <SolidColorBrush x:Key="TreeDataGridHeaderBackgroundPointerOverBrush" Color="Yellow" /> -->
<!-- <SolidColorBrush x:Key="TreeDataGridHeaderBackgroundPressedBrush" Color="Red" /> -->
<!-- <SolidColorBrush x:Key="TreeDataGridHeaderBorderBrushPointerOverBrush" Color="DarkGreen" /> -->
<!-- <SolidColorBrush x:Key="TreeDataGridHeaderBorderBrushPressedBrush" Color="DarkRed" /> -->
<!-- <SolidColorBrush x:Key="TreeDataGridHeaderForegroundPointerOverBrush" Color="Black" /> -->
<!-- <SolidColorBrush x:Key="TreeDataGridHeaderForegroundPressedBrush" Color="Black" /> -->
<!-- </Application.Resources> -->
</Application>
6 changes: 3 additions & 3 deletions samples/TreeDataGridDemo/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window xmlns="https://github.com/avaloniaui"
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down Expand Up @@ -31,7 +31,7 @@
AutoDragDropRows="True">
<TreeDataGrid.Styles>
<Style Selector="TreeDataGrid TreeDataGridRow:nth-last-child(2n)">
<Setter Property="Background" Value="#fff8f8f8"/>
<Setter Property="Background" Value="#20808080"/>
</Style>
<Style Selector="TreeDataGrid :is(TreeDataGridCell):nth-last-child(1)">
<Setter Property="TextBlock.FontWeight" Value="Bold"/>
Expand Down Expand Up @@ -82,7 +82,7 @@
</TreeDataGrid.Resources>
<TreeDataGrid.Styles>
<Style Selector="TreeDataGrid TreeDataGridRow:nth-child(2n)">
<Setter Property="Background" Value="#fff8f8f8"/>
<Setter Property="Background" Value="#20808080"/>
</Style>
</TreeDataGrid.Styles>
</TreeDataGrid>
Expand Down
4 changes: 2 additions & 2 deletions samples/TreeDataGridDemo/Models/OnThisDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ internal class OnThisDayArticle : NotifyingBase
{
private const string UserAgent = @"AvaloniaTreeDataGridSample/1.0 (https://avaloniaui.net; team@avaloniaui.net)";
private bool _loadedImage;
private IBitmap? _image;
private Bitmap? _image;

public string? Type { get; set; }
public OnThisDayTitles? Titles { get; set; }
public OnThisDayImage? Thumbnail { get; set; }
public string? Description { get; set; }
public string? Extract { get; set; }

public IBitmap? Image
public Bitmap? Image
{
get
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using Avalonia.Threading;

namespace Avalonia.Controls.Experimental.Data.Core;

internal abstract class SingleSubscriberObservableBase<T> : IObservable<T>, IDisposable
{
private Exception? _error;
private IObserver<T>? _observer;
private bool _completed;

public IDisposable Subscribe(IObserver<T> observer)
{
_ = observer ?? throw new ArgumentNullException(nameof(observer));
Dispatcher.UIThread.VerifyAccess();

if (_observer != null)
{
throw new InvalidOperationException("The observable can only be subscribed once.");
}

if (_error != null)
{
observer.OnError(_error);
}
else if (_completed)
{
observer.OnCompleted();
}
else
{
_observer = observer;
Subscribed();
}

return this;
}

public virtual void Dispose()
{
Unsubscribed();
_observer = null;
}

protected abstract void Unsubscribed();

protected void PublishNext(T value)
{
_observer?.OnNext(value);
}

protected void PublishCompleted()
{
_completed = true;

if (_observer != null)
{
_observer.OnCompleted();
Unsubscribed();
_observer = null;
}
}

protected void PublishError(Exception error)
{
_error = error;

if (_observer != null)
{
_observer.OnError(error);
Unsubscribed();
_observer = null;
}
}

protected abstract void Subscribed();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Reactive;
using Avalonia.Controls.Experimental.Data.Core;
using Avalonia.Experimental.Data.Core;

#nullable enable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Avalonia.Reactive;
using Avalonia.Controls.Experimental.Data.Core;
using Avalonia.Experimental.Data.Core;
using Avalonia.VisualTree;

#nullable enable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void ITreeDataGridSource.DragDropRows(
TreeDataGridRowDropPosition position,
DragDropEffects effects)
{
if (!effects.HasAnyFlag(DragDropEffects.Move))
if (effects != DragDropEffects.Move)
throw new NotSupportedException("Only move is currently supported for drag/drop.");
if (IsSorted)
throw new NotSupportedException("Drag/drop is not supported on sorted data.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ IList<TModel> GetItems(IndexPath path)
throw new InvalidOperationException("Items does not implement IList<T>.");
}

if (!effects.HasAnyFlag(DragDropEffects.Move))
if (effects != DragDropEffects.Move)
throw new NotSupportedException("Only move is currently supported for drag/drop.");
if (IsSorted)
throw new NotSupportedException("Drag/drop is not supported on sorted data.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Controls.Experimental.Data.Core;
using Avalonia.Data;
using Avalonia.Experimental.Data;
using Avalonia.Reactive;
using Avalonia.Experimental.Data.Core;

namespace Avalonia.Controls.Models.TreeDataGrid
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Avalonia.Controls.Primitives
{
public abstract class TreeDataGridPresenterBase<TItem> : Border, IPresenter
public abstract class TreeDataGridPresenterBase<TItem> : Border
{
#pragma warning disable AVP1002
public static readonly DirectProperty<TreeDataGridPresenterBase<TItem>, TreeDataGridElementFactory?>
Expand Down Expand Up @@ -107,7 +107,7 @@ public IReadOnlyList<TItem>? Items
element.BringIntoView();
return element;
}
else if (this.GetVisualRoot() is ILayoutRoot root)
else if (this.IsAttachedToVisualTree())
{
// Create and measure the element to be brought into view. Store it in a field so that
// it can be re-used in the layout pass.
Expand All @@ -129,7 +129,7 @@ public IReadOnlyList<TItem>? Items
if (!Bounds.Contains(elementRect) && !Viewport.Contains(elementRect))
{
_isWaitingForViewportUpdate = true;
root.LayoutManager.ExecuteLayoutPass();
UpdateLayout();
_isWaitingForViewportUpdate = false;
}

Expand All @@ -145,15 +145,15 @@ public IReadOnlyList<TItem>? Items
// - The viewport is then updated by the layout system which invalidates our measure
// - Measure is then done with the new viewport.
_isWaitingForViewportUpdate = !Viewport.Contains(elementRect);
root.LayoutManager.ExecuteLayoutPass();
UpdateLayout();

// If for some reason the layout system didn't give us a new viewport during the layout, we
// need to do another layout pass as the one that took place was a no-op.
if (_isWaitingForViewportUpdate)
{
_isWaitingForViewportUpdate = false;
InvalidateMeasure();
root.LayoutManager.ExecuteLayoutPass();
UpdateLayout();
}

var result = _scrollToElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void ITreeDataGridSelectionInteraction.OnKeyDown(TreeDataGrid sender, KeyEventAr
var newIndex = hierarchicalRows.GetParentRowIndex(AnchorIndex);
UpdateSelection(sender, newIndex, true);
sender.RowsPresenter.BringIntoView(newIndex);
FocusManager.Instance?.Focus(sender);
sender.Focus();
}

if (!e.Handled && direction == NavigationDirection.Right
Expand Down Expand Up @@ -381,8 +381,8 @@ private void PointerSelect(TreeDataGrid sender, TreeDataGridRow row, PointerEven
{
var point = e.GetCurrentPoint(sender);

var commandModifiers = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>()?.CommandModifiers;
var toggleModifier = commandModifiers is not null ? e.KeyModifiers.HasFlag(commandModifiers) : false;
var commandModifiers = TopLevel.GetTopLevel(sender)?.PlatformSettings?.HotkeyConfiguration.CommandModifiers;
var toggleModifier = commandModifiers is not null && e.KeyModifiers.HasFlag(commandModifiers);
var isRightButton = point.Properties.PointerUpdateKind is PointerUpdateKind.RightButtonPressed or
PointerUpdateKind.RightButtonReleased;

Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls.TreeDataGrid/Themes/Fluent.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</Style>

<Style Selector=":is(TreeDataGridCell):selected">
<Setter Property="Background" Value="{DynamicResource SystemControlHighlightListAccentLowBrush}"/>
<Setter Property="Background" Value="{DynamicResource TreeDataGridSelectedCellBackgroundBrush}"/>
</Style>

</Styles>
80 changes: 64 additions & 16 deletions src/Avalonia.Controls.TreeDataGrid/Themes/FluentControls.axaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:Avalonia.Controls.Converters">
xmlns:conv="using:Avalonia.Controls.Converters"
x:ClassModifier="internal">

<SolidColorBrush x:Key="TreeDataGridGridLinesBrush"
Color="{StaticResource SystemBaseMediumLowColor}"
Opacity="0.4" />
<StreamGeometry x:Key="TreeDataGridGridSortIconDescendingPath">M1875 1011l-787 787v-1798h-128v1798l-787 -787l-90 90l941 941l941 -941z</StreamGeometry>
<StreamGeometry x:Key="TreeDataGridGridSortIconAscendingPath">M1965 947l-941 -941l-941 941l90 90l787 -787v1798h128v-1798l787 787z</StreamGeometry>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="TreeDataGridGridLinesBrush" Color="{StaticResource SystemListLowColor}" />
<SolidColorBrush x:Key="TreeDataGridHeaderBackgroundPointerOverBrush" Color="{StaticResource SystemBaseHighColor}" Opacity="0.1" />
<SolidColorBrush x:Key="TreeDataGridHeaderBackgroundPressedBrush" Color="{StaticResource SystemBaseMediumLowColor}" />
<SolidColorBrush x:Key="TreeDataGridHeaderBorderBrushPointerOverBrush" Color="Transparent" />
<SolidColorBrush x:Key="TreeDataGridHeaderBorderBrushPressedBrush" Color="Transparent" />
<SolidColorBrush x:Key="TreeDataGridHeaderForegroundPointerOverBrush" Color="{StaticResource SystemBaseHighColor}" />
<SolidColorBrush x:Key="TreeDataGridHeaderForegroundPressedBrush" Color="{StaticResource SystemBaseHighColor}" />
<SolidColorBrush x:Key="TreeDataGridSelectedCellBackgroundBrush" Color="{StaticResource SystemAccentColor}" Opacity="0.4" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="TreeDataGridGridLinesBrush" Color="{StaticResource SystemListLowColor}" />
<SolidColorBrush x:Key="TreeDataGridHeaderBackgroundPointerOverBrush" Color="{StaticResource SystemBaseHighColor}" Opacity="0.1" />
<SolidColorBrush x:Key="TreeDataGridHeaderBackgroundPressedBrush" Color="{StaticResource SystemBaseMediumLowColor}" />
<SolidColorBrush x:Key="TreeDataGridHeaderBorderBrushPointerOverBrush" Color="Transparent" />
<SolidColorBrush x:Key="TreeDataGridHeaderBorderBrushPressedBrush" Color="Transparent" />
<SolidColorBrush x:Key="TreeDataGridHeaderForegroundPointerOverBrush" Color="{StaticResource SystemBaseHighColor}" />
<SolidColorBrush x:Key="TreeDataGridHeaderForegroundPressedBrush" Color="{StaticResource SystemBaseHighColor}" />
<SolidColorBrush x:Key="TreeDataGridSelectedCellBackgroundBrush" Color="{StaticResource SystemAccentColor}" Opacity="0.4" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

<StreamGeometry x:Key="TreeDataGridSortIconDescendingPath">M1875 1011l-787 787v-1798h-128v1798l-787 -787l-90 90l941 941l941 -941z</StreamGeometry>
<StreamGeometry x:Key="TreeDataGridSortIconAscendingPath">M1965 947l-941 -941l-941 941l90 90l787 -787v1798h128v-1798l787 787z</StreamGeometry>
<StreamGeometry x:Key="TreeDataGridItemCollapsedChevronPathData">M 1,0 10,10 l -9,10 -1,-1 L 8,10 -0,1 Z</StreamGeometry>
<StreamGeometry x:Key="TreeDataGridItemExpandedChevronPathData">M0,1 L10,10 20,1 19,0 10,8 1,0 Z</StreamGeometry>

<ControlTheme x:Key="{x:Type TreeDataGrid}" TargetType="TreeDataGrid">
<Setter Property="Template">
Expand Down Expand Up @@ -106,25 +129,25 @@
</Setter>

<Style Selector="^:pointerover /template/ Border#DataGridBorder">
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundPointerOver}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderBrushPointerOver}" />
<Setter Property="TextBlock.Foreground" Value="{DynamicResource ButtonForegroundPointerOver}" />
<Setter Property="Background" Value="{DynamicResource TreeDataGridHeaderBackgroundPointerOverBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource TreeDataGridHeaderBorderBrushPointerOverBrush}" />
<Setter Property="TextBlock.Foreground" Value="{DynamicResource TreeDataGridHeaderForegroundPointerOverBrush}" />
</Style>

<Style Selector="^:pressed /template/ Border#DataGridBorder">
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundPressed}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderBrushPressed}" />
<Setter Property="TextBlock.Foreground" Value="{DynamicResource ButtonForegroundPressed}" />
<Setter Property="Background" Value="{DynamicResource TreeDataGridHeaderBackgroundPressedBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource TreeDataGridHeaderBorderBrushPressedBrush}" />
<Setter Property="TextBlock.Foreground" Value="{DynamicResource TreeDataGridHeaderForegroundPressedBrush}" />
</Style>

<Style Selector="^[SortDirection=Ascending] /template/ Path#SortIcon">
<Setter Property="IsVisible" Value="True" />
<Setter Property="Data" Value="{StaticResource TreeDataGridGridSortIconAscendingPath}" />
<Setter Property="Data" Value="{StaticResource TreeDataGridSortIconAscendingPath}" />
</Style>

<Style Selector="^[SortDirection=Descending] /template/ Path#SortIcon">
<Setter Property="IsVisible" Value="True" />
<Setter Property="Data" Value="{StaticResource TreeDataGridGridSortIconDescendingPath}" />
<Setter Property="Data" Value="{StaticResource TreeDataGridSortIconDescendingPath}" />
</Style>

</ControlTheme>
Expand All @@ -146,7 +169,7 @@
</Setter>

<Style Selector="^:selected /template/ TreeDataGridCellsPresenter#PART_CellsPresenter">
<Setter Property="Background" Value="{DynamicResource SystemControlHighlightListAccentLowBrush}"/>
<Setter Property="Background" Value="{DynamicResource TreeDataGridSelectedCellBackgroundBrush}"/>
</Style>

</ControlTheme>
Expand All @@ -169,6 +192,31 @@
</Setter>
</ControlTheme>

<ControlTheme x:Key="TreeDataGridExpandCollapseChevron" TargetType="ToggleButton">
<Setter Property="Margin" Value="0" />
<Setter Property="Width" Value="12" />
<Setter Property="Height" Value="12" />
<Setter Property="Template">
<ControlTemplate>
<Border Background="Transparent"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Path x:Name="ChevronPath"
Data="{StaticResource TreeDataGridItemCollapsedChevronPathData}"
Fill="{TemplateBinding Foreground}"
Stretch="Uniform"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:checked /template/ Path#ChevronPath">
<Setter Property="Data" Value="{StaticResource TreeDataGridItemExpandedChevronPathData}" />
</Style>
</ControlTheme>

<ControlTheme x:Key="{x:Type TreeDataGridExpanderCell}" TargetType="TreeDataGridExpanderCell">
<Setter Property="Template">
<ControlTemplate>
Expand All @@ -182,7 +230,7 @@
<Border DockPanel.Dock="Left"
Margin="4 0"
Width="12" Height="12">
<ToggleButton Theme="{StaticResource FluentTreeViewExpandCollapseChevron}"
<ToggleButton Theme="{StaticResource TreeDataGridExpandCollapseChevron}"
Focusable="False"
IsChecked="{TemplateBinding IsExpanded, Mode=TwoWay}"
IsVisible="{TemplateBinding ShowExpander}"/>
Expand Down
Loading