Browse Source

Merge branch 'feature/selectionmodel' into feature/selectionmodel-changed-notifications

pull/3470/head
Steven Kirk 6 years ago
parent
commit
7829e0cdab
  1. 47
      src/Avalonia.Controls/ISelectionModel.cs
  2. 17
      src/Avalonia.Controls/SelectionModel.cs

47
src/Avalonia.Controls/ISelectionModel.cs

@ -0,0 +1,47 @@
// This source file is adapted from the WinUI project.
// (https://github.com/microsoft/microsoft-ui-xaml)
//
// Licensed to The Avalonia Project under MIT License, courtesy of The .NET Foundation.
using System;
using System.Collections.Generic;
namespace Avalonia.Controls
{
public interface ISelectionModel
{
IndexPath AnchorIndex { get; set; }
IndexPath SelectedIndex { get; set; }
IReadOnlyList<IndexPath> SelectedIndices { get; }
object SelectedItem { get; }
IReadOnlyList<object> SelectedItems { get; }
bool SingleSelect { get; set; }
object Source { get; set; }
event EventHandler<SelectionModelChildrenRequestedEventArgs> ChildrenRequested;
event EventHandler<SelectionModelSelectionChangedEventArgs> SelectionChanged;
void ClearSelection();
void Deselect(int index);
void Deselect(int groupIndex, int itemIndex);
void DeselectAt(IndexPath index);
void DeselectRange(IndexPath start, IndexPath end);
void DeselectRangeFromAnchor(int index);
void DeselectRangeFromAnchor(int endGroupIndex, int endItemIndex);
void DeselectRangeFromAnchorTo(IndexPath index);
void Dispose();
bool? IsSelected(int index);
bool? IsSelected(int groupIndex, int itemIndex);
bool? IsSelectedAt(IndexPath index);
void Select(int index);
void Select(int groupIndex, int itemIndex);
void SelectAll();
void SelectAt(IndexPath index);
void SelectRange(IndexPath start, IndexPath end);
void SelectRangeFromAnchor(int index);
void SelectRangeFromAnchor(int endGroupIndex, int endItemIndex);
void SelectRangeFromAnchorTo(IndexPath index);
void SetAnchorIndex(int index);
void SetAnchorIndex(int groupIndex, int index);
}
}

17
src/Avalonia.Controls/SelectionModel.cs

@ -13,7 +13,7 @@ using Avalonia.Controls.Utils;
namespace Avalonia.Controls
{
public class SelectionModel : INotifyPropertyChanged, IDisposable
public class SelectionModel : ISelectionModel, INotifyPropertyChanged, IDisposable
{
private readonly SelectionNode _rootNode;
private bool _singleSelect;
@ -97,7 +97,6 @@ namespace Avalonia.Controls
}
}
public IndexPath AnchorIndex
{
get
@ -316,7 +315,7 @@ namespace Avalonia.Controls
_selectedIndicesCached = indices;
}
return _selectedIndicesCached;
return _selectedIndicesCached;
}
}
@ -594,7 +593,7 @@ namespace Avalonia.Controls
RaisePropertyChanged(nameof(SelectedIndex));
RaisePropertyChanged(nameof(SelectedIndices));
if (_rootNode.Source != null)
{
RaisePropertyChanged(nameof(SelectedItem));
@ -610,7 +609,7 @@ namespace Avalonia.Controls
}
var selected = _rootNode.Select(index, select);
if (selected)
{
AnchorIndex = new IndexPath(index);
@ -626,7 +625,7 @@ namespace Avalonia.Controls
var childNode = _rootNode.GetAt(groupIndex, realizeChild: true);
var selected = childNode!.Select(itemIndex, select);
if (selected)
{
AnchorIndex = new IndexPath(groupIndex, itemIndex);
@ -636,7 +635,7 @@ namespace Avalonia.Controls
private void SelectWithPathImpl(IndexPath index, bool select)
{
bool selected = false;
if (_singleSelect)
{
ClearSelection(resetAnchor: true);
@ -665,7 +664,7 @@ namespace Avalonia.Controls
{
int anchorIndex = 0;
var anchor = AnchorIndex;
if (anchor != null)
{
anchorIndex = anchor.GetAt(0);
@ -679,7 +678,7 @@ namespace Avalonia.Controls
var startGroupIndex = 0;
var startItemIndex = 0;
var anchorIndex = AnchorIndex;
if (anchorIndex != null)
{
startGroupIndex = anchorIndex.GetAt(0);

Loading…
Cancel
Save