diff --git a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs index d9072cc..c86be1c 100644 --- a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs +++ b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs @@ -24,10 +24,8 @@ internal static class SharedFunctions var rowsCount = rows.Length; var failed = false; var factory = new ModpackFactory(); - - api.Model.Progress.Value = 0; - api.Model.Progress.MaxValue = rowsCount; - api.Model.Progress.Visible = true; + + api.Model.Progress.Start(rowsCount); for (var i = 0; i < rowsCount; i++) { @@ -50,10 +48,10 @@ internal static class SharedFunctions return; row.StateImage = failed ? imageSourceFailed : imageSourceSuccess; - api.Model.Progress.Value = i; + api.Model.Progress.Set(i); } - api.Model.Progress.Visible = false; + api.Model.Progress.End(); } public static async Task CollectUpdates(IMainApi api, params InstallAction[] actions) @@ -100,9 +98,7 @@ internal static class SharedFunctions { var factory = new ModpackFactory(); - api.Model.Progress.Value = 0; - api.Model.Progress.MaxValue = rows.Length; - api.Model.Progress.Visible = true; + api.Model.Progress.Start(rows.Length); for (var i = 0; i < rows.Length; i++) { @@ -123,17 +119,15 @@ internal static class SharedFunctions if (api.HasClosed) return; - api.Model.Progress.Value = i; + api.Model.Progress.Set(i); } - api.Model.Progress.Visible = false; + api.Model.Progress.End(); } public static void ClearDirectLinks(IMainApi api, params MainWindowGridRow[] rows) { - api.Model.Progress.Value = 0; - api.Model.Progress.MaxValue = rows.Length; - api.Model.Progress.Visible = true; + api.Model.Progress.Start(rows.Length); for (var i = 0; i < rows.Length; i++) { @@ -141,10 +135,10 @@ internal static class SharedFunctions if (row.SourceType != SourceType.DirectLink) row.SourceUrl = null; row.StateImage = null; - api.Model.Progress.Value = i; + api.Model.Progress.Set(i); } - api.Model.Progress.Visible = false; + api.Model.Progress.End(); } public static string GenerateChangelog(InstallInfos installInfos, UpdateInfo updateInfos) diff --git a/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml b/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml index 9c3c585..7c8c1e3 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml +++ b/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml @@ -39,8 +39,8 @@ - - + + @@ -154,26 +154,15 @@ - - + - - - - - - - + Maximum="{Binding Progress.MaxValue}" + Value="{Binding Progress.Value}" + ShowProgressText="{Binding Progress.ShowText}" + IsIndeterminate="{Binding Progress.IsGeneric}" + IsVisible="{Binding Progress.IsVisible}"/> diff --git a/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml.cs b/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml.cs index fe11d55..c93aced 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml.cs +++ b/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml.cs @@ -1,5 +1,4 @@ using Avalonia.Controls; -using Avalonia.Data; using Avalonia.Interactivity; using Avalonia.Media; using ModpackUpdater.Apps.Manager.Api; @@ -7,7 +6,6 @@ using ModpackUpdater.Apps.Manager.Api.Model; using ModpackUpdater.Apps.Manager.Api.Plugins.Features; using ModpackUpdater.Apps.Manager.Api.Plugins.Params; using ModpackUpdater.Apps.Manager.Settings; -using ModpackUpdater.Apps.Manager.Ui.Models; using ModpackUpdater.Apps.Manager.Ui.Models.MainWindow; using Pilz.Features; using Pilz.UI.AvaloniaUI.Features; @@ -19,6 +17,8 @@ public partial class MainWindow : Window, IMainApi { public static IImage? ButtonImageAddAction => AppGlobals.Symbols.GetImageSource(AppSymbols.add); public static IImage? ButtonImageRemoveAction => AppGlobals.Symbols.GetImageSource(AppSymbols.remove); + + private WorkspaceFeature? curWs; public MainWindowViewModel Model { get; } = new(); Window IMainApi.MainWindow => this; @@ -57,19 +57,19 @@ public partial class MainWindow : Window, IMainApi insertPrioSplitters: true); } - private async Task LoadNewWorkspace(IWorkspace? workspace) + private async Task LoadNewWorkspace(IWorkspace? workspace, WorkspaceFeature feature) { if (workspace is null) return; if (!await workspace.Load()) - { - // Error return; - } if (workspace != Model.CurrentWorkspace) + { Model.CurrentWorkspace = workspace; + curWs = feature; + } AddToRecentFiles(workspace); LoadRecentWorkspaces(); @@ -124,14 +124,33 @@ public partial class MainWindow : Window, IMainApi var context = new WorkspaceContext(MainApi, null); await feature.Configure(context); - if (context.Workspace != null) - await LoadNewWorkspace(context.Workspace); + await LoadNewWorkspace(context.Workspace, feature); + } + + private async void MenuItemWorkspacePreferences_OnClick(object? sender, RoutedEventArgs e) + { + if (curWs is null || Model.CurrentWorkspace is null) + return; + + var context = new WorkspaceContext(MainApi, Model.CurrentWorkspace); + await curWs.Configure(context); + await LoadNewWorkspace(context.Workspace, curWs); + } + + private async void MenuItemSaveWorkspace_OnClick(object? sender, RoutedEventArgs e) + { + if (Model.CurrentWorkspace is not { } ws) + return; + + Model.Progress.Start(); + await ws.Save(); + Model.Progress.End(); } private async void MenuItemRecentWorkspaceItem_Click(object? sender, RoutedEventArgs e) { if (sender is MenuItem item && item.DataContext is MainWindowRecentFilesItem tag && tag.Feature.CreateFromConfig(tag.Config) is IWorkspace workspace) - await LoadNewWorkspace(workspace); + await LoadNewWorkspace(workspace, tag.Feature); } private void MenuItemToolsItem_Click(object? sender, RoutedEventArgs e) diff --git a/ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs b/ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs index 91866ce..d4a6b95 100644 --- a/ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs +++ b/ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using PropertyChanged; namespace ModpackUpdater.Apps.Manager.Ui.Models; @@ -7,9 +6,43 @@ public class ProgressInfos : INotifyPropertyChanged { public event PropertyChangedEventHandler? PropertyChanged; - public bool Visible { get; set; } + public bool IsVisible { get; set; } + public bool IsGeneric { get; set; } + public bool ShowText { get; set; } public double MaxValue { get; set; } public double Value { get; set; } - [DependsOn(nameof(Value), nameof(MaxValue))] - public string? Text => $"{Math.Round(Value / MaxValue * 100)}%"; + + public void Start(int maxValue) + { + IsGeneric = false; + Value = 0; + MaxValue = maxValue; + ShowText = true; + IsVisible = true; + } + + public void Start() + { + ShowText = false; + IsGeneric = true; + IsVisible = true; + } + + public void Set(int value) + { + if (!IsGeneric) + Value = value; + } + + public void Increment() + { + if (!IsGeneric) + Value += 1; + } + + public void End() + { + IsVisible = false; + IsGeneric = false; + } } \ No newline at end of file diff --git a/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml index c818977..c95f240 100644 --- a/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml +++ b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml @@ -82,23 +82,15 @@ - + - - - - - - - + Maximum="{Binding Progress.MaxValue}" + Value="{Binding Progress.Value}" + ShowProgressText="{Binding Progress.ShowText}" + IsIndeterminate="{Binding Progress.IsGeneric}" + IsVisible="{Binding Progress.IsVisible}"/> \ No newline at end of file diff --git a/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml.cs b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml.cs index 9972ef1..3a28e03 100644 --- a/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml.cs +++ b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml.cs @@ -25,15 +25,13 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase private async Task FindUpdates() { - Model.Progress.Value = 0; - Model.Progress.MaxValue = actions.Length; - Model.Progress.Visible = true; + Model.Progress.Start(actions.Length); foreach (var action in actions) { var updates = await factory.FindUpdates(action, workspace.ModpackConfig?.MinecraftVersion, workspace.ModpackConfig?.ModLoader ?? ModLoader.Any); - Model.Progress.Value += 1; + Model.Progress.Increment(); if (updates == null || updates.Length == 0 || updates[0].Value == action.SourceTag) continue; @@ -44,7 +42,7 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase break; } - Model.Progress.Visible = false; + Model.Progress.End(); } protected override object GetResult()