using System; using System.Collections.Generic; using System.Windows.Input; using CommunityToolkit.Mvvm.Input; using DynamicData.Binding; using JetBrains.Annotations; namespace StabilityMatrix.Avalonia.Models; [PublicAPI] public class SelectableItem(T item) : AbstractNotifyPropertyChanged, IEquatable> { public T Item { get; } = item; private bool _isSelected; public bool IsSelected { get => _isSelected; set => SetAndRaise(ref _isSelected, value); } public ICommand ToggleSelectedCommand => new RelayCommand(() => IsSelected = !IsSelected); /// public bool Equals(SelectableItem? other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return EqualityComparer.Default.Equals(Item, other.Item); } /// public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != GetType()) return false; return Equals((SelectableItem)obj); } /// public override int GetHashCode() { return HashCode.Combine(GetType().GetHashCode(), Item?.GetHashCode()); } }