using System.Collections.ObjectModel; using System.ComponentModel; using ModpackUpdater.Apps.Manager.Api.Model; using PropertyChanged; namespace ModpackUpdater.Apps.Manager.Ui.Models.MainWindow; public class MainWindowViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler? PropertyChanged; private ObservableCollection? currentTreeNodes; private ObservableCollection? currentGridRows; private MainWindowTreeNode? selectedTreeNode; private IWorkspace? currentWorkspace; public bool IsUpdate => selectedTreeNode is ActionSetTreeNode node && node.Infos is UpdateInfo; public MainWindowGridRow? SelectedGridRow { get; set; } [AlsoNotifyFor(nameof(CurrentTreeNodes))] public IWorkspace? CurrentWorkspace { get => currentWorkspace; set { currentTreeNodes = null; currentWorkspace = value; } } public ObservableCollection? CurrentTreeNodes { get { if (currentTreeNodes == null && currentWorkspace?.InstallInfos != null && currentWorkspace?.UpdateInfos != null) currentTreeNodes = [ new ActionSetTreeNode(currentWorkspace.InstallInfos), new SimpleMainWindowTreeNode("Updates") { Image = AppGlobals.Symbols.GetImageSource(AppSymbols.update_done), Nodes = [.. currentWorkspace.UpdateInfos.Updates.Select(n => new ActionSetTreeNode(n))], }, ]; return currentTreeNodes; } } [AlsoNotifyFor(nameof(CurrentGridRows))] public MainWindowTreeNode? SelectedTreeNode { get => selectedTreeNode; set { currentGridRows = null; selectedTreeNode = value; } } public ObservableCollection? CurrentGridRows { get { if (currentGridRows == null && CurrentWorkspace?.InstallInfos != null && selectedTreeNode is ActionSetTreeNode node) currentGridRows = [.. node.Infos.Actions.Select(n => new MainWindowGridRow(n, CurrentWorkspace.InstallInfos))]; return currentGridRows; } } }