-
Notifications
You must be signed in to change notification settings - Fork 690
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
v2 Fixes #2897. ListView ListWrapper - marking does work if you give an IList which in which the count changes #3510
Conversation
To test, you can copy and paste this code into a scenario. public override void Main ()
{
// Init
Application.Init ();
// Setup - Create a top-level application window and configure it.
Window appWindow = new ()
{
Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
};
var count = 0;
var source = new ObservableCollection<string> ();
var listView = new ListView
{
Width = 20,
Height = Dim.Fill (),
AllowsMarking = true,
AllowsMultipleSelection = true,
Source = new ListWrapper<string> (source)
};
appWindow.Add (listView);
var btnAdd = new Button
{
X = Pos.Center (),
Y = Pos.Center (),
Text = "_Add Item"
};
btnAdd.Accept += (s, e) =>
{
source.Add ($"Item{count}");
count++;
listView.MoveEnd ();
};
appWindow.Add (btnAdd);
var btnRemove = new Button
{
X = Pos.Center (),
Y = Pos.Center () + 1,
Text = "_Remove Item"
};
btnRemove.Accept += (s, e) =>
{
if (source.Count > 0 && listView.SelectedItem > -1)
{
source.Remove (source [listView.SelectedItem]);
}
};
appWindow.Add (btnRemove);
// Run - Start the application.
Application.Run (appWindow);
appWindow.Dispose ();
// Shutdown - Calling Application.Shutdown is required.
Application.Shutdown ();
} @tig the scrolling in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the thinking in this, but...
While ObservableCollection does make things a lot easier for us, it is now restricting users to use that type, specifically, which is non-ideal.
It's a nice thought to try to handle things automatically for the user, here, but they may not even need that behavior.
WPF doesn't force the use of ObservableCollection, but you still can use it, as the consumer, if you want to. But what if it's a huge collection or they just want to hook it up to their ORM of choice like EFCore? Now they have to copy to a new collection before feeding it to us.
For a Terminal.Gui case:
SnapsInAZfs uses views with various different collections, depending on what is appropriate at the time. At least one is an ObservableCollection, but others aren't, or there's even at least one that implements INotifyCollectionChanged itself, using a dictionary underneath, and providing the values to Terminal.Gui for rendering.
Basic point is we shouldn't be forcing users to use things like that which are fundamentally different types, while also not restricting them from doing so, if they want/need to.
Thus, use of IEnumerable<T>
or similar is likely to be the best for us to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed a multiple-subscription issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big performance hit here
…rce is null. For the ListWrapper the user is responsible to dispose it.
…sposing. ListView does it.
Fixes
Proposed Changes/Todos
Pull Request checklist:
CTRL-K-D
to automatically reformat your files before committing.dotnet test
before commit///
style comments)