Browse Source

Add extension settings

pull/438/head
ionite34 10 months ago
parent
commit
7013f81311
No known key found for this signature in database
GPG Key ID: B3404C5F3827849B
  1. 17
      StabilityMatrix.Avalonia/ViewModels/Dialogs/PropertyGridViewModel.cs
  2. 5
      StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs
  3. 58
      StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageExtensionBrowserViewModel.cs
  4. 9
      StabilityMatrix.Avalonia/Views/PackageManager/PackageExtensionBrowserView.axaml
  5. 8
      StabilityMatrix.Core/Models/InstalledPackage.cs
  6. 17
      StabilityMatrix.Core/Models/Packages/Extensions/GitPackageExtensionManager.cs

17
StabilityMatrix.Avalonia/ViewModels/Dialogs/PropertyGridViewModel.cs

@ -3,6 +3,7 @@ using System.ComponentModel;
using Avalonia; using Avalonia;
using Avalonia.PropertyGrid.ViewModels; using Avalonia.PropertyGrid.ViewModels;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using FluentAvalonia.UI.Controls;
using OneOf; using OneOf;
using StabilityMatrix.Avalonia.Controls; using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Languages; using StabilityMatrix.Avalonia.Languages;
@ -44,4 +45,20 @@ public partial class PropertyGridViewModel : ContentDialogViewModelBase
return dialog; return dialog;
} }
/// <summary>
/// Like <see cref="GetDialog"/>, but with a primary save button.
/// </summary>
public BetterContentDialog GetSaveDialog()
{
var dialog = base.GetDialog();
dialog.Padding = new Thickness(0);
dialog.CloseOnClickOutside = true;
dialog.CloseButtonText = Resources.Action_Close;
dialog.PrimaryButtonText = Resources.Action_Save;
dialog.DefaultButton = ContentDialogButton.Primary;
return dialog;
}
} }

