Browse Source

Make ICollectionView internal and rename DataGrid specific

classes on Avalonia.Collection namespace of DataGrid's assembly
with DataGrid prefix to avoid API pollution later on.
pull/2109/head
Jumar Macato 8 years ago
parent
commit
7d8e218699
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 2
      samples/ControlCatalog/Pages/DataGridPage.xaml.cs
  2. 44
      src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs
  3. 106
      src/Avalonia.Controls.DataGrid/Collections/DataGridGroupDescription.cs
  4. 20
      src/Avalonia.Controls.DataGrid/Collections/DataGridSortDescription.cs
  5. 14
      src/Avalonia.Controls.DataGrid/Collections/IDataGridCollectionView.cs
  6. 8
      src/Avalonia.Controls.DataGrid/DataGrid.cs
  7. 2
      src/Avalonia.Controls.DataGrid/DataGridColumn.cs
  8. 8
      src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs
  9. 28
      src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs
  10. 4
      src/Avalonia.Controls.DataGrid/DataGridRowGroupInfo.cs
  11. 20
      src/Avalonia.Controls.DataGrid/DataGridRows.cs

2
samples/ControlCatalog/Pages/DataGridPage.xaml.cs

@ -23,7 +23,7 @@ namespace ControlCatalog.Pages
dg2.IsReadOnly = true;
var collectionView2 = new CollectionViewBase(Countries.All);
collectionView2.GroupDescriptions.Add(new PathGroupDescription("Region"));
collectionView2.GroupDescriptions.Add(new DataGridPathGroupDescription("Region"));
dg2.Items = collectionView2;

44
src/Avalonia.Controls.DataGrid/Collections/CollectionView.cs → src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs

