File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
src/Files.App/ViewModels/UserControls Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright (c) Files Community
2+ // Licensed under the MIT License.
3+
4+ using System . Collections . Specialized ;
5+ using Files . Shared . Utils ;
6+
7+ namespace Files . App . ViewModels . UserControls
8+ {
9+ [ Bindable ( true ) ]
10+ public sealed partial class ShelfViewModel : ObservableObject , IAsyncInitialize
11+ {
12+ private readonly Dictionary < string , IFolderWatcher > _watchers ;
13+
14+ public ObservableCollection < ShelfItem > Items { get ; }
15+
16+ public ShelfViewModel ( )
17+ {
18+ _watchers = new ( ) ;
19+ Items = new ( ) ;
20+ Items . CollectionChanged += Items_CollectionChanged ;
21+ }
22+
23+ /// <inheritdoc/>
24+ public Task InitAsync ( CancellationToken cancellationToken = default )
25+ {
26+ // TODO: Load persisted shelf items
27+ return Task . CompletedTask ;
28+ }
29+
30+ private async void Items_CollectionChanged ( object ? sender , NotifyCollectionChangedEventArgs e )
31+ {
32+ switch ( e . Action )
33+ {
34+ case NotifyCollectionChangedAction . Add when e . NewItems is not null :
35+ {
36+ if ( e . NewItems [ 0 ] is not INestedStorable nestedStorable )
37+ return ;
38+
39+ var parentPath = SystemIO . Path . GetDirectoryName ( nestedStorable . Id ) ?? string . Empty ;
40+ if ( _watchers . ContainsKey ( parentPath ) )
41+ return ;
42+
43+ if ( await nestedStorable . GetParentAsync ( ) is not IMutableFolder mutableFolder )
44+ return ;
45+
46+ // TODO: Register IFolderWatcher
47+
48+ break ;
49+ }
50+
51+ case NotifyCollectionChangedAction . Remove :
52+
53+ break ;
54+ }
55+ }
56+ }
57+ }
You can’t perform that action at this time.
0 commit comments