You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
10 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Windows.Input;
|
||
|
using CommunityToolkit.Mvvm.Input;
|
||
11 months ago
|
using DynamicData.Binding;
|
||
|
using JetBrains.Annotations;
|
||
|
|
||
10 months ago
|
namespace StabilityMatrix.Avalonia.Models;
|
||
11 months ago
|
|
||
|
[PublicAPI]
|
||
|
public class SelectableItem<T>(T item) : AbstractNotifyPropertyChanged, IEquatable<SelectableItem<T>>
|
||
|
{
|
||
|
public T Item { get; } = item;
|
||
|
|
||
|
private bool _isSelected;
|
||
|
|
||
|
public bool IsSelected
|
||
|
{
|
||
|
get => _isSelected;
|
||
|
set => SetAndRaise(ref _isSelected, value);
|
||
|
}
|
||
|
|
||
10 months ago
|
public ICommand ToggleSelectedCommand => new RelayCommand(() => IsSelected = !IsSelected);
|
||
|
|
||
11 months ago
|
/// <inheritdoc />
|
||
|
public bool Equals(SelectableItem<T>? other)
|
||
|
{
|
||
|
if (ReferenceEquals(null, other))
|
||
|
return false;
|
||
|
if (ReferenceEquals(this, other))
|
||
|
return true;
|
||
|
return EqualityComparer<T>.Default.Equals(Item, other.Item);
|
||
|
}
|
||
|
|
||
|
/// <inheritdoc />
|
||
|
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<T>)obj);
|
||
|
}
|
||
|
|
||
|
/// <inheritdoc />
|
||
|
public override int GetHashCode()
|
||
|
{
|
||
|
return HashCode.Combine(GetType().GetHashCode(), Item?.GetHashCode());
|
||
|
}
|
||
|
}
|