Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Avalonia.Automation.Peers;

namespace Avalonia.Controls.Automation.Peers;

public class TreeDataGridAutomationPeer : ControlAutomationPeer
{
public TreeDataGridAutomationPeer(TreeDataGrid owner)
: base(owner)
{
}

public new TreeDataGrid Owner => (TreeDataGrid)base.Owner;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.DataGrid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Avalonia.Automation.Peers;
using Avalonia.Controls.Primitives;

namespace Avalonia.Controls.Automation.Peers;

public class TreeDataGridCellAutomationPeer : ControlAutomationPeer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
public TreeDataGridCellAutomationPeer(TreeDataGridCell owner)
: base(owner)
{
}

public new TreeDataGridCell Owner => (TreeDataGridCell)base.Owner;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Custom;
}

protected override bool IsContentElementCore() => true;

protected override bool IsControlElementCore() => true;

protected override string? GetNameCore()
{
var name = base.GetNameCore();
if (!string.IsNullOrEmpty(name))
{
return name;
}

return Owner switch
{
TreeDataGridTextCell textCell => textCell.Value,
TreeDataGridTemplateCell templateCell => templateCell.Content?.ToString(),
_ => Owner.Model?.ToString()
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Avalonia.Automation.Peers;
using Avalonia.Controls.Primitives;

namespace Avalonia.Controls.Automation.Peers;

public class TreeDataGridColumnHeaderAutomationPeer : ContentControlAutomationPeer
{
public TreeDataGridColumnHeaderAutomationPeer(TreeDataGridColumnHeader owner)
: base(owner)
{
}

public new TreeDataGridColumnHeader Owner => (TreeDataGridColumnHeader)base.Owner;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.HeaderItem;
}

protected override bool IsContentElementCore() => false;

protected override bool IsControlElementCore() => true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Avalonia.Automation.Peers;
using Avalonia.Controls.Primitives;

namespace Avalonia.Controls.Automation.Peers;

public class TreeDataGridColumnHeadersPresenterAutomationPeer : ControlAutomationPeer
{
public TreeDataGridColumnHeadersPresenterAutomationPeer(TreeDataGridColumnHeadersPresenter owner)
: base(owner)
{
}

public new TreeDataGridColumnHeadersPresenter Owner => (TreeDataGridColumnHeadersPresenter)base.Owner;

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Header;
}

protected override bool IsContentElementCore() => false;

protected override bool IsControlElementCore() => true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Primitives;

namespace Avalonia.Controls.Automation.Peers;

public class TreeDataGridRowAutomationPeer : ControlAutomationPeer, IToggleProvider, IValueProvider
{
public TreeDataGridRowAutomationPeer(TreeDataGridRow owner)
: base(owner)
{
}

public new TreeDataGridRow Owner => (TreeDataGridRow)base.Owner;

public ToggleState ToggleState
{
get
{
if (Owner.DataContext is IExpander expander)
{
return expander.IsExpanded ? ToggleState.On : ToggleState.Off;
}
return ToggleState.Indeterminate;
}
}

public bool IsReadOnly => true;

public string? Value
{
get
{
return Owner.Model?.ToString();
}
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.TreeItem;
}

protected override bool IsContentElementCore() => true;

protected override bool IsControlElementCore() => true;

public void Toggle()
{
if (Owner.DataContext is IExpander expander)
{
expander.IsExpanded = !expander.IsExpanded;
}
}

public void SetValue(string? value)
{
throw new InvalidOperationException("TreeDataGrid rows are read-only.");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.ComponentModel;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Selection;
Expand Down Expand Up @@ -74,6 +76,11 @@ public virtual void Unrealize()
Model = null;
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new TreeDataGridCellAutomationPeer(this);
}

protected internal void BeginEdit()
{
if (!IsEditing)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.ComponentModel;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Input;
using Avalonia.Utilities;
Expand Down Expand Up @@ -81,6 +83,11 @@ public void Unrealize()
UpdatePropertiesFromModel();
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new TreeDataGridColumnHeaderAutomationPeer(this);
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Layout;
using Avalonia.LogicalTree;
Expand All @@ -12,6 +14,11 @@ public class TreeDataGridColumnHeadersPresenter : TreeDataGridColumnarPresenterB

protected override Orientation Orientation => Orientation.Horizontal;

protected override AutomationPeer OnCreateAutomationPeer()
{
return new TreeDataGridColumnHeadersPresenterAutomationPeer(this);
}

protected override Size ArrangeOverride(Size finalSize)
{
(Items as IColumns)?.CommitActualWidths();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Text;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Selection;
Expand Down Expand Up @@ -112,6 +114,11 @@ public void Unrealize()
CellsPresenter?.Unrealize();
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new TreeDataGridRowAutomationPeer(this);
}

protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
_treeDataGrid = this.FindLogicalAncestorOfType<TreeDataGrid>();
Expand Down
7 changes: 7 additions & 0 deletions src/Avalonia.Controls.TreeDataGrid/TreeDataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Automation.Peers;
using Avalonia.Controls.Documents;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Primitives;
Expand Down Expand Up @@ -310,6 +312,11 @@ public bool QueryCancelSelection()
return e.Cancel;
}

protected override AutomationPeer OnCreateAutomationPeer()
{
return new TreeDataGridAutomationPeer(this);
}

protected virtual TreeDataGridElementFactory CreateDefaultElementFactory() => new TreeDataGridElementFactory();

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Expand Down
Loading