55using System . Collections . Specialized ;
66using Stride . Core . Assets . Editor . Components . Properties ;
77using Stride . Core . Assets . Presentation . ViewModels ;
8+ using Stride . Core . Extensions ;
89using Stride . Core . Presentation . Collections ;
10+ using Stride . Core . Presentation . Commands ;
911using Stride . Core . Presentation . ViewModels ;
1012
1113namespace Stride . Core . Assets . Editor . ViewModels ;
@@ -26,6 +28,8 @@ public AssetCollectionViewModel(SessionViewModel session)
2628 // Initialize the view model that will manage the properties of the assets selected on the main asset view
2729 AssetViewProperties = new SessionObjectPropertiesViewModel ( session ) ;
2830
31+ SelectAssetCommand = new AnonymousCommand < AssetViewModel > ( ServiceProvider , x => SelectAssets ( x . Yield ( ) ! ) ) ;
32+
2933 selectedContent . CollectionChanged += SelectedContentCollectionChanged ;
3034 SelectedLocations . CollectionChanged += SelectedLocationCollectionChanged ;
3135 }
@@ -61,7 +65,32 @@ public object? SingleSelectedContent
6165 get => singleSelectedContent ;
6266 private set => SetValue ( ref singleSelectedContent , value ) ;
6367 }
64-
68+
69+ public ICommandBase SelectAssetCommand { get ; }
70+
71+ public void SelectAssets ( IEnumerable < AssetViewModel > assetsToSelect )
72+ {
73+ Dispatcher . EnsureAccess ( ) ;
74+
75+ var assetList = assetsToSelect . ToList ( ) ;
76+
77+ // Ensure the location of the assets to select are themselves selected.
78+ var locations = new HashSet < DirectoryBaseViewModel > ( assetList . Select ( x => x . Directory ) ) ;
79+ if ( locations . All ( x => ! SelectedLocations . Contains ( x ) ) )
80+ {
81+ SelectedLocations . Clear ( ) ;
82+ SelectedLocations . AddRange ( locations ) ;
83+ }
84+
85+ // Don't reselect if the current selection is the same
86+ if ( assetList . Count != SelectedAssets . Count || ! assetList . All ( x => SelectedAssets . Contains ( x ) ) )
87+ {
88+ selectedContent . Clear ( ) ;
89+ // FIXME xplat-editor filters
90+ selectedContent . AddRange ( assetList ) ;
91+ }
92+ }
93+
6594 internal IReadOnlyCollection < DirectoryBaseViewModel > GetSelectedDirectories ( bool includeSubDirectoriesOfSelected )
6695 {
6796 var selectedDirectories = new List < DirectoryBaseViewModel > ( ) ;
@@ -162,7 +191,7 @@ private async void SelectedContentCollectionChanged(object? sender, NotifyCollec
162191 }
163192
164193 AssetViewProperties . UpdateTypeAndName ( SelectedAssets , x => x . TypeDisplayName , x => x . Url , "assets" ) ;
165- await AssetViewProperties . GenerateSelectionPropertiesAsync ( SelectedAssets ) ;
194+ await AssetViewProperties . GenerateSelectionPropertiesAsync ( SelectedAssets ) ;
166195 }
167196
168197 private void SelectedLocationCollectionChanged ( object ? sender , NotifyCollectionChangedEventArgs e )
0 commit comments