@ -45,17 +45,17 @@ namespace Avalonia.Collections
}
/// <summary>Defines a method that enables a collection to provide a custom view for specialized sorting, filtering, grouping, and currency.</summary>
public interface ICollectionViewFactory
internal interface ICollectionViewFactory
{
/// <summary>Returns a custom view for specialized sorting, filtering, grouping, and currency.</summary>
/// <returns>A custom view for specialized sorting, filtering, grouping, and currency.</returns>
ICollectionView CreateView();
IDataGridCollectionView CreateView();
}
/// <summary>
/// PagedCollectionView view over an IEnumerable.
/// </summary>
public sealed class CollectionViewBase : ICollectionView, IEditableCollectionView, INotifyPropertyChanged //IPagedCollectionView,
public sealed class CollectionViewBase : IDataGridCollectionView, IDataGridEditableCollectionView, INotifyPropertyChanged //IPagedCollectionView,
{
#region Static Fields and Constants
@ -63,7 +63,7 @@ namespace Avalonia.Collections
/// Since there's nothing in the un-cancelable event args that is mutable,
/// just create one instance to be used universally.
/// </summary>
private static readonly CurrentChangingEventArgs uncancelableCurrentChangingEventArgs = new CurrentChangingEventArgs(false);
private static readonly DataGridCurrentChangingEventArgs uncancelableCurrentChangingEventArgs = new DataGridCurrentChangingEventArgs(false);
#endregion Static Fields and Constants
@ -178,7 +178,7 @@ namespace Avalonia.Collections
/// <summary>
/// Private accessor for the SortDescriptions
/// </summary>
private AvaloniaSortDescriptionCollection _sortDescriptions;
private DataGridSortDescriptionCollection _sortDescriptions;
/// <summary>
/// Private accessor for the SourceCollection
@ -298,7 +298,7 @@ namespace Avalonia.Collections
/// <summary>
/// Raised when the CurrentItem property is changing
/// </summary>
public event EventHandler<CurrentChangingEventArgs> CurrentChanging;
public event EventHandler<DataGridCurrentChangingEventArgs> CurrentChanging;
/// <summary>
/// Raised when a page index change completed
@ -678,7 +678,7 @@ namespace Avalonia.Collections
/// <summary>
/// Gets the description of grouping, indexed by level.
/// </summary>
public AvaloniaList<AvaloniaGroupDescription> GroupDescriptions
public AvaloniaList<DataGridGroupDescription> GroupDescriptions
{
get
{
@ -686,8 +686,8 @@ namespace Avalonia.Collections
}
}
int ICollectionView.GroupingDepth => GroupDescriptions?.Count ?? 0;
string ICollectionView.GetGroupingPropertyNameAtDepth(int level)
int IDataGridCollectionView.GroupingDepth => GroupDescriptions?.Count ?? 0;
string IDataGridCollectionView.GetGroupingPropertyNameAtDepth(int level)
{
var groups = GroupDescriptions;
if(groups != null && level >= 0 && level < groups.Count)
@ -971,13 +971,13 @@ namespace Avalonia.Collections
/// Use <seealso cref="CanSort"/> property to test if sorting is supported before adding
/// to SortDescriptions.
/// </exception>
public AvaloniaSortDescriptionCollection SortDescriptions
public DataGridSortDescriptionCollection SortDescriptions
{
get
{
if (_sortDescriptions == null)
{
SetSortDescriptions(new AvaloniaSortDescriptionCollection());
SetSortDescriptions(new DataGridSortDescriptionCollection());
}
return _sortDescriptions;
@ -1089,7 +1089,7 @@ namespace Avalonia.Collections
get { return _isGrouping; }
}
bool ICollectionView.IsGrouping => IsGrouping;
bool IDataGridCollectionView.IsGrouping => IsGrouping;
/// <summary>
/// Gets a value indicating whether there
@ -2379,7 +2379,7 @@ namespace Avalonia.Collections
/// </summary>
public void Refresh()
{
if (this is IEditableCollectionView ecv && (ecv.IsAddingNew || ecv.IsEditingItem))
if (this is IDataGridEditableCollectionView ecv && (ecv.IsAddingNew || ecv.IsEditingItem))
{
throw new InvalidOperationException(GetOperationNotAllowedDuringAddOrEditText(nameof(Refresh)));
}
@ -2970,7 +2970,7 @@ namespace Avalonia.Collections
/// <returns>False if a listener cancels the change, True otherwise</returns>
private bool OkToChangeCurrent()
{
CurrentChangingEventArgs args = new CurrentChangingEventArgs();
DataGridCurrentChangingEventArgs args = new DataGridCurrentChangingEventArgs();
OnCurrentChanging(args);
return !args.Cancel;
}
@ -3060,7 +3060,7 @@ namespace Avalonia.Collections
/// <exception cref="InvalidOperationException">
/// This CurrentChanging event cannot be canceled.
/// </exception>
private void OnCurrentChanging(CurrentChangingEventArgs args)
private void OnCurrentChanging(DataGridCurrentChangingEventArgs args)
{
if (args == null)
{
@ -3153,19 +3153,19 @@ namespace Avalonia.Collections
{
if (groupRoot == _temporaryGroup || PageSize == 0)
{
if (groupRoot.ActiveComparer is CollectionViewGroupInternal.ListComparer listComparer)
if (groupRoot.ActiveComparer is DataGridCollectionViewGroupInternal.ListComparer listComparer)
{
listComparer.ResetList(InternalList);
}
else
{
groupRoot.ActiveComparer = new CollectionViewGroupInternal.ListComparer(InternalList);
groupRoot.ActiveComparer = new DataGridCollectionViewGroupInternal.ListComparer(InternalList);
}
}
else if (groupRoot == _group)
{
// create the new comparer based on the current _temporaryGroup
groupRoot.ActiveComparer = new CollectionViewGroupInternal.CollectionViewGroupComparer(_temporaryGroup);
groupRoot.ActiveComparer = new DataGridCollectionViewGroupInternal.CollectionViewGroupComparer(_temporaryGroup);
}
}
@ -3965,7 +3965,7 @@ namespace Avalonia.Collections
/// Set new SortDescription collection; re-hook collection change notification handler
/// </summary>
/// <param name="descriptions">SortDescriptionCollection to set the property value to</param>
private void SetSortDescriptions(AvaloniaSortDescriptionCollection descriptions)
private void SetSortDescriptions(DataGridSortDescriptionCollection descriptions)
{
if (_sortDescriptions != null)
{
@ -4028,7 +4028,7 @@ namespace Avalonia.Collections
var itemType = ItemType;
foreach (AvaloniaSortDescription sort in SortDescriptions)
foreach (DataGridSortDescription sort in SortDescriptions)
{
sort.Initialize(itemType);
//string propertyPath = sort.PropertyName;
@ -4385,7 +4385,7 @@ namespace Avalonia.Collections
{
private readonly IComparer<object>[] _comparers;
public MergedComparer(AvaloniaSortDescriptionCollection coll)
public MergedComparer(DataGridSortDescriptionCollection coll)
{
_comparers = MakeComparerArray(coll);
}
@ -4393,7 +4393,7 @@ namespace Avalonia.Collections
: this(collectionView.SortDescriptions)
{ }
private static IComparer<object>[] MakeComparerArray(AvaloniaSortDescriptionCollection coll)
private static IComparer<object>[] MakeComparerArray(DataGridSortDescriptionCollection coll)
{
return
coll.Select(c => c.Comparer)

106
src/Avalonia.Controls.DataGrid/Collections/AvaloniaGroupDescription.cs → src/Avalonia.Controls.DataGrid/Collections/DataGridGroupDescription.cs

@ -19,11 +19,11 @@ using Avalonia.Utilities;
namespace Avalonia.Collections
{
public abstract class AvaloniaGroupDescription : INotifyPropertyChanged
public abstract class DataGridGroupDescription : INotifyPropertyChanged
{
public AvaloniaList<object> GroupKeys { get; }
public AvaloniaGroupDescription()
public DataGridGroupDescription()
{
GroupKeys = new AvaloniaList<object>();
GroupKeys.CollectionChanged += (sender, e) => OnPropertyChanged(new PropertyChangedEventArgs(nameof(GroupKeys)));
@ -54,14 +54,14 @@ namespace Avalonia.Collections
return object.Equals(groupKey, itemKey);
}
}
public class PathGroupDescription : AvaloniaGroupDescription
public class DataGridPathGroupDescription : DataGridGroupDescription
{
private string _propertyPath;
private Type _propertyType;
private IValueConverter _valueConverter;
private StringComparison _stringComparison = StringComparison.Ordinal;
public PathGroupDescription(string propertyPath)
public DataGridPathGroupDescription(string propertyPath)
{
_propertyPath = propertyPath;
}
@ -114,7 +114,7 @@ namespace Avalonia.Collections
}
}
public abstract class CollectionViewGroup : INotifyPropertyChanged
public abstract class DataGridCollectionViewGroup : INotifyPropertyChanged
{
private int _itemCount;
@ -133,7 +133,7 @@ namespace Avalonia.Collections
}
}
protected CollectionViewGroup(object key)
protected DataGridCollectionViewGroup(object key)
{
Key = key;
ProtectedItems = new AvaloniaList<object>();
@ -159,24 +159,24 @@ namespace Avalonia.Collections
PropertyChanged?.Invoke(this, e);
}
}
internal class CollectionViewGroupInternal : CollectionViewGroup
internal class DataGridCollectionViewGroupInternal : DataGridCollectionViewGroup
{
/// <summary>
/// GroupDescription used to define how to group the items
/// </summary>
private AvaloniaGroupDescription _groupBy;
private DataGridGroupDescription _groupBy;
/// <summary>
/// Parent group of this CollectionViewGroupInternal
/// </summary>
private readonly CollectionViewGroupInternal _parentGroup;
private readonly DataGridCollectionViewGroupInternal _parentGroup;
/// <summary>
/// Used for detecting stale enumerators
/// </summary>
private int _version;
public CollectionViewGroupInternal(object key, CollectionViewGroupInternal parent)
public DataGridCollectionViewGroupInternal(object key, DataGridCollectionViewGroupInternal parent)
: base(key)
{
_parentGroup = parent;
@ -186,7 +186,7 @@ namespace Avalonia.Collections
internal int FullCount { get; set; }
internal AvaloniaGroupDescription GroupBy
internal DataGridGroupDescription GroupBy
{
get { return _groupBy; }
set
@ -240,7 +240,7 @@ namespace Avalonia.Collections
// look for first item, child by child
for (int k = 0, n = Items.Count; k < n; ++k)
{
if (!(Items[k] is CollectionViewGroupInternal subgroup))
if (!(Items[k] is DataGridCollectionViewGroupInternal subgroup))
{
// child is an item - return it
return Items[k];
@ -267,7 +267,7 @@ namespace Avalonia.Collections
}
}
private CollectionViewGroupInternal Parent => _parentGroup;
private DataGridCollectionViewGroupInternal Parent => _parentGroup;
/// <summary>
/// Adds the specified item to the collection
@ -322,7 +322,7 @@ namespace Avalonia.Collections
for (index = low; index < high; ++index)
{
object seed1 = (ProtectedItems[index] is CollectionViewGroupInternal subgroup) ? subgroup.SeedItem : ProtectedItems[index];
object seed1 = (ProtectedItems[index] is DataGridCollectionViewGroupInternal subgroup) ? subgroup.SeedItem : ProtectedItems[index];
if (seed1 == AvaloniaProperty.UnsetValue)
{
continue;
@ -383,7 +383,7 @@ namespace Avalonia.Collections
{
for (int k = 0, n = Items.Count; k < n; ++k)
{
if (Items[k] is CollectionViewGroupInternal subgroup)
if (Items[k] is DataGridCollectionViewGroupInternal subgroup)
{
// current item is a group - either drill in, or skip over
if (index < subgroup.ItemCount)
@ -426,7 +426,7 @@ namespace Avalonia.Collections
int result = 0;
// accumulate the number of predecessors at each level
for (CollectionViewGroupInternal group = this;
for (DataGridCollectionViewGroupInternal group = this;
group != null;
item = group, group = group.Parent, index = -1)
{
@ -441,7 +441,7 @@ namespace Avalonia.Collections
}
// accumulate leaf count
CollectionViewGroupInternal subgroup = group.Items[k] as CollectionViewGroupInternal;
DataGridCollectionViewGroupInternal subgroup = group.Items[k] as DataGridCollectionViewGroupInternal;
result += subgroup?.ItemCount ?? 1;
}
}
@ -460,7 +460,7 @@ namespace Avalonia.Collections
int leaves = 0; // number of leaves we've passed over so far
for (int k = 0, n = Items.Count; k < n; ++k)
{
if (Items[k] is CollectionViewGroupInternal subgroup)
if (Items[k] is DataGridCollectionViewGroupInternal subgroup)
{
int subgroupIndex = subgroup.LeafIndexOf(item);
if (subgroupIndex < 0)
@ -519,13 +519,13 @@ namespace Avalonia.Collections
/// Removes an empty group from the PagedCollectionView grouping
/// </summary>
/// <param name="group">Empty subgroup to remove</param>
private static void RemoveEmptyGroup(CollectionViewGroupInternal group)
private static void RemoveEmptyGroup(DataGridCollectionViewGroupInternal group)
{
CollectionViewGroupInternal parent = group.Parent;
DataGridCollectionViewGroupInternal parent = group.Parent;
if (parent != null)
{
AvaloniaGroupDescription groupBy = parent.GroupBy;
DataGridGroupDescription groupBy = parent.GroupBy;
int index = parent.ProtectedItems.IndexOf(group);
// remove the subgroup unless it is one of the explicit groups
@ -544,9 +544,9 @@ namespace Avalonia.Collections
/// <param name="delta">Delta to change count by</param>
protected void ChangeCounts(object item, int delta)
{
bool changeLeafCount = !(item is CollectionViewGroup);
bool changeLeafCount = !(item is DataGridCollectionViewGroup);
for (CollectionViewGroupInternal group = this;
for (DataGridCollectionViewGroupInternal group = this;
group != null;
group = group._parentGroup)
{
@ -576,7 +576,7 @@ namespace Avalonia.Collections
private class LeafEnumerator : IEnumerator
{
private object _current; // current item
private CollectionViewGroupInternal _group; // parent group
private DataGridCollectionViewGroupInternal _group; // parent group
private int _index; // current index into Items
private IEnumerator _subEnum; // enumerator over current subgroup
private int _version; // parent group's version at ctor
@ -585,7 +585,7 @@ namespace Avalonia.Collections
/// Initializes a new instance of the LeafEnumerator class.
/// </summary>
/// <param name="group">CollectionViewGroupInternal that uses the enumerator</param>
public LeafEnumerator(CollectionViewGroupInternal group)
public LeafEnumerator(DataGridCollectionViewGroupInternal group)
{
_group = group;
DoReset(); // don't call virtual Reset in ctor
@ -636,7 +636,7 @@ namespace Avalonia.Collections
return false;
}
CollectionViewGroupInternal subgroup = _group.Items[_index] as CollectionViewGroupInternal;
DataGridCollectionViewGroupInternal subgroup = _group.Items[_index] as DataGridCollectionViewGroupInternal;
if (subgroup == null)
{
// current item is a leaf - it's the new Current
@ -839,7 +839,7 @@ namespace Avalonia.Collections
}
internal class CollectionViewGroupRoot : CollectionViewGroupInternal, INotifyCollectionChanged
internal class CollectionViewGroupRoot : DataGridCollectionViewGroupInternal, INotifyCollectionChanged
{
/// <summary>
/// String constant used for the Root Name
@ -854,12 +854,12 @@ namespace Avalonia.Collections
/// <summary>
/// Private accessor for the top level GroupDescription
/// </summary>
private static AvaloniaGroupDescription topLevelGroupDescription;
private static DataGridGroupDescription topLevelGroupDescription;
/// <summary>
/// Private accessor for an ObservableCollection containing group descriptions
/// </summary>
private readonly AvaloniaList<AvaloniaGroupDescription> _groupBy = new AvaloniaList<AvaloniaGroupDescription>();
private readonly AvaloniaList<DataGridGroupDescription> _groupBy = new AvaloniaList<DataGridGroupDescription>();
/// <summary>
/// Indicates whether the list of items (after applying the sort and filters, if any)
@ -870,7 +870,7 @@ namespace Avalonia.Collections
/// <summary>
/// Private accessor for the owning ICollectionView
/// </summary>
private readonly ICollectionView _view;
private readonly IDataGridCollectionView _view;
/// <summary>
/// Raise this event when the (grouped) view changes
@ -887,7 +887,7 @@ namespace Avalonia.Collections
/// </summary>
/// <param name="view">CollectionView that contains this grouping</param>
/// <param name="isDataInGroupOrder">True if items are already in correct order for grouping</param>
internal CollectionViewGroupRoot(ICollectionView view, bool isDataInGroupOrder)
internal CollectionViewGroupRoot(IDataGridCollectionView view, bool isDataInGroupOrder)
: base(RootName, null)
{
_view = view;
@ -897,7 +897,7 @@ namespace Avalonia.Collections
/// <summary>
/// Gets the description of grouping, indexed by level.
/// </summary>
public virtual AvaloniaList<AvaloniaGroupDescription> GroupDescriptions => _groupBy;
public virtual AvaloniaList<DataGridGroupDescription> GroupDescriptions => _groupBy;
/// <summary>
/// Gets or sets the current IComparer being used
@ -938,7 +938,7 @@ namespace Avalonia.Collections
protected override int FindIndex(object item, object seed, IComparer comparer, int low, int high)
{
// root group needs to adjust the bounds of the search to exclude the new item (if any)
if (_view is IEditableCollectionView iecv && iecv.IsAddingNew)
if (_view is IDataGridEditableCollectionView iecv && iecv.IsAddingNew)
{
--high;
}
@ -1061,15 +1061,15 @@ namespace Avalonia.Collections
/// <param name="level">The level of grouping.</param>
/// <param name="key">Name of subgroup to add to</param>
/// <param name="loading">Whether we are currently loading</param>
private void AddToSubgroup(object item, CollectionViewGroupInternal group, int level, object key, bool loading)
private void AddToSubgroup(object item, DataGridCollectionViewGroupInternal group, int level, object key, bool loading)
{
CollectionViewGroupInternal subgroup;
DataGridCollectionViewGroupInternal subgroup;
int index = (_isDataInGroupOrder) ? group.LastIndex : 0;
// find the desired subgroup
for (int n = group.Items.Count; index < n; ++index)
{
subgroup = group.Items[index] as CollectionViewGroupInternal;
subgroup = group.Items[index] as DataGridCollectionViewGroupInternal;
if (subgroup == null)
{
continue; // skip children that are not groups
@ -1084,7 +1084,7 @@ namespace Avalonia.Collections
}
// the item didn't match any subgroups. Create a new subgroup and add the item.
subgroup = new CollectionViewGroupInternal(key, group);
subgroup = new DataGridCollectionViewGroupInternal(key, group);
InitializeGroup(subgroup, level + 1, item);
@ -1112,7 +1112,7 @@ namespace Avalonia.Collections
/// <param name="group">Group to add item to</param>
/// <param name="level">The level of grouping</param>
/// <param name="loading">Whether we are currently loading</param>
private void AddToSubgroups(object item, CollectionViewGroupInternal group, int level, bool loading)
private void AddToSubgroups(object item, DataGridCollectionViewGroupInternal group, int level, bool loading)
{
object key = GetGroupKey(item, group.GroupBy, level);
@ -1145,7 +1145,7 @@ namespace Avalonia.Collections
}
}
public virtual Func<CollectionViewGroup, int, AvaloniaGroupDescription> GroupBySelector { get; set; }
public virtual Func<DataGridCollectionViewGroup, int, DataGridGroupDescription> GroupBySelector { get; set; }
/// <summary>
/// Returns the description of how to divide the given group into subgroups
@ -1153,9 +1153,9 @@ namespace Avalonia.Collections
/// <param name="group">CollectionViewGroup to get group description from</param>
/// <param name="level">The level of grouping</param>
/// <returns>GroupDescription of how to divide the given group</returns>
private AvaloniaGroupDescription GetGroupDescription(CollectionViewGroup group, int level)
private DataGridGroupDescription GetGroupDescription(DataGridCollectionViewGroup group, int level)
{
AvaloniaGroupDescription result = null;
DataGridGroupDescription result = null;
if (group == this)
{
group = null;
@ -1181,7 +1181,7 @@ namespace Avalonia.Collections
/// <param name="groupDescription">GroupDescription for the group</param>
/// <param name="level">The level of grouping</param>
/// <returns>Group names for the specified item</returns>
private object GetGroupKey(object item, AvaloniaGroupDescription groupDescription, int level)
private object GetGroupKey(object item, DataGridGroupDescription groupDescription, int level)
{
if (groupDescription != null)
{
@ -1199,10 +1199,10 @@ namespace Avalonia.Collections
/// <param name="group">Group to initialize</param>
/// <param name="level">The level of grouping</param>
/// <param name="seedItem">The seed item to compare with to see where to insert</param>
private void InitializeGroup(CollectionViewGroupInternal group, int level, object seedItem)
private void InitializeGroup(DataGridCollectionViewGroupInternal group, int level, object seedItem)
{
// set the group description for dividing the group into subgroups
AvaloniaGroupDescription groupDescription = GetGroupDescription(group, level);
DataGridGroupDescription groupDescription = GetGroupDescription(group, level);
group.GroupBy = groupDescription;
// create subgroups for each of the explicit names
@ -1211,7 +1211,7 @@ namespace Avalonia.Collections
{
for (int k = 0, n = keys.Count; k < n; ++k)
{
CollectionViewGroupInternal subgroup = new CollectionViewGroupInternal(keys[k], group);
DataGridCollectionViewGroupInternal subgroup = new DataGridCollectionViewGroupInternal(keys[k], group);
InitializeGroup(subgroup, level + 1, seedItem);
group.Add(subgroup);
}
@ -1226,7 +1226,7 @@ namespace Avalonia.Collections
/// <param name="group">Group to remove item from</param>
/// <param name="item">Item to remove</param>
/// <returns>True if item could not be removed</returns>
private bool RemoveFromGroupDirectly(CollectionViewGroupInternal group, object item)
private bool RemoveFromGroupDirectly(DataGridCollectionViewGroupInternal group, object item)
{
int leafIndex = group.Remove(item, true);
if (leafIndex >= 0)
@ -1248,15 +1248,15 @@ namespace Avalonia.Collections
/// <param name="level">The level of grouping</param>
/// <param name="key">Name of item to remove</param>
/// <returns>Return true if the item was not in one of the subgroups it was supposed to be.</returns>
private bool RemoveFromSubgroup(object item, CollectionViewGroupInternal group, int level, object key)
private bool RemoveFromSubgroup(object item, DataGridCollectionViewGroupInternal group, int level, object key)
{
bool itemIsMissing = false;
CollectionViewGroupInternal subgroup;
DataGridCollectionViewGroupInternal subgroup;
// find the desired subgroup
for (int index = 0, n = group.Items.Count; index < n; ++index)
{
subgroup = group.Items[index] as CollectionViewGroupInternal;
subgroup = group.Items[index] as DataGridCollectionViewGroupInternal;
if (subgroup == null)
{
continue; // skip children that are not groups
@ -1284,7 +1284,7 @@ namespace Avalonia.Collections
/// <param name="group">Group to remove item from</param>
/// <param name="level">The level of grouping</param>
/// <returns>Return true if the item was not in one of the subgroups it was supposed to be.</returns>
private bool RemoveFromSubgroups(object item, CollectionViewGroupInternal group, int level)
private bool RemoveFromSubgroups(object item, DataGridCollectionViewGroupInternal group, int level)
{
bool itemIsMissing = false;
object key = GetGroupKey(item, group.GroupBy, level);
@ -1326,7 +1326,7 @@ namespace Avalonia.Collections
/// </summary>
/// <param name="group">Group to remove item from</param>
/// <param name="item">Item to remove</param>
private void RemoveItemFromSubgroupsByExhaustiveSearch(CollectionViewGroupInternal group, object item)
private void RemoveItemFromSubgroupsByExhaustiveSearch(DataGridCollectionViewGroupInternal group, object item)
{
// try to remove the item from the direct children
// this function only returns true if it failed to remove from group directly
@ -1337,7 +1337,7 @@ namespace Avalonia.Collections
// (loop runs backwards in case an entire group is deleted)
for (int k = group.Items.Count - 1; k >= 0; --k)
{
if (group.Items[k] is CollectionViewGroupInternal subgroup)
if (group.Items[k] is DataGridCollectionViewGroupInternal subgroup)
{
RemoveItemFromSubgroupsByExhaustiveSearch(subgroup, item);
}
@ -1349,7 +1349,7 @@ namespace Avalonia.Collections
/// <summary>
/// TopLevelGroupDescription class
/// </summary>
private class TopLevelGroupDescription : AvaloniaGroupDescription
private class TopLevelGroupDescription : DataGridGroupDescription
{
/// <summary>
/// Initializes a new instance of the TopLevelGroupDescription class.

20
src/Avalonia.Controls.DataGrid/Collections/AvaloniaSortDescription.cs → src/Avalonia.Controls.DataGrid/Collections/DataGridSortDescription.cs

@ -13,7 +13,7 @@ using Avalonia.Utilities;
namespace Avalonia.Collections
{
public abstract class AvaloniaSortDescription
public abstract class DataGridSortDescription
{
public virtual string PropertyPath => null;
public virtual bool Descending => false;
@ -29,7 +29,7 @@ namespace Avalonia.Collections
return seq.ThenBy(o => o, Comparer);
}
internal virtual AvaloniaSortDescription SwitchSortDirection()
internal virtual DataGridSortDescription SwitchSortDirection()
{
return this;
}
@ -109,7 +109,7 @@ namespace Avalonia.Collections
#endregion
}
private class PathSortDescription : AvaloniaSortDescription
private class DataGridPathSortDescription : DataGridSortDescription
{
private readonly bool _descending;
private readonly string _propertyPath;
@ -138,14 +138,14 @@ namespace Avalonia.Collections
public override IComparer<object> Comparer => _comparer.Value;
public override bool Descending => _descending;
public PathSortDescription(string propertyPath, bool descending, CultureInfo culture)
public DataGridPathSortDescription(string propertyPath, bool descending, CultureInfo culture)
{
_propertyPath = propertyPath;
_descending = descending;
_cultureSensitiveComparer = new Lazy<CultureSensitiveComparer>(() => new CultureSensitiveComparer(culture ?? CultureInfo.CurrentCulture));
_comparer = new Lazy<IComparer<object>>(() => Comparer<object>.Create((x, y) => Compare(x, y)));
}
private PathSortDescription(PathSortDescription inner, bool descending)
private DataGridPathSortDescription(DataGridPathSortDescription inner, bool descending)
{
_propertyPath = inner._propertyPath;
_descending = descending;
@ -245,18 +245,18 @@ namespace Avalonia.Collections
}
}
internal override AvaloniaSortDescription SwitchSortDirection()
internal override DataGridSortDescription SwitchSortDirection()
{
return new PathSortDescription(this, !_descending);
return new DataGridPathSortDescription(this, !_descending);
}
}
public static AvaloniaSortDescription FromPath(string propertyPath, bool descending = false, CultureInfo culture = null)
public static DataGridSortDescription FromPath(string propertyPath, bool descending = false, CultureInfo culture = null)
{
return new PathSortDescription(propertyPath, descending, culture);
return new DataGridPathSortDescription(propertyPath, descending, culture);
}
}
public class AvaloniaSortDescriptionCollection : AvaloniaList<AvaloniaSortDescription>
public class DataGridSortDescriptionCollection : AvaloniaList<DataGridSortDescription>
{ }
}

14
src/Avalonia.Controls.DataGrid/Collections/ICollectionView.cs → src/Avalonia.Controls.DataGrid/Collections/IDataGridCollectionView.cs

@ -13,20 +13,20 @@ using System.Text;
namespace Avalonia.Collections
{
/// <summary>Provides data for the <see cref="E:Avalonia.Collections.ICollectionView.CurrentChanging" /> event.</summary>
public class CurrentChangingEventArgs : EventArgs
public class DataGridCurrentChangingEventArgs : EventArgs
{
private bool _cancel;
private bool _isCancelable;
/// <summary>Initializes a new instance of the <see cref="T:System.ComponentModel.CurrentChangingEventArgs" /> class and sets the <see cref="P:System.ComponentModel.CurrentChangingEventArgs.IsCancelable" /> property to true.</summary>
public CurrentChangingEventArgs()
public DataGridCurrentChangingEventArgs()
{
Initialize(true);
}
/// <summary>Initializes a new instance of the <see cref="T:System.ComponentModel.CurrentChangingEventArgs" /> class and sets the <see cref="P:System.ComponentModel.CurrentChangingEventArgs.IsCancelable" /> property to the specified value.</summary>
/// <param name="isCancelable">true to disable the ability to cancel a <see cref="P:System.ComponentModel.ICollectionView.CurrentItem" /> change; false to enable cancellation.</param>
public CurrentChangingEventArgs(bool isCancelable)
public DataGridCurrentChangingEventArgs(bool isCancelable)
{
Initialize(isCancelable);
}
@ -66,7 +66,7 @@ namespace Avalonia.Collections
}
/// <summary>Enables collections to have the functionalities of current record management, custom sorting, filtering, and grouping.</summary>
public interface ICollectionView : IEnumerable, INotifyCollectionChanged
internal interface IDataGridCollectionView : IEnumerable, INotifyCollectionChanged
{
/// <summary>Gets or sets the cultural information for any operations of the view that may differ by culture, such as sorting.</summary>
/// <returns>The culture information to use during culture-sensitive operations. </returns>
@ -91,7 +91,7 @@ namespace Avalonia.Collections
/// <summary>Gets a collection of <see cref="T:System.ComponentModel.SortDescription" /> instances that describe how the items in the collection are sorted in the view.</summary>
/// <returns>A collection of values that describe how the items in the collection are sorted in the view.</returns>
AvaloniaSortDescriptionCollection SortDescriptions { get; }
DataGridSortDescriptionCollection SortDescriptions { get; }
/// <summary>Gets a value that indicates whether this view supports sorting by way of the <see cref="P:System.ComponentModel.ICollectionView.SortDescriptions" /> property.</summary>
/// <returns>true if this view supports sorting; otherwise, false.</returns>
@ -167,12 +167,12 @@ namespace Avalonia.Collections
bool MoveCurrentToPosition(int position);
/// <summary>Occurs before the current item changes.</summary>
event EventHandler<CurrentChangingEventArgs> CurrentChanging;
event EventHandler<DataGridCurrentChangingEventArgs> CurrentChanging;
/// <summary>Occurs after the current item has been changed.</summary>
event EventHandler CurrentChanged;
}
public interface IEditableCollectionView
internal interface IDataGridEditableCollectionView
{
/// <summary>Gets a value that indicates whether a new item can be added to the collection.</summary>
/// <returns>true if a new item can be added to the collection; otherwise, false.</returns>

8
src/Avalonia.Controls.DataGrid/DataGrid.cs

@ -897,7 +897,7 @@ namespace Avalonia.Controls
// Wrap an IEnumerable in an ICollectionView if it's not already one
bool setDefaultSelection = false;
if (newItemsSource != null && !(newItemsSource is ICollectionView))
if (newItemsSource != null && !(newItemsSource is IDataGridCollectionView))
{
DataConnection.DataSource = DataGridDataConnection.CreateView(newItemsSource);
}
@ -2050,7 +2050,7 @@ namespace Avalonia.Controls
{
int slot = -1;
DataGridRowGroupInfo rowGroupInfo = null;
if (item is CollectionViewGroup collectionViewGroup)
if (item is DataGridCollectionViewGroup collectionViewGroup)
{
rowGroupInfo = RowGroupInfoFromCollectionViewGroup(collectionViewGroup);
if (rowGroupInfo == null)
@ -2737,7 +2737,7 @@ namespace Avalonia.Controls
try
{
int slot = -1;
if (item is CollectionViewGroup group)
if (item is DataGridCollectionViewGroup group)
{
DataGridRowGroupInfo groupInfo = RowGroupInfoFromCollectionViewGroup(group);
if (groupInfo != null)
@ -5940,7 +5940,7 @@ namespace Avalonia.Controls
/// <param name="item">item</param>
/// <param name="groupLevel">groupLevel</param>
/// <returns>The group the given item falls under or null if the item is not in the ItemsSource</returns>
public CollectionViewGroup GetGroupFromItem(object item, int groupLevel)
public DataGridCollectionViewGroup GetGroupFromItem(object item, int groupLevel)
{
int itemIndex = DataConnection.IndexOf(item);
if (itemIndex == -1)

2
src/Avalonia.Controls.DataGrid/DataGridColumn.cs

@ -1044,7 +1044,7 @@ namespace Avalonia.Controls
/// We get the sort description from the data source. We don't worry whether we can modify sort -- perhaps the sort description
/// describes an unchangeable sort that exists on the data.
/// </summary>
internal AvaloniaSortDescription GetSortDescription()
internal DataGridSortDescription GetSortDescription()
{
if (OwningGrid != null
&& OwningGrid.DataConnection != null

8
src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs

@ -341,12 +341,12 @@ namespace Avalonia.Controls
{
DataGrid owningGrid = OwningGrid;
AvaloniaSortDescription newSort;
DataGridSortDescription newSort;
KeyboardHelper.GetMetaKeyState(inputModifiers, out bool ctrl, out bool shift);
AvaloniaSortDescription sort = OwningColumn.GetSortDescription();
ICollectionView collectionView = owningGrid.DataConnection.CollectionView;
DataGridSortDescription sort = OwningColumn.GetSortDescription();
IDataGridCollectionView collectionView = owningGrid.DataConnection.CollectionView;
Debug.Assert(collectionView != null);
using (collectionView.DeferRefresh())
{
@ -402,7 +402,7 @@ namespace Avalonia.Controls
return;
}
newSort = AvaloniaSortDescription.FromPath(propertyName, culture: collectionView.Culture);
newSort = DataGridSortDescription.FromPath(propertyName, culture: collectionView.Culture);
owningGrid.DataConnection.SortDescriptions.Add(newSort);
}
}

28
src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs

@ -196,22 +196,22 @@ namespace Avalonia.Controls
}
}
public ICollectionView CollectionView
public IDataGridCollectionView CollectionView
{
get
{
return DataSource as ICollectionView;
return DataSource as IDataGridCollectionView;
}
}
public IEditableCollectionView EditableCollectionView
public IDataGridEditableCollectionView EditableCollectionView
{
get
{
return DataSource as IEditableCollectionView;
return DataSource as IDataGridEditableCollectionView;
}
}
public AvaloniaSortDescriptionCollection SortDescriptions
public DataGridSortDescriptionCollection SortDescriptions
{
get
{
@ -242,7 +242,7 @@ namespace Avalonia.Controls
return false;
}
IEditableCollectionView editableCollectionView = EditableCollectionView;
IDataGridEditableCollectionView editableCollectionView = EditableCollectionView;
if (editableCollectionView != null)
{
if (editableCollectionView.IsEditingItem && (dataItem == editableCollectionView.CurrentEditItem))
@ -272,7 +272,7 @@ namespace Avalonia.Controls
/// <returns>True if a cancellation operation was invoked.</returns>
public bool CancelEdit(object dataItem)
{
IEditableCollectionView editableCollectionView = EditableCollectionView;
IDataGridEditableCollectionView editableCollectionView = EditableCollectionView;
if (editableCollectionView != null)
{
if (editableCollectionView.CanCancelEdit)
@ -324,7 +324,7 @@ namespace Avalonia.Controls
/// <returns>True if a commit operation was invoked.</returns>
public bool EndEdit(object dataItem)
{
IEditableCollectionView editableCollectionView = EditableCollectionView;
IDataGridEditableCollectionView editableCollectionView = EditableCollectionView;
if (editableCollectionView != null)
{
// IEditableCollectionView.CommitEdit can potentially change currency. If it does,
@ -470,12 +470,12 @@ namespace Avalonia.Controls
/// </summary>
/// <param name="source">Enumerable source for which to create a view</param>
/// <returns>ICollectionView view over the provided source</returns>
internal static ICollectionView CreateView(IEnumerable source)
internal static IDataGridCollectionView CreateView(IEnumerable source)
{
Debug.Assert(source != null, "source unexpectedly null");
Debug.Assert(!(source is ICollectionView), "source is an ICollectionView");
Debug.Assert(!(source is IDataGridCollectionView), "source is an ICollectionView");
ICollectionView collectionView = null;
IDataGridCollectionView collectionView = null;
if (source is ICollectionViewFactory collectionViewFactory)
{
@ -515,7 +515,7 @@ namespace Avalonia.Controls
_scrollForCurrentChanged = scrollIntoView;
_backupSlotForCurrentChanged = backupSlot;
CollectionView.MoveCurrentTo(item is CollectionViewGroup ? null : item);
CollectionView.MoveCurrentTo(item is DataGridCollectionViewGroup ? null : item);
_expectingCurrentChanged = false;
}
@ -574,7 +574,7 @@ namespace Avalonia.Controls
{
// Committing Edit could cause our item to move to a group that no longer exists. In
// this case, we need to update the item.
if (_itemToSelectOnCurrentChanged is CollectionViewGroup collectionViewGroup)
if (_itemToSelectOnCurrentChanged is DataGridCollectionViewGroup collectionViewGroup)
{
DataGridRowGroupInfo groupInfo = _owner.RowGroupInfoFromCollectionViewGroup(collectionViewGroup);
if (groupInfo == null)
@ -609,7 +609,7 @@ namespace Avalonia.Controls
}
}
private void CollectionView_CurrentChanging(object sender, CurrentChangingEventArgs e)
private void CollectionView_CurrentChanging(object sender, DataGridCurrentChangingEventArgs e)
{
if (_owner.NoCurrentCellChangeCount == 0 &&
!_expectingCurrentChanged &&

4
src/Avalonia.Controls.DataGrid/DataGridRowGroupInfo.cs

@ -11,7 +11,7 @@ namespace Avalonia.Controls
internal class DataGridRowGroupInfo
{
public DataGridRowGroupInfo(
CollectionViewGroup collectionViewGroup,
DataGridCollectionViewGroup collectionViewGroup,
bool isVisible,
int level,
int slot,
@ -24,7 +24,7 @@ namespace Avalonia.Controls
LastSubItemSlot = lastSubItemSlot;
}
public CollectionViewGroup CollectionViewGroup
public DataGridCollectionViewGroup CollectionViewGroup
{
get;
private set;

20
src/Avalonia.Controls.DataGrid/DataGridRows.cs

@ -2225,7 +2225,7 @@ namespace Avalonia.Controls
// it since this lookup should be performant enough
int insertSlot = -1;
DataGridRowGroupInfo parentGroupInfo = GetParentGroupInfo(sender);
CollectionViewGroup group = e.NewItems[0] as CollectionViewGroup;
DataGridCollectionViewGroup group = e.NewItems[0] as DataGridCollectionViewGroup;
if (parentGroupInfo != null)
{
@ -2305,7 +2305,7 @@ namespace Avalonia.Controls
Debug.Assert(e.OldItems.Count == 1);
if (e.OldItems != null && e.OldItems.Count > 0)
{
if (e.OldItems[0] is CollectionViewGroup removedGroup)
if (e.OldItems[0] is DataGridCollectionViewGroup removedGroup)
{
if (removedGroup.Items != null)
{
@ -2380,7 +2380,7 @@ namespace Avalonia.Controls
{
if (e.PropertyName == "ItemCount")
{
DataGridRowGroupInfo rowGroupInfo = RowGroupInfoFromCollectionViewGroup(sender as CollectionViewGroup);
DataGridRowGroupInfo rowGroupInfo = RowGroupInfoFromCollectionViewGroup(sender as DataGridCollectionViewGroup);
if (rowGroupInfo != null && IsSlotVisible(rowGroupInfo.Slot))
{
if (DisplayData.GetDisplayedElement(rowGroupInfo.Slot) is DataGridRowGroupHeader rowGroupHeader)
@ -2414,12 +2414,12 @@ namespace Avalonia.Controls
{
int treeCount = 1;
if (group is CollectionViewGroup collectionViewGroup)
if (group is DataGridCollectionViewGroup collectionViewGroup)
{
if (collectionViewGroup.Items != null && collectionViewGroup.Items.Count > 0)
{
collectionViewGroup.Items.CollectionChanged += CollectionViewGroup_CollectionChanged;
if (collectionViewGroup.Items[0] is CollectionViewGroup)
if (collectionViewGroup.Items[0] is DataGridCollectionViewGroup)
{
foreach (object subGroup in collectionViewGroup.Items)
{
@ -2887,7 +2887,7 @@ namespace Avalonia.Controls
EnsureRowGroupSpacerColumnWidth(groupLevelCount);
}
internal DataGridRowGroupInfo RowGroupInfoFromCollectionViewGroup(CollectionViewGroup collectionViewGroup)
internal DataGridRowGroupInfo RowGroupInfoFromCollectionViewGroup(DataGridCollectionViewGroup collectionViewGroup)
{
foreach (int slot in RowGroupHeadersTable.GetIndexes())
{
@ -2905,7 +2905,7 @@ namespace Avalonia.Controls
/// </summary>
/// <param name="collectionViewGroup">CollectionViewGroup</param>
/// <param name="collapseAllSubgroups">Set to true to collapse all Subgroups</param>
public void CollapseRowGroup(CollectionViewGroup collectionViewGroup, bool collapseAllSubgroups)
public void CollapseRowGroup(DataGridCollectionViewGroup collectionViewGroup, bool collapseAllSubgroups)
{
if (WaitForLostFocus(delegate { CollapseRowGroup(collectionViewGroup, collapseAllSubgroups); }) ||
collectionViewGroup == null || !CommitEdit())
@ -2919,7 +2919,7 @@ namespace Avalonia.Controls
{
foreach (object groupObj in collectionViewGroup.Items)
{
if (groupObj is CollectionViewGroup subGroup)
if (groupObj is DataGridCollectionViewGroup subGroup)
{
CollapseRowGroup(subGroup, collapseAllSubgroups);
}
@ -2932,7 +2932,7 @@ namespace Avalonia.Controls
/// </summary>
/// <param name="collectionViewGroup">CollectionViewGroup</param>
/// <param name="expandAllSubgroups">Set to true to expand all Subgroups</param>
public void ExpandRowGroup(CollectionViewGroup collectionViewGroup, bool expandAllSubgroups)
public void ExpandRowGroup(DataGridCollectionViewGroup collectionViewGroup, bool expandAllSubgroups)
{
if (WaitForLostFocus(delegate { ExpandRowGroup(collectionViewGroup, expandAllSubgroups); }) ||
collectionViewGroup == null || !CommitEdit())
@ -2947,7 +2947,7 @@ namespace Avalonia.Controls
{
foreach (object groupObj in collectionViewGroup.Items)
{
if (groupObj is CollectionViewGroup subGroup)
if (groupObj is DataGridCollectionViewGroup subGroup)
{
ExpandRowGroup(subGroup, expandAllSubgroups);
}

Loading…
Cancel
Save