This commit is contained in:
2025-11-17 07:19:43 +01:00
parent 72a81e05ad
commit e584996043
29 changed files with 134 additions and 668 deletions

View File

@@ -0,0 +1,156 @@
using System.ComponentModel;
using ModpackUpdater.Apps.Manager.Utils;
using PropertyChanged;
namespace ModpackUpdater.Apps.Manager.Ui.Models.MainWindow;
public class MainWindowGridRow(InstallAction action, IActionSet baseActions) : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
public static Dictionary<SourceType, string> SourceTypes { get; } = Enum.GetValues<SourceType>().ToDictionary(n => n, n => Enum.GetName(n)!);
public static Dictionary<Side, string> Sides { get; } = Enum.GetValues<Side>().ToDictionary(n => n, n => Enum.GetName(n)!);
public static Dictionary<UpdateActionType, string> UpdateActionTypes { get; } = Enum.GetValues<UpdateActionType>().ToDictionary(n => n, n => Enum.GetName(n)!);
public InstallAction Action => action;
private InstallAction? Base => action is UpdateAction ua ? baseActions.Actions.FirstOrDefault(n => n.Id == ua.InheritFrom) : null;
private InstallAction Inherited => Base ?? action;
public bool IsUpdate => action is UpdateAction;
public bool? IsValid { get; set; } = null;
[DependsOn(nameof(Id), nameof(InheritFrom))]
public string? InheritedId => action is UpdateAction ua && !string.IsNullOrWhiteSpace(ua.InheritFrom) ? ua.InheritFrom : action.Id;
[DependsOn(nameof(Side), nameof(InheritedId), nameof(Id))]
public string InheritedSide => Sides[Inherited.Side];
[DependsOn(nameof(UpdateType), nameof(InheritedId), nameof(Id))]
public string InheritedUpdateType => action is UpdateAction ua ? UpdateActionTypes[ua.Type] : string.Empty;
[DependsOn(nameof(SourceType), nameof(InheritedId), nameof(Id))]
public string InheritedSourceType => SourceTypes[Inherited.SourceType];
[DependsOn(nameof(DestPath), nameof(InheritedId), nameof(Id))]
public string? InheritedDestPath => Inherited.DestPath;
public string? Id
{
get => action.Id;
set => action.Id = value?.Trim().Nullify();
}
public string? Name
{
get => action.Name;
set => action.Name = value?.Trim().Nullify();
}
public string? Website
{
get => action.Website;
set => action.Website = value?.Trim().Nullify();
}
public bool IsZip
{
get => action.IsZip;
set => action.IsZip = value;
}
public string? ZipPath
{
get => action.ZipPath;
set => action.ZipPath = value?.Trim().Nullify();
}
public string? DestPath
{
get => action.DestPath;
set => action.DestPath = value?.Trim().Nullify();
}
public string? SourceUrl
{
get => action.SourceUrl;
set => action.SourceUrl = value?.Trim().Nullify();
}
public SourceType SourceType
{
get => action.SourceType;
set => action.SourceType = value;
}
public string? SourceOwner
{
get => action.SourceOwner;
set => action.SourceOwner = value?.Trim().Nullify();
}
public string? SourceName
{
get => action.SourceName;
set => action.SourceName = value?.Trim().Nullify();
}
public string? SourceRegex
{
get => action.SourceRegex;
set => action.SourceRegex = value?.Trim().Nullify();
}
public string? SourceTag
{
get => action.SourceTag;
set => action.SourceTag = value?.Trim().Nullify();
}
public Side Side
{
get => action.Side;
set => action.Side = value;
}
public bool IsExtra
{
get => action.IsExtra;
set => action.IsExtra = value;
}
public UpdateActionType UpdateType
{
get => action is UpdateAction ua ? ua.Type : default;
set
{
if (action is UpdateAction ua)
ua.Type = value;
}
}
public string? SrcPath
{
get => (action as UpdateAction)?.SrcPath;
set
{
if (action is UpdateAction ua)
ua.SrcPath = value?.Trim().Nullify();
}
}
public bool IsDirectory
{
get => action is UpdateAction ua && ua.IsDirectory;
set
{
if (action is UpdateAction ua)
ua.IsDirectory = value;
}
}
public string? InheritFrom
{
get => (action as UpdateAction)?.InheritFrom;
set
{
if (action is UpdateAction ua)
ua.InheritFrom = value?.Trim().Nullify();
}
}
}

View File

@@ -0,0 +1,6 @@
using ModpackUpdater.Apps.Manager.Api.Model;
using ModpackUpdater.Apps.Manager.Api.Plugins.Features;
namespace ModpackUpdater.Apps.Manager.Ui.Models.MainWindow;
public record class MainWindowRecentFilesItem(WorkspaceConfig Config, WorkspaceFeature Feature);

View File

@@ -0,0 +1,61 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Avalonia.Media;
using PropertyChanged;
namespace ModpackUpdater.Apps.Manager.Ui.Models.MainWindow;
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() ?? string.Empty;
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;
}
}

View File

@@ -0,0 +1,70 @@
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<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;
}
}
}