5
StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Notifications; using Avalonia.Controls.Notifications;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
@ -394,6 +395,10 @@ public partial class PackageCardViewModel : ProgressViewModel
var dialog = new BetterContentDialog var dialog = new BetterContentDialog
{ {
Content = vm, Content = vm,
MinDialogWidth = 850,
MaxDialogHeight = 1100,
MaxDialogWidth = 850,
ContentMargin = new Thickness(16, 32),
CloseOnClickOutside = true, CloseOnClickOutside = true,
FullSizeDesired = true, FullSizeDesired = true,
IsFooterVisible = false, IsFooterVisible = false,

58
StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageExtensionBrowserViewModel.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Linq; using System.Linq;
using System.Reactive.Disposables; using System.Reactive.Disposables;
@ -14,9 +15,13 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using DynamicData; using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using FluentAvalonia.UI.Controls;
using KGySoft.CoreLibraries;
using StabilityMatrix.Avalonia.Collections; using StabilityMatrix.Avalonia.Collections;
using StabilityMatrix.Avalonia.Languages;
using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base; using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.ViewModels.Dialogs;
using StabilityMatrix.Avalonia.Views.PackageManager; using StabilityMatrix.Avalonia.Views.PackageManager;
using StabilityMatrix.Core.Attributes; using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Extensions; using StabilityMatrix.Core.Extensions;
@ -24,6 +29,7 @@ using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models; using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.PackageModification; using StabilityMatrix.Core.Models.PackageModification;
using StabilityMatrix.Core.Models.Packages.Extensions; using StabilityMatrix.Core.Models.Packages.Extensions;
using StabilityMatrix.Core.Services;
namespace StabilityMatrix.Avalonia.ViewModels.PackageManager; namespace StabilityMatrix.Avalonia.ViewModels.PackageManager;
@ -33,7 +39,9 @@ namespace StabilityMatrix.Avalonia.ViewModels.PackageManager;
public partial class PackageExtensionBrowserViewModel : ViewModelBase, IDisposable public partial class PackageExtensionBrowserViewModel : ViewModelBase, IDisposable
{ {
private readonly INotificationService notificationService; private readonly INotificationService notificationService;
private readonly IDisposable cleanUp; private readonly ISettingsManager settingsManager;
private readonly ServiceManager<ViewModelBase> vmFactory;
private readonly CompositeDisposable cleanUp;
public PackagePair? PackagePair { get; set; } public PackagePair? PackagePair { get; set; }
@ -70,9 +78,15 @@ public partial class PackageExtensionBrowserViewModel : ViewModelBase, IDisposab
public IObservableCollection<InstalledPackageExtension> InstalledExtensions { get; } = public IObservableCollection<InstalledPackageExtension> InstalledExtensions { get; } =
new ObservableCollectionExtended<InstalledPackageExtension>(); new ObservableCollectionExtended<InstalledPackageExtension>();
public PackageExtensionBrowserViewModel(INotificationService notificationService) public PackageExtensionBrowserViewModel(
INotificationService notificationService,
ISettingsManager settingsManager,
ServiceManager<ViewModelBase> vmFactory
)
{ {
this.notificationService = notificationService; this.notificationService = notificationService;
this.settingsManager = settingsManager;
this.vmFactory = vmFactory;
var availableItemsChangeSet = availableExtensionsSource var availableItemsChangeSet = availableExtensionsSource
.Connect() .Connect()
@ -225,6 +239,39 @@ public partial class PackageExtensionBrowserViewModel : ViewModelBase, IDisposab
RefreshBackground(); RefreshBackground();
} }
[RelayCommand]
public async Task OpenExtensionsSettingsDialog()
{
if (PackagePair is null)
return;
var grid = new ExtensionSettingsPropertyGrid
{
ManifestUrls = new BindingList<string>(
PackagePair?.InstalledPackage.ExtraExtensionManifestUrls ?? []
)
};
var dialog = vmFactory
.Get<PropertyGridViewModel>(vm =>
{
vm.Title = $"{Resources.Label_Settings}";
vm.SelectedObject = grid;
vm.IncludeCategories = ["Base"];
})
.GetSaveDialog();
dialog.MinDialogWidth = 750;
dialog.MaxDialogWidth = 750;
if (await dialog.ShowAsync() == ContentDialogResult.Primary)
{
await using var _ = settingsManager.BeginTransaction();
PackagePair!.InstalledPackage.ExtraExtensionManifestUrls = grid.ManifestUrls.ToList();
}
}
/// <inheritdoc /> /// <inheritdoc />
public override async Task OnLoadedAsync() public override async Task OnLoadedAsync()
{ {
@ -374,4 +421,11 @@ public partial class PackageExtensionBrowserViewModel : ViewModelBase, IDisposab
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
private class ExtensionSettingsPropertyGrid : AbstractNotifyPropertyChanged
{
[Category("Base")]
[DisplayName("Extension Manifest Sources")]
public BindingList<string> ManifestUrls { get; init; } = [];
}
} }

9
StabilityMatrix.Avalonia/Views/PackageManager/PackageExtensionBrowserView.axaml

@ -166,6 +166,7 @@
<Button <Button
Grid.Row="0" Grid.Row="0"
Grid.Column="2" Grid.Column="2"
Command="{Binding OpenExtensionsSettingsDialogCommand}"
Padding="16,6" Padding="16,6"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
@ -226,7 +227,7 @@
RowSpacing="12" RowSpacing="12"
Margin="8"> Margin="8">
<sg:SpacedGrid <sg:SpacedGrid
ColumnDefinitions="*,Auto,Auto" ColumnDefinitions="*,Auto"
ColumnSpacing="8"> ColumnSpacing="8">
<TextBox <TextBox
Classes="search" Classes="search"
@ -236,7 +237,7 @@
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Center"
Text="{Binding Query, Mode=TwoWay}"/> Text="{Binding Query, Mode=TwoWay}"/>
<!-- Refresh Button --> <!-- Refresh Button -->
<Button <Button
Grid.Row="0" Grid.Row="0"
@ -249,14 +250,14 @@
</Button> </Button>
<!-- Settings / Edit Manifests Button --> <!-- Settings / Edit Manifests Button -->
<Button <!--<Button
Grid.Row="0" Grid.Row="0"
Grid.Column="2" Grid.Column="2"
Padding="16,6" Padding="16,6"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
<ui:SymbolIcon FontSize="16" Symbol="Settings" /> <ui:SymbolIcon FontSize="16" Symbol="Settings" />
</Button> </Button>-->
</sg:SpacedGrid> </sg:SpacedGrid>
<ScrollViewer <ScrollViewer

8
StabilityMatrix.Core/Models/InstalledPackage.cs

@ -57,6 +57,8 @@ public class InstalledPackage : IJsonOnDeserialized
public bool UseSharedOutputFolder { get; set; } public bool UseSharedOutputFolder { get; set; }
public List<string>? ExtraExtensionManifestUrls { get; set; }
/// <summary> /// <summary>
/// Get the launch args host option value. /// Get the launch args host option value.
/// </summary> /// </summary>
@ -239,7 +241,11 @@ public class InstalledPackage : IJsonOnDeserialized
if (string.IsNullOrWhiteSpace(InstalledBranch) && !string.IsNullOrWhiteSpace(PackageVersion)) if (string.IsNullOrWhiteSpace(InstalledBranch) && !string.IsNullOrWhiteSpace(PackageVersion))
{ {
// release mode // release mode
Version = new InstalledPackageVersion { InstalledReleaseVersion = PackageVersion, IsPrerelease = false }; Version = new InstalledPackageVersion
{
InstalledReleaseVersion = PackageVersion,
IsPrerelease = false
};
} }
else if (!string.IsNullOrWhiteSpace(PackageVersion)) else if (!string.IsNullOrWhiteSpace(PackageVersion))
{ {

17
StabilityMatrix.Core/Models/Packages/Extensions/GitPackageExtensionManager.cs

@ -35,7 +35,22 @@ public abstract class GitPackageExtensionManager(IPrerequisiteHelper prerequisit
protected virtual IEnumerable<ExtensionManifest> GetManifests(InstalledPackage installedPackage) protected virtual IEnumerable<ExtensionManifest> GetManifests(InstalledPackage installedPackage)
{ {
return DefaultManifests; if (installedPackage.ExtraExtensionManifestUrls is not { } customUrls)
{
return DefaultManifests;
}
var manifests = DefaultManifests.ToList();
foreach (var url in customUrls)
{
if (!string.IsNullOrEmpty(url) && Uri.TryCreate(url, UriKind.Absolute, out var uri))
{
manifests.Add(new ExtensionManifest(uri));
}
}
return manifests;
} }
/// <inheritdoc /> /// <inheritdoc />

Loading…
Cancel
Save