a lot of work
This commit is contained in:
@@ -1,176 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
||||
|
||||
public class InstallActionViewModel(InstallAction action, IActionSet baseActions) : INotifyPropertyChanged
|
||||
{
|
||||
#region Implementation of INotifyPropertyChanged
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
#endregion Implementation of INotifyPropertyChanged
|
||||
|
||||
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 string InheritedId => action is UpdateAction ua && !string.IsNullOrWhiteSpace(ua.InheritFrom) ? ua.InheritFrom : action.Id;
|
||||
public string InheritedSide => Sides[Inherited.Side];
|
||||
public string InheritedUpdateType => action is UpdateAction ua ? UpdateActionTypes[ua.Type] : string.Empty;
|
||||
public string InheritedSourceType => SourceTypes[Inherited.SourceType];
|
||||
public string InheritedDestPath => Inherited.DestPath;
|
||||
|
||||
public string Id
|
||||
{
|
||||
get => action.Id;
|
||||
set
|
||||
{
|
||||
action.Id = value;
|
||||
OnPropertyChanged(nameof(InheritedId));
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => action.Name;
|
||||
set => action.Name = value;
|
||||
}
|
||||
|
||||
public string Website
|
||||
{
|
||||
get => action.Website;
|
||||
set => action.Website = value;
|
||||
}
|
||||
|
||||
public bool IsZip
|
||||
{
|
||||
get => action.IsZip;
|
||||
set => action.IsZip = value;
|
||||
}
|
||||
|
||||
public string ZipPath
|
||||
{
|
||||
get => action.ZipPath;
|
||||
set => action.ZipPath = value;
|
||||
}
|
||||
|
||||
public string DestPath
|
||||
{
|
||||
get => action.DestPath;
|
||||
set
|
||||
{
|
||||
action.DestPath = value;
|
||||
OnPropertyChanged(nameof(InheritedDestPath));
|
||||
}
|
||||
}
|
||||
|
||||
public string SourceUrl
|
||||
{
|
||||
get => action.SourceUrl;
|
||||
set => action.SourceUrl = value;
|
||||
}
|
||||
|
||||
public SourceType SourceType
|
||||
{
|
||||
get => action.SourceType;
|
||||
set
|
||||
{
|
||||
action.SourceType = value;
|
||||
OnPropertyChanged(nameof(InheritedSourceType));
|
||||
}
|
||||
}
|
||||
|
||||
public string SourceOwner
|
||||
{
|
||||
get => action.SourceOwner;
|
||||
set => action.SourceOwner = value;
|
||||
}
|
||||
|
||||
public string SourceName
|
||||
{
|
||||
get => action.SourceName;
|
||||
set => action.SourceName = value;
|
||||
}
|
||||
|
||||
public string SourceRegex
|
||||
{
|
||||
get => action.SourceRegex;
|
||||
set => action.SourceRegex = value;
|
||||
}
|
||||
|
||||
public string SourceTag
|
||||
{
|
||||
get => action.SourceTag;
|
||||
set => action.SourceTag = value;
|
||||
}
|
||||
|
||||
public Side Side
|
||||
{
|
||||
get => action.Side;
|
||||
set
|
||||
{
|
||||
action.Side = value;
|
||||
OnPropertyChanged(nameof(InheritedSide));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsExtra
|
||||
{
|
||||
get => action.IsExtra;
|
||||
set => action.IsExtra = value;
|
||||
}
|
||||
|
||||
public UpdateActionType Type
|
||||
{
|
||||
get => action is UpdateAction ua ? ua.Type : default;
|
||||
set
|
||||
{
|
||||
if (action is UpdateAction ua)
|
||||
ua.Type = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string SrcPath
|
||||
{
|
||||
get => action is UpdateAction ua ? ua.SrcPath : string.Empty;
|
||||
set
|
||||
{
|
||||
if (action is UpdateAction ua)
|
||||
ua.SrcPath = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDirectory
|
||||
{
|
||||
get => action is UpdateAction ua && ua.IsDirectory;
|
||||
set
|
||||
{
|
||||
if (action is UpdateAction ua)
|
||||
ua.IsDirectory = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string InheritFrom
|
||||
{
|
||||
get => action is UpdateAction ua ? ua.InheritFrom : string.Empty;
|
||||
set
|
||||
{
|
||||
if (action is UpdateAction ua)
|
||||
ua.InheritFrom = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(InheritedId));
|
||||
}
|
||||
}
|
||||
}
|
||||
232
ModpackUpdater.Apps.Manager/Ui/Models/MainWindowGridRow.cs
Normal file
232
ModpackUpdater.Apps.Manager/Ui/Models/MainWindowGridRow.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using System.ComponentModel;
|
||||
using ModpackUpdater.Apps.Manager.Utils;
|
||||
using PropertyChanged;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
||||
|
||||
public class MainWindowGridRow : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
private string? actionId;
|
||||
private string? actionName;
|
||||
private string? actionWebsite;
|
||||
private string? actionZipPath;
|
||||
private string? actionDestPath;
|
||||
private string? actionSourceUrl;
|
||||
private string? actionSourceOwner;
|
||||
private string? actionSourceName;
|
||||
private string? actionSourceRegEx;
|
||||
private string? actionSourceTag;
|
||||
private string? actionSrcPath;
|
||||
private string? actionInheritFrom;
|
||||
private readonly InstallAction action;
|
||||
private readonly IActionSet baseActions;
|
||||
|
||||
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 == actionInheritFrom) : 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(actionInheritFrom) ? actionInheritFrom : actionId;
|
||||
[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 => Base != null ? Base.DestPath : actionDestPath;
|
||||
|
||||
public MainWindowGridRow(InstallAction action, IActionSet baseActions)
|
||||
{
|
||||
this.action = action;
|
||||
this.baseActions = baseActions;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
public void Invalidate()
|
||||
{
|
||||
actionId = action.Id;
|
||||
actionName = action.Name;
|
||||
actionWebsite = action.Website;
|
||||
actionZipPath = action.ZipPath;
|
||||
actionDestPath = action.DestPath;
|
||||
actionSourceUrl = action.SourceUrl;
|
||||
actionSourceOwner = action.SourceOwner;
|
||||
actionSourceName = action.SourceName;
|
||||
actionSourceRegEx = action.SourceRegex;
|
||||
actionSourceTag = action.SourceTag;
|
||||
actionSrcPath = (action as UpdateAction)?.SrcPath;
|
||||
actionInheritFrom = (action as UpdateAction)?.InheritFrom;
|
||||
}
|
||||
|
||||
public string? Id
|
||||
{
|
||||
get => action.Id;
|
||||
set => action.Id = (actionId = value)?.Trim().Nullify();
|
||||
}
|
||||
|
||||
public string? Name
|
||||
{
|
||||
get => actionName;
|
||||
set
|
||||
{
|
||||
actionName = value;
|
||||
action.Name = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? Website
|
||||
{
|
||||
get => actionWebsite;
|
||||
set
|
||||
{
|
||||
actionWebsite = value;
|
||||
action.Website = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsZip
|
||||
{
|
||||
get => action.IsZip;
|
||||
set => action.IsZip = value;
|
||||
}
|
||||
|
||||
public string? ZipPath
|
||||
{
|
||||
get => actionZipPath;
|
||||
set
|
||||
{
|
||||
actionZipPath = value;
|
||||
action.ZipPath = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? DestPath
|
||||
{
|
||||
get => actionDestPath;
|
||||
set
|
||||
{
|
||||
actionDestPath = value;
|
||||
action.DestPath = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? SourceUrl
|
||||
{
|
||||
get => actionSourceUrl;
|
||||
set
|
||||
{
|
||||
actionSourceUrl = value;
|
||||
action.SourceUrl = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public SourceType SourceType
|
||||
{
|
||||
get => action.SourceType;
|
||||
set => action.SourceType = value;
|
||||
}
|
||||
|
||||
public string? SourceOwner
|
||||
{
|
||||
get => actionSourceOwner;
|
||||
set
|
||||
{
|
||||
actionSourceOwner = value;
|
||||
action.SourceOwner = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? SourceName
|
||||
{
|
||||
get => actionSourceName;
|
||||
set
|
||||
{
|
||||
actionSourceName = value;
|
||||
action.SourceName = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? SourceRegex
|
||||
{
|
||||
get => actionSourceRegEx;
|
||||
set
|
||||
{
|
||||
actionSourceRegEx = value;
|
||||
action.SourceRegex = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? SourceTag
|
||||
{
|
||||
get => actionSourceTag;
|
||||
set
|
||||
{
|
||||
actionSourceTag = value;
|
||||
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 => actionSrcPath;
|
||||
set
|
||||
{
|
||||
actionSrcPath = value;
|
||||
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 => actionInheritFrom;
|
||||
set
|
||||
{
|
||||
actionInheritFrom = value;
|
||||
if (action is UpdateAction ua)
|
||||
ua.InheritFrom = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using ModpackUpdater.Apps.Manager.Api.Model;
|
||||
using ModpackUpdater.Apps.Manager.Api.Plugins.Features;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
||||
|
||||
public record class MainWindowRecentFilesItem(WorkspaceConfig Config, WorkspaceFeature Feature);
|
||||
57
ModpackUpdater.Apps.Manager/Ui/Models/MainWindowTreeNode.cs
Normal file
57
ModpackUpdater.Apps.Manager/Ui/Models/MainWindowTreeNode.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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(editVersion = value, out var v) ? v : new();
|
||||
}
|
||||
|
||||
[AlsoNotifyFor(nameof(Image))]
|
||||
public bool IsPublic
|
||||
{
|
||||
get => infos.IsPublic;
|
||||
set => infos.IsPublic = value;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,72 @@
|
||||
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
|
||||
{
|
||||
#region Implementation of INotifyPropertyChanged
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
#endregion Implementation of INotifyPropertyChanged
|
||||
|
||||
public bool IsUpdate { get; set; }
|
||||
|
||||
public List<InstallActionViewModel> Actions { get; } = [];
|
||||
|
||||
public InstallActionViewModel? SelectedAction { get; set; }
|
||||
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
|
||||
{
|
||||
currentWorkspace = value;
|
||||
currentTreeNodes = null;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
selectedTreeNode = value;
|
||||
currentGridRows = null;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user