Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[WIP] AdvancedCollectionViewSource #349

Merged
merged 20 commits into from Jan 11, 2017

Conversation

tomzorz
Copy link
Contributor

@tomzorz tomzorz commented Sep 18, 2016

This is a work in progress for issue #248

Right now I only did the suggested formattings to the original code.

Skipped for now:

  • grouping (I /* commented out */ the parts until we/I figure out how to proceed on this one)

Done:

  • filtering
  • sorting
  • selected value persists while using sort/filter
  • incremental item loading (inherited)
  • tests (maybe add more later)
  • sample

Edited: 2016.10.09., 2016.10.22., 2017.01.07.

@msftclas
Copy link

Hi @tomzorz, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

@msftclas
Copy link

@tomzorz, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, MSBOT;

@deltakosh
Copy link
Contributor

deltakosh commented Sep 19, 2016

This is REALLY cool. It is a big amount of work though. To all: Do not hesitate to use this issue (#248) to discuss about architecture or whatever else you may need.

@tomzorz
Copy link
Contributor Author

tomzorz commented Sep 19, 2016

Edited the original comment, I added the done section.

@tomzorz tomzorz changed the title AdvancedCollectionViewSource WIP [WIP] AdvancedCollectionViewSource Sep 19, 2016
@deltakosh deltakosh added this to the v1.2 milestone Sep 26, 2016
using Windows.Foundation.Collections;
using Windows.UI.Xaml.Data;

namespace Microsoft.Toolkit.Uwp.UI.Controls.AdvancedCollectionViewSource
Copy link
Contributor

Choose a reason for hiding this comment

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

I should not be in its own namespace

Copy link
Contributor

Choose a reason for hiding this comment

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

....nor in a UI.Controls namespace since it's neither

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. The built-in one is in .Xaml.Data - https://msdn.microsoft.com/library/windows/apps/br209833?f=255&MSPPError=-2147217396 - I'd move it to the .UI project under the Data namespace based on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

.UI should be enough (no need for .Data)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it.

HandleSourceChanged();
}

public IEnumerator<object> GetEnumerator() => _view.GetEnumerator();
Copy link
Contributor

Choose a reason for hiding this comment

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

Properties order is not aligned to Stylecop checks here (You must have warnings for that when compiling)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@dotMorten dotMorten left a comment

Choose a reason for hiding this comment

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

Did a quick little initial review

using Windows.Foundation.Collections;
using Windows.UI.Xaml.Data;

namespace Microsoft.Toolkit.Uwp.UI.Controls.AdvancedCollectionViewSource
Copy link
Contributor

Choose a reason for hiding this comment

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

....nor in a UI.Controls namespace since it's neither

return;
}

CurrentChanging?.Invoke(this, e);
Copy link
Contributor

@dotMorten dotMorten Oct 6, 2016

Choose a reason for hiding this comment

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

Is this event needed? Wouldn't it be better to have oldValue and newValue in the event arguments of the CurrentChanged event?

Also why virtual? If the intent is to subclass and ovewrite this event to handle when the item is changing, generally this should be an empty method to override, so the content of this code still executes if the subclass doesn't call base.OnCurrentChanging (same for OnCurrentChanged and OnVectorChanged)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this event needed? Wouldn't it be better to have oldValue and newValue in the event arguments of the CurrentChanged event?

The implementations are this way because of ICollectionView's requirements. (They are only used for the defer notifications part.)

Also why virtual?

True. Removed virtual, and made it private.

_sourceNcc = _source as INotifyCollectionChanged;
if (_sourceNcc != null)
{
_sourceNcc.CollectionChanged += _sourceNcc_CollectionChanged;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be a weak listener

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is now.

MoveCurrentTo(currentItem);
}

private void _sourceNcc_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the naming of this method creating a warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also fixed.

switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
if (e.NewItems.Count == 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

NewItems could be null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

/// </summary>
/// <param name="item">item</param>
/// <returns>success of operation</returns>
public bool MoveCurrentTo(object item) => item == CurrentItem || MoveCurrentToIndex(IndexOf(item));
Copy link
Contributor

@dotMorten dotMorten Oct 6, 2016

Choose a reason for hiding this comment

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

Why have this when you already have the CurrentItem property that is get and set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ICollectionView implementation.

/// <exception cref="NotImplementedException">Not implemented yet...</exception>
public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
{
throw new NotImplementedException("todo...");
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to be completed. I assume it's just a matter of checking if the source implements ISupportIncrementalLoading and call LoadMoreItemsAsync on that ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

/// <summary>
/// Gets a value indicating whether the source has more items
/// </summary>
public bool HasMoreItems => false; // todo
Copy link
Contributor

@dotMorten dotMorten Oct 6, 2016

Choose a reason for hiding this comment

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

Isn't this just:

public bool HasMoreItems => (_source as ISupportIncrementalLoading)?.HasMoreItems ?? false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it is - added.

/// <summary>
/// Occurs when the vector changes.
/// </summary>
public event VectorChangedEventHandler<object> VectorChanged;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not INotifyCollectionChanged instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is required IObservableVector implementation.

/// <summary>
/// Vector changed EventArgs
/// </summary>
public class VectorChangedEventArgs : IVectorChangedEventArgs
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this class can be kept internal. It's enough to have IVectorChangedEventArgs public which is already part of WinRT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@tomzorz
Copy link
Contributor Author

tomzorz commented Oct 8, 2016

Thanks for the reviews - I'll try to work on the issues this weekend.

@tomzorz
Copy link
Contributor Author

tomzorz commented Oct 9, 2016

Aaand, third time's the charm :) I left some questions above before proceeding with certain fixes.

@deltakosh
Copy link
Contributor

This is really good work! It 's gonna be a truly awesome addition to the toolkit

@deltakosh
Copy link
Contributor

Hey! How things are going here?

@tomzorz
Copy link
Contributor Author

tomzorz commented Oct 19, 2016

@deltakosh got an exam tomorrow - I'm planning on finishing the remaining issues later this week :)

@deltakosh
Copy link
Contributor

Ouch!! good luck :)

@deltakosh
Copy link
Contributor

Ok keep me posted. There is no problem to flag it for 1.3

@tomzorz
Copy link
Contributor Author

tomzorz commented Nov 1, 2016

@deltakosh Let's flag it for 1.3 - I want to do this right, but I don't have time for right until 1.2 :D (maybe I'll have some down time during the summit)

@deltakosh
Copy link
Contributor

Completely aligned!

@deltakosh deltakosh modified the milestones: v1.3, v1.2 Nov 1, 2016
@tomzorz
Copy link
Contributor Author

tomzorz commented Dec 2, 2016

I haven't forgot about the PR - definitely planning on to finish it before 1.3 :)

@deltakosh
Copy link
Contributor

OK thanks:)

/// <summary>
/// Extended ICollectionView with filtering and sorting
/// </summary>
public interface ICollectionViewEx : ICollectionView

Choose a reason for hiding this comment

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

Why not call it "IAdvancedCollectionView" to match the class name.
Or "ICollectionViewSource" if the class name is named "CollectionViewSource"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'll do that.

/// <summary>
/// Gets or sets the predicate used to filter the visisble items
/// </summary>
public Predicate<object> Filter

Choose a reason for hiding this comment

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

I think we have to create a delegate type rather than use Predicate.
If we want to add new behavior on the filtering it will be easy without make breaking changes.
In the Silverlight implementation of CollectionViewSource they create a delegate called FilterEventHandler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd personally go with the functional-ish/linq-ish style of the predicate, rather than have events instead. Also we can always ease-in breaking changes by marking things obsolete first. But I guess this is open for discussion.

@jgiacomini
Copy link

Very good work. I cant wait to have it in the toolkit. :)

bool CanFilter { get; }

/// <summary>
/// Gets or sets the predicate used to filter the visisble items

Choose a reason for hiding this comment

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

In the summary block => "visisble" must be "visible"

@deltakosh
Copy link
Contributor

Up? :) and Happy new year 💃

@tomzorz
Copy link
Contributor Author

tomzorz commented Jan 3, 2017

@deltakosh Yes! Sorry, planning on wrapping it up this weekend.

@deltakosh
Copy link
Contributor

You rock!

@tomzorz
Copy link
Contributor Author

tomzorz commented Jan 7, 2017

So theoretically this is it, pinging @deltakosh for a final re-check.

/// <summary>
/// Sort description
/// </summary>
public class SortDescription
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have you named it SortDescription ? shouldn't it be SortDirection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not just a direction - it describes a sorting step: a property to sort on plus the direction. So you can have more of these, and for example it'll sort by prop A asc, then by prob B desc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Whilst its specifying a sort, calling it a SortDescription is misleading. I think you should call it SortDirection, SortEntry or something else. yes I get that you can add more than one

Copy link
Contributor Author

@tomzorz tomzorz Jan 8, 2017

Choose a reason for hiding this comment

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

Maybe SortLevel, to match the phrasing that Excel uses?

Copy link
Contributor

@deltakosh deltakosh Jan 10, 2017

Choose a reason for hiding this comment

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

I'm for SortDescription actually. It makes sense to me

@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should not be in the repo

@@ -273,7 +273,7 @@
<CodeAnalysisRuleSet>microsoft.toolkit.uwp.ui.controls.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Copy link
Contributor

Choose a reason for hiding this comment

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

not necessary update ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah, apparently VS was automatically removing that space from the end of the line any time I saved... had to edit it back in VSCode :)

Copy link
Contributor

@deltakosh deltakosh left a comment

Choose a reason for hiding this comment

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

Small changes only..Really good job

@tomzorz
Copy link
Contributor Author

tomzorz commented Jan 10, 2017

@deltakosh done :) Thanks!

@deltakosh
Copy link
Contributor

@dotMorten @hermitdave Fancy doing a second check? Thanks!

@hermitdave
Copy link
Contributor

@deltakosh I already went through the code.. I don't see any significant changes since then.. maybe @dotMorten can take a look.. good from my side

@deltakosh
Copy link
Contributor

Do you mind flagging it as approved?

@hermitdave hermitdave merged commit 1d409d4 into CommunityToolkit:dev Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants