61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using Avalonia.Media;
|
|
using PropertyChanged;
|
|
|
|
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
|
|
|
public abstract class MainWindowTreeNode : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
public abstract string DisplayText { get; }
|
|
public virtual IImage? Image { get; set; }
|
|
public ObservableCollection<MainWindowTreeNode> Nodes { get; init; } = [];
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
|
{
|
|
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
|
|
field = value;
|
|
OnPropertyChanged(propertyName);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public class SimpleMainWindowTreeNode(string text) : MainWindowTreeNode
|
|
{
|
|
public override string DisplayText => text;
|
|
}
|
|
|
|
public class ActionSetTreeNode(IActionSetInfos infos) : MainWindowTreeNode
|
|
{
|
|
private string editVersion = infos.Version.ToString();
|
|
|
|
public override string DisplayText => infos.Version.ToString();
|
|
public IActionSetInfos Infos => infos;
|
|
public override IImage? Image => AppGlobals.Symbols.GetImageSource(infos.IsPublic ? AppSymbols.eye : AppSymbols.invisible);
|
|
|
|
[AlsoNotifyFor(nameof(DisplayText))]
|
|
public string Version
|
|
{
|
|
get => editVersion;
|
|
set
|
|
{
|
|
infos.Version = System.Version.TryParse(value, out var v) ? v : new();
|
|
editVersion = value;
|
|
}
|
|
}
|
|
|
|
[AlsoNotifyFor(nameof(Image))]
|
|
public bool IsPublic
|
|
{
|
|
get => infos.IsPublic;
|
|
set => infos.IsPublic = value;
|
|
}
|
|
} |