From 7d8e2186995d01805f423a989c5a3e14d9c837b9 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 2 Mar 2019 22:02:33 +0800 Subject: [PATCH] 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. --- .../ControlCatalog/Pages/DataGridPage.xaml.cs | 2 +- ...ctionView.cs => DataGridCollectionView.cs} | 44 ++++---- ...ription.cs => DataGridGroupDescription.cs} | 106 +++++++++--------- ...cription.cs => DataGridSortDescription.cs} | 20 ++-- ...tionView.cs => IDataGridCollectionView.cs} | 14 +-- src/Avalonia.Controls.DataGrid/DataGrid.cs | 8 +- .../DataGridColumn.cs | 2 +- .../DataGridColumnHeader.cs | 8 +- .../DataGridDataConnection.cs | 28 ++--- .../DataGridRowGroupInfo.cs | 4 +- .../DataGridRows.cs | 20 ++-- 11 files changed, 128 insertions(+), 128 deletions(-) rename src/Avalonia.Controls.DataGrid/Collections/{CollectionView.cs => DataGridCollectionView.cs} (98%) rename src/Avalonia.Controls.DataGrid/Collections/{AvaloniaGroupDescription.cs => DataGridGroupDescription.cs} (91%) rename src/Avalonia.Controls.DataGrid/Collections/{AvaloniaSortDescription.cs => DataGridSortDescription.cs} (92%) rename src/Avalonia.Controls.DataGrid/Collections/{ICollectionView.cs => IDataGridCollectionView.cs} (96%) diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs index 465f800275..d37297d837 100644 --- a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs +++ b/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; diff --git a/src/Avalonia.Controls.DataGrid/Collections/CollectionView.cs b/src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs similarity index 98% rename from src/Avalonia.Controls.DataGrid/Collections/CollectionView.cs rename to src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs index 995cc87fad..b334595971 100644 --- a/src/Avalonia.Controls.DataGrid/Collections/CollectionView.cs +++ b/src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs @@ -45,17 +45,17 @@ namespace Avalonia.Collections } /// Defines a method that enables a collection to provide a custom view for specialized sorting, filtering, grouping, and currency. - public interface ICollectionViewFactory + internal interface ICollectionViewFactory { /// Returns a custom view for specialized sorting, filtering, grouping, and currency. /// A custom view for specialized sorting, filtering, grouping, and currency. - ICollectionView CreateView(); + IDataGridCollectionView CreateView(); } /// /// PagedCollectionView view over an IEnumerable. /// - 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. /// - 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 /// /// Private accessor for the SortDescriptions /// - private AvaloniaSortDescriptionCollection _sortDescriptions; + private DataGridSortDescriptionCollection _sortDescriptions; /// /// Private accessor for the SourceCollection @@ -298,7 +298,7 @@ namespace Avalonia.Collections /// /// Raised when the CurrentItem property is changing /// - public event EventHandler CurrentChanging; + public event EventHandler CurrentChanging; /// /// Raised when a page index change completed @@ -678,7 +678,7 @@ namespace Avalonia.Collections /// /// Gets the description of grouping, indexed by level. /// - public AvaloniaList GroupDescriptions + public AvaloniaList 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 property to test if sorting is supported before adding /// to SortDescriptions. /// - 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; /// /// Gets a value indicating whether there @@ -2379,7 +2379,7 @@ namespace Avalonia.Collections /// 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 /// False if a listener cancels the change, True otherwise private bool OkToChangeCurrent() { - CurrentChangingEventArgs args = new CurrentChangingEventArgs(); + DataGridCurrentChangingEventArgs args = new DataGridCurrentChangingEventArgs(); OnCurrentChanging(args); return !args.Cancel; } @@ -3060,7 +3060,7 @@ namespace Avalonia.Collections /// /// This CurrentChanging event cannot be canceled. /// - 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 /// /// SortDescriptionCollection to set the property value to - 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[] _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[] MakeComparerArray(AvaloniaSortDescriptionCollection coll) + private static IComparer[] MakeComparerArray(DataGridSortDescriptionCollection coll) { return coll.Select(c => c.Comparer) diff --git a/src/Avalonia.Controls.DataGrid/Collections/AvaloniaGroupDescription.cs b/src/Avalonia.Controls.DataGrid/Collections/DataGridGroupDescription.cs similarity index 91% rename from src/Avalonia.Controls.DataGrid/Collections/AvaloniaGroupDescription.cs rename to src/Avalonia.Controls.DataGrid/Collections/DataGridGroupDescription.cs index 1ad22a640a..d04870ac2f 100644 --- a/src/Avalonia.Controls.DataGrid/Collections/AvaloniaGroupDescription.cs +++ b/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 GroupKeys { get; } - public AvaloniaGroupDescription() + public DataGridGroupDescription() { GroupKeys = new AvaloniaList(); 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(); @@ -159,24 +159,24 @@ namespace Avalonia.Collections PropertyChanged?.Invoke(this, e); } } - internal class CollectionViewGroupInternal : CollectionViewGroup + internal class DataGridCollectionViewGroupInternal : DataGridCollectionViewGroup { /// /// GroupDescription used to define how to group the items /// - private AvaloniaGroupDescription _groupBy; + private DataGridGroupDescription _groupBy; /// /// Parent group of this CollectionViewGroupInternal /// - private readonly CollectionViewGroupInternal _parentGroup; + private readonly DataGridCollectionViewGroupInternal _parentGroup; /// /// Used for detecting stale enumerators /// 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; /// /// 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 /// /// Empty subgroup to remove - 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 /// Delta to change count by 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. /// /// CollectionViewGroupInternal that uses the enumerator - 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 { /// /// String constant used for the Root Name @@ -854,12 +854,12 @@ namespace Avalonia.Collections /// /// Private accessor for the top level GroupDescription /// - private static AvaloniaGroupDescription topLevelGroupDescription; + private static DataGridGroupDescription topLevelGroupDescription; /// /// Private accessor for an ObservableCollection containing group descriptions /// - private readonly AvaloniaList _groupBy = new AvaloniaList(); + private readonly AvaloniaList _groupBy = new AvaloniaList(); /// /// Indicates whether the list of items (after applying the sort and filters, if any) @@ -870,7 +870,7 @@ namespace Avalonia.Collections /// /// Private accessor for the owning ICollectionView /// - private readonly ICollectionView _view; + private readonly IDataGridCollectionView _view; /// /// Raise this event when the (grouped) view changes @@ -887,7 +887,7 @@ namespace Avalonia.Collections /// /// CollectionView that contains this grouping /// True if items are already in correct order for grouping - internal CollectionViewGroupRoot(ICollectionView view, bool isDataInGroupOrder) + internal CollectionViewGroupRoot(IDataGridCollectionView view, bool isDataInGroupOrder) : base(RootName, null) { _view = view; @@ -897,7 +897,7 @@ namespace Avalonia.Collections /// /// Gets the description of grouping, indexed by level. /// - public virtual AvaloniaList GroupDescriptions => _groupBy; + public virtual AvaloniaList GroupDescriptions => _groupBy; /// /// 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 /// The level of grouping. /// Name of subgroup to add to /// Whether we are currently loading - 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 /// Group to add item to /// The level of grouping /// Whether we are currently loading - 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 GroupBySelector { get; set; } + public virtual Func GroupBySelector { get; set; } /// /// Returns the description of how to divide the given group into subgroups @@ -1153,9 +1153,9 @@ namespace Avalonia.Collections /// CollectionViewGroup to get group description from /// The level of grouping /// GroupDescription of how to divide the given group - 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 /// GroupDescription for the group /// The level of grouping /// Group names for the specified item - 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 /// Group to initialize /// The level of grouping /// The seed item to compare with to see where to insert - 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 /// Group to remove item from /// Item to remove /// True if item could not be removed - 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 /// The level of grouping /// Name of item to remove /// Return true if the item was not in one of the subgroups it was supposed to be. - 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 /// Group to remove item from /// The level of grouping /// Return true if the item was not in one of the subgroups it was supposed to be. - 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 /// /// Group to remove item from /// Item to remove - 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 /// /// TopLevelGroupDescription class /// - private class TopLevelGroupDescription : AvaloniaGroupDescription + private class TopLevelGroupDescription : DataGridGroupDescription { /// /// Initializes a new instance of the TopLevelGroupDescription class. diff --git a/src/Avalonia.Controls.DataGrid/Collections/AvaloniaSortDescription.cs b/src/Avalonia.Controls.DataGrid/Collections/DataGridSortDescription.cs similarity index 92% rename from src/Avalonia.Controls.DataGrid/Collections/AvaloniaSortDescription.cs rename to src/Avalonia.Controls.DataGrid/Collections/DataGridSortDescription.cs index d80cfa6a29..e6b604b75f 100644 --- a/src/Avalonia.Controls.DataGrid/Collections/AvaloniaSortDescription.cs +++ b/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 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(() => new CultureSensitiveComparer(culture ?? CultureInfo.CurrentCulture)); _comparer = new Lazy>(() => Comparer.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 + public class DataGridSortDescriptionCollection : AvaloniaList { } } diff --git a/src/Avalonia.Controls.DataGrid/Collections/ICollectionView.cs b/src/Avalonia.Controls.DataGrid/Collections/IDataGridCollectionView.cs similarity index 96% rename from src/Avalonia.Controls.DataGrid/Collections/ICollectionView.cs rename to src/Avalonia.Controls.DataGrid/Collections/IDataGridCollectionView.cs index c7241d7627..ab4c1383f9 100644 --- a/src/Avalonia.Controls.DataGrid/Collections/ICollectionView.cs +++ b/src/Avalonia.Controls.DataGrid/Collections/IDataGridCollectionView.cs @@ -13,20 +13,20 @@ using System.Text; namespace Avalonia.Collections { /// Provides data for the event. - public class CurrentChangingEventArgs : EventArgs + public class DataGridCurrentChangingEventArgs : EventArgs { private bool _cancel; private bool _isCancelable; /// Initializes a new instance of the class and sets the property to true. - public CurrentChangingEventArgs() + public DataGridCurrentChangingEventArgs() { Initialize(true); } /// Initializes a new instance of the class and sets the property to the specified value. /// true to disable the ability to cancel a change; false to enable cancellation. - public CurrentChangingEventArgs(bool isCancelable) + public DataGridCurrentChangingEventArgs(bool isCancelable) { Initialize(isCancelable); } @@ -66,7 +66,7 @@ namespace Avalonia.Collections } /// Enables collections to have the functionalities of current record management, custom sorting, filtering, and grouping. - public interface ICollectionView : IEnumerable, INotifyCollectionChanged + internal interface IDataGridCollectionView : IEnumerable, INotifyCollectionChanged { /// Gets or sets the cultural information for any operations of the view that may differ by culture, such as sorting. /// The culture information to use during culture-sensitive operations. @@ -91,7 +91,7 @@ namespace Avalonia.Collections /// Gets a collection of instances that describe how the items in the collection are sorted in the view. /// A collection of values that describe how the items in the collection are sorted in the view. - AvaloniaSortDescriptionCollection SortDescriptions { get; } + DataGridSortDescriptionCollection SortDescriptions { get; } /// Gets a value that indicates whether this view supports sorting by way of the property. /// true if this view supports sorting; otherwise, false. @@ -167,12 +167,12 @@ namespace Avalonia.Collections bool MoveCurrentToPosition(int position); /// Occurs before the current item changes. - event EventHandler CurrentChanging; + event EventHandler CurrentChanging; /// Occurs after the current item has been changed. event EventHandler CurrentChanged; } - public interface IEditableCollectionView + internal interface IDataGridEditableCollectionView { /// Gets a value that indicates whether a new item can be added to the collection. /// true if a new item can be added to the collection; otherwise, false. diff --git a/src/Avalonia.Controls.DataGrid/DataGrid.cs b/src/Avalonia.Controls.DataGrid/DataGrid.cs index 22c3578c80..1f57041001 100644 --- a/src/Avalonia.Controls.DataGrid/DataGrid.cs +++ b/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 /// item /// groupLevel /// The group the given item falls under or null if the item is not in the ItemsSource - public CollectionViewGroup GetGroupFromItem(object item, int groupLevel) + public DataGridCollectionViewGroup GetGroupFromItem(object item, int groupLevel) { int itemIndex = DataConnection.IndexOf(item); if (itemIndex == -1) diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs index c57f2b0296..168b455d4b 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs +++ b/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. /// - internal AvaloniaSortDescription GetSortDescription() + internal DataGridSortDescription GetSortDescription() { if (OwningGrid != null && OwningGrid.DataConnection != null diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs index abc2e681d6..a992f75c47 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs +++ b/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); } } diff --git a/src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs b/src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs index 12ef456aac..bfb2cf33b9 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs +++ b/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 /// True if a cancellation operation was invoked. public bool CancelEdit(object dataItem) { - IEditableCollectionView editableCollectionView = EditableCollectionView; + IDataGridEditableCollectionView editableCollectionView = EditableCollectionView; if (editableCollectionView != null) { if (editableCollectionView.CanCancelEdit) @@ -324,7 +324,7 @@ namespace Avalonia.Controls /// True if a commit operation was invoked. 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 /// /// Enumerable source for which to create a view /// ICollectionView view over the provided source - 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 && diff --git a/src/Avalonia.Controls.DataGrid/DataGridRowGroupInfo.cs b/src/Avalonia.Controls.DataGrid/DataGridRowGroupInfo.cs index 267f869f53..0ea30f314d 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRowGroupInfo.cs +++ b/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; diff --git a/src/Avalonia.Controls.DataGrid/DataGridRows.cs b/src/Avalonia.Controls.DataGrid/DataGridRows.cs index b4901a7619..072c1041b5 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRows.cs +++ b/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 /// /// CollectionViewGroup /// Set to true to collapse all Subgroups - 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 /// /// CollectionViewGroup /// Set to true to expand all Subgroups - 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); }