72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using Avalonia.Controls;
|
|
using ModpackUpdater.Apps.Manager.Api.Model;
|
|
using PropertyChanged;
|
|
|
|
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
|
|
|
public class MainWindowViewModel : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
private ObservableCollection<MainWindowTreeNode>? currentTreeNodes;
|
|
private ObservableCollection<MainWindowGridRow>? 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<MainWindowTreeNode>? 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<MainWindowGridRow>? 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;
|
|
}
|
|
}
|
|
} |