@@ -12,11 +12,13 @@ namespace BasisPM.App.ViewModels;
1212
1313public sealed class PackagesViewModel : ObservableObject
1414{
15+ private readonly UserSettingsService _settingsService ;
1516 private readonly CatalogService _catalogService ;
1617 private readonly UnityProjectService _projectService ;
1718 private readonly GitHubService _githubService ;
1819 private readonly VersionService _versionService = new ( ) ;
1920 private readonly MainWindowViewModel _shell ;
21+ private bool _isGridView ;
2022
2123 private Catalog _catalog = new ( ) ;
2224 private BasisInstall ? _install ;
@@ -57,15 +59,32 @@ public BasisInstall? SelectedInstall
5759 public bool HasInstall => _install is not null && _install . HasUnityProject ;
5860 public bool HasInstalls => InstallOptions . Count > 0 ;
5961
62+ // Packages "Available" list layout: false = rows (default), true = a grid of cards. Persisted.
63+ public bool IsGridView
64+ {
65+ get => _isGridView ;
66+ set
67+ {
68+ if ( ! SetField ( ref _isGridView , value ) ) return ;
69+ OnPropertyChanged ( nameof ( IsListView ) ) ;
70+ OnPropertyChanged ( nameof ( LayoutToggleLabel ) ) ;
71+ _ = PersistGridViewAsync ( value ) ;
72+ }
73+ }
74+ public bool IsListView => ! _isGridView ;
75+ public string LayoutToggleLabel => _isGridView ? L . Tr ( "packages.button.listView" ) : L . Tr ( "packages.button.gridView" ) ;
76+
6077 public RelayCommand < CatalogPackageVersion > InstallCommand { get ; }
6178 public RelayCommand < InstalledPackageRow > UninstallCommand { get ; }
6279 public RelayCommand RefreshCommand { get ; }
6380 public RelayCommand AddFromGitHubCommand { get ; }
6481 public RelayCommand CreateBundleCommand { get ; }
6582 public RelayCommand < CatalogPackageVersion > ChooseVersionCommand { get ; }
83+ public RelayCommand ToggleLayoutCommand { get ; }
6684
67- public PackagesViewModel ( CatalogService catalogService , UnityProjectService projectService , MainWindowViewModel shell )
85+ public PackagesViewModel ( UserSettingsService settingsService , CatalogService catalogService , UnityProjectService projectService , MainWindowViewModel shell )
6886 {
87+ _settingsService = settingsService ;
6988 _catalogService = catalogService ;
7089 _projectService = projectService ;
7190 _githubService = new GitHubService ( ) ;
@@ -77,6 +96,28 @@ public PackagesViewModel(CatalogService catalogService, UnityProjectService proj
7796 AddFromGitHubCommand = new RelayCommand ( AddFromGitHubAsync ) ;
7897 CreateBundleCommand = new RelayCommand ( CreateBundleAsync ) ;
7998 ChooseVersionCommand = new RelayCommand < CatalogPackageVersion > ( ChooseVersionAsync ) ;
99+ ToggleLayoutCommand = new RelayCommand ( ( ) => IsGridView = ! IsGridView ) ;
100+ }
101+
102+ /// <summary>Applies the persisted layout choice at startup without re-saving it.</summary>
103+ public void SetInitialGridView ( bool grid )
104+ {
105+ if ( _isGridView == grid ) return ;
106+ _isGridView = grid ;
107+ OnPropertyChanged ( nameof ( IsGridView ) ) ;
108+ OnPropertyChanged ( nameof ( IsListView ) ) ;
109+ OnPropertyChanged ( nameof ( LayoutToggleLabel ) ) ;
110+ }
111+
112+ private async Task PersistGridViewAsync ( bool grid )
113+ {
114+ try
115+ {
116+ var settings = await _settingsService . LoadAsync ( ) ;
117+ settings . PackagesGridView = grid ;
118+ await _settingsService . SaveAsync ( settings ) ;
119+ }
120+ catch { /* a view preference isn't worth surfacing a settings-write error */ }
80121 }
81122
82123 public void SetActiveInstall ( BasisInstall install )
@@ -554,6 +595,8 @@ public sealed record PackageRow(CatalogPackageVersion Entry, string? InstalledVe
554595 public bool HasAuthor => ! string . IsNullOrWhiteSpace ( Entry . Author ? . Name ) ;
555596 public string ? Unity => Entry . Unity ;
556597 public bool HasUnity => ! string . IsNullOrWhiteSpace ( Entry . Unity ) ;
598+ public string ? License => Entry . License ;
599+ public bool HasLicense => ! string . IsNullOrWhiteSpace ( Entry . License ) ;
557600 public string Owner => PackagesViewModel . OwnerOf ( Entry . Name ) ;
558601 public string Initial => string . IsNullOrWhiteSpace ( DisplayName ) ? "?" : DisplayName . TrimStart ( ) [ ..1 ] . ToUpperInvariant ( ) ;
559602 public bool HasGit => ! string . IsNullOrWhiteSpace ( Entry . Url ) ;
0 commit comments