progressbar tweaks
This commit is contained in:
@@ -25,9 +25,7 @@ internal static class SharedFunctions
|
||||
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<bool> 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)
|
||||
|
||||
@@ -39,8 +39,8 @@
|
||||
<pilz:ImageButton.Flyout>
|
||||
<MenuFlyout>
|
||||
<MenuFlyout.Items>
|
||||
<MenuItem x:Name="MenuItemWorkspacePreferences" Header="{x:Static langRes:GeneralLangRes.WorkspacePreferences}"/>
|
||||
<MenuItem x:Name="MenuItemSaveWorkspace" Header="{x:Static langRes:GeneralLangRes.SaveWorkspace}" HotKey="Ctrl+S"/>
|
||||
<MenuItem x:Name="MenuItemWorkspacePreferences" Header="{x:Static langRes:GeneralLangRes.WorkspacePreferences}" Click="MenuItemWorkspacePreferences_OnClick"/>
|
||||
<MenuItem x:Name="MenuItemSaveWorkspace" Header="{x:Static langRes:GeneralLangRes.SaveWorkspace}" HotKey="Ctrl+S" Click="MenuItemSaveWorkspace_OnClick"/>
|
||||
<Separator/>
|
||||
<MenuItem x:Name="MenuItemNewWorkspace" Header="{x:Static langRes:GeneralLangRes.NewWorkspace}"/>
|
||||
<Separator/>
|
||||
@@ -154,26 +154,15 @@
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
|
||||
<!-- Progress -->
|
||||
<Panel
|
||||
HorizontalAlignment="Stretch"
|
||||
<!-- ProgressBar: Status -->
|
||||
<ProgressBar
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Stretch"
|
||||
IsVisible="{Binding Progress.Visible}">
|
||||
|
||||
<!-- ProgressBar: Status -->
|
||||
<ProgressBar
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Maximum="{Binding Progress.MaxValue}"
|
||||
Value="{Binding Progress.Value}"/>
|
||||
|
||||
<!-- TextBox: Status -->
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
Text="{Binding Progress.Text}"/>
|
||||
</Panel>
|
||||
Maximum="{Binding Progress.MaxValue}"
|
||||
Value="{Binding Progress.Value}"
|
||||
ShowProgressText="{Binding Progress.ShowText}"
|
||||
IsIndeterminate="{Binding Progress.IsGeneric}"
|
||||
IsVisible="{Binding Progress.IsVisible}"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- DataGrid -->
|
||||
|
||||
@@ -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;
|
||||
@@ -20,6 +18,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;
|
||||
public IMainApi MainApi => 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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -82,23 +82,15 @@
|
||||
|
||||
<!-- Footer -->
|
||||
<dialogs:AvaloniaFlyoutBase.FooterContent>
|
||||
<Panel
|
||||
|
||||
<!-- ProgressBar: Status -->
|
||||
<ProgressBar
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
IsVisible="{Binding Progress.Visible}">
|
||||
|
||||
<!-- ProgressBar: Status -->
|
||||
<ProgressBar
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Maximum="{Binding Progress.MaxValue}"
|
||||
Value="{Binding Progress.Value}"/>
|
||||
|
||||
<!-- TextBox: Status -->
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding Progress.Text}"/>
|
||||
</Panel>
|
||||
Maximum="{Binding Progress.MaxValue}"
|
||||
Value="{Binding Progress.Value}"
|
||||
ShowProgressText="{Binding Progress.ShowText}"
|
||||
IsIndeterminate="{Binding Progress.IsGeneric}"
|
||||
IsVisible="{Binding Progress.IsVisible}"/>
|
||||
</dialogs:AvaloniaFlyoutBase.FooterContent>
|
||||
</dialogs:AvaloniaFlyoutBase>
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user