@@ -33,8 +33,6 @@ public sealed partial class QuickAccessWidgetViewModel : BaseWidgetViewModel, IW
3333
3434 public QuickAccessWidgetViewModel ( )
3535 {
36- _ = InitializeWidget ( ) ;
37-
3836 Items . CollectionChanged += Items_CollectionChanged ;
3937
4038 OpenPropertiesCommand = new RelayCommand < WidgetFolderCardItem > ( ExecuteOpenPropertiesCommand ) ;
@@ -46,15 +44,22 @@ public QuickAccessWidgetViewModel()
4644
4745 private async Task InitializeWidget ( )
4846 {
49- var itemsToAdd = await QuickAccessService . GetPinnedFoldersAsync ( ) ;
50- ModifyItemAsync ( this , new ( itemsToAdd . ToArray ( ) , false ) { Reset = true } ) ;
47+ //await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
48+ //{
49+ // await foreach (IWindowsStorable folder in HomePageContext.HomeFolder.GetQuickAccessFolderAsync(default))
50+ // {
51+ // folder.GetPropertyValue<bool>("System.Home.IsPinned", out var isPinned);
52+
53+ // var card = new WidgetFolderCardItem(folder, folder.GetDisplayName(Windows.Win32.UI.Shell.SIGDN.SIGDN_PARENTRELATIVEFORUI), isPinned);
5154
52- App . QuickAccessManager . UpdateQuickAccessWidget += ModifyItemAsync ;
55+ // Items.Insert(Items.Count, card);
56+ // }
57+ //});
5358 }
5459
5560 public Task RefreshWidgetAsync ( )
5661 {
57- return Task . CompletedTask ;
62+ return InitializeWidget ( ) ;
5863 }
5964
6065 public override List < ContextMenuFlyoutItemViewModel > GetItemMenuItems ( WidgetCardItem item , bool isPinned , bool isFolder = false )
@@ -125,87 +130,87 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
125130 } . Where ( x => x . ShowItem ) . ToList ( ) ;
126131 }
127132
128- private async void ModifyItemAsync ( object ? sender , ModifyQuickAccessEventArgs ? e )
129- {
130- if ( e is null )
131- return ;
132-
133- await MainWindow . Instance . DispatcherQueue . EnqueueOrInvokeAsync ( async ( ) =>
134- {
135- if ( e . Reset )
136- {
137- // Find the intersection between the two lists and determine whether to remove or add
138- var originalItems = Items . ToList ( ) ;
139- var itemsToRemove = originalItems . Where ( x => ! e . Paths . Contains ( x . Path ) ) ;
140- var itemsToAdd = e . Paths . Where ( x => ! originalItems . Any ( y => y . Path == x ) ) ;
141-
142- // Remove items
143- foreach ( var itemToRemove in itemsToRemove )
144- Items . Remove ( itemToRemove ) ;
145-
146- // Add items
147- foreach ( var itemToAdd in itemsToAdd )
148- {
149- var interimItems = Items . ToList ( ) ;
150- var item = await App . QuickAccessManager . Model . CreateLocationItemFromPathAsync ( itemToAdd ) ;
151- var lastIndex = Items . IndexOf ( interimItems . FirstOrDefault ( x => ! x . IsPinned ) ) ;
152- var isPinned = ( bool ? ) e . Items . Where ( x => x . FilePath == itemToAdd ) . FirstOrDefault ( ) ? . Properties [ "System.Home.IsPinned" ] ?? false ;
153- if ( interimItems . Any ( x => x . Path == itemToAdd ) )
154- continue ;
155-
156- Items . Insert ( isPinned && lastIndex >= 0 ? Math . Min ( lastIndex , Items . Count ) : Items . Count , new WidgetFolderCardItem ( item , Path . GetFileName ( item . Text ) , isPinned )
157- {
158- Path = item . Path ,
159- } ) ;
160- }
161-
162- return ;
163- }
164- if ( e . Reorder )
165- {
166- // Remove pinned items
167- foreach ( var itemToRemove in Items . ToList ( ) . Where ( x => x . IsPinned ) )
168- Items . Remove ( itemToRemove ) ;
169-
170- // Add pinned items in the new order
171- foreach ( var itemToAdd in e . Paths )
172- {
173- var interimItems = Items . ToList ( ) ;
174- var item = await App . QuickAccessManager . Model . CreateLocationItemFromPathAsync ( itemToAdd ) ;
175- var lastIndex = Items . IndexOf ( interimItems . FirstOrDefault ( x => ! x . IsPinned ) ) ;
176- if ( interimItems . Any ( x => x . Path == itemToAdd ) )
177- continue ;
178-
179- Items . Insert ( lastIndex >= 0 ? Math . Min ( lastIndex , Items . Count ) : Items . Count , new WidgetFolderCardItem ( item , Path . GetFileName ( item . Text ) , true )
180- {
181- Path = item . Path ,
182- } ) ;
183- }
184-
185- return ;
186- }
187- if ( e . Add )
188- {
189- foreach ( var itemToAdd in e . Paths )
190- {
191- var interimItems = Items . ToList ( ) ;
192- var item = await App . QuickAccessManager . Model . CreateLocationItemFromPathAsync ( itemToAdd ) ;
193- var lastIndex = Items . IndexOf ( interimItems . FirstOrDefault ( x => ! x . IsPinned ) ) ;
194- if ( interimItems . Any ( x => x . Path == itemToAdd ) )
195- continue ;
196- Items . Insert ( e . Pin && lastIndex >= 0 ? Math . Min ( lastIndex , Items . Count ) : Items . Count , new WidgetFolderCardItem ( item , Path . GetFileName ( item . Text ) , e . Pin ) // Add just after the Recent Folders
197- {
198- Path = item . Path ,
199- } ) ;
200- }
201- }
202- else
203- {
204- foreach ( var itemToRemove in Items . ToList ( ) . Where ( x => e . Item . Contains ( x . Path ) ) )
205- Items . Remove ( itemToRemove ) ;
206- }
207- } ) ;
208- }
133+ // private async void ModifyItemAsync(object? sender, ModifyQuickAccessEventArgs? e)
134+ // {
135+ // if (e is null)
136+ // return;
137+
138+ // await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
139+ // {
140+ // if (e.Reset)
141+ // {
142+ // // Find the intersection between the two lists and determine whether to remove or add
143+ // var originalItems = Items.ToList();
144+ // var itemsToRemove = originalItems.Where(x => !e.Paths.Contains(x.Path));
145+ // var itemsToAdd = e.Paths.Where(x => !originalItems.Any(y => y.Path == x));
146+
147+ // // Remove items
148+ // foreach (var itemToRemove in itemsToRemove)
149+ // Items.Remove(itemToRemove);
150+
151+ // // Add items
152+ // foreach (var itemToAdd in itemsToAdd)
153+ // {
154+ // var interimItems = Items.ToList();
155+ // var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
156+ // var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
157+ // var isPinned = (bool?)e.Items.Where(x => x.FilePath == itemToAdd).FirstOrDefault()?.Properties["System.Home.IsPinned"] ?? false;
158+ // if (interimItems.Any(x => x.Path == itemToAdd))
159+ // continue;
160+
161+ // Items.Insert(isPinned && lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), isPinned)
162+ // {
163+ // Path = item.Path,
164+ // });
165+ // }
166+
167+ // return;
168+ // }
169+ // if (e.Reorder)
170+ // {
171+ // // Remove pinned items
172+ // foreach (var itemToRemove in Items.ToList().Where(x => x.IsPinned))
173+ // Items.Remove(itemToRemove);
174+
175+ // // Add pinned items in the new order
176+ // foreach (var itemToAdd in e.Paths)
177+ // {
178+ // var interimItems = Items.ToList();
179+ // var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
180+ // var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
181+ // if (interimItems.Any(x => x.Path == itemToAdd))
182+ // continue;
183+
184+ // Items.Insert(lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), true)
185+ // {
186+ // Path = item.Path,
187+ // });
188+ // }
189+
190+ // return;
191+ // }
192+ // if (e.Add)
193+ // {
194+ // foreach (var itemToAdd in e.Paths)
195+ // {
196+ // var interimItems = Items.ToList();
197+ // var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
198+ // var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
199+ // if (interimItems.Any(x => x.Path == itemToAdd))
200+ // continue;
201+ // Items.Insert(e.Pin && lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), e.Pin) // Add just after the Recent Folders
202+ // {
203+ // Path = item.Path,
204+ // });
205+ // }
206+ // }
207+ // else
208+ // {
209+ // foreach (var itemToRemove in Items.ToList().Where(x => e.Item.Contains(x.Path)))
210+ // Items.Remove(itemToRemove);
211+ // }
212+ // });
213+ // }
209214
210215 public async Task NavigateToPath ( string path )
211216 {
@@ -305,7 +310,6 @@ private void ExecuteOpenPropertiesCommand(WidgetFolderCardItem? item)
305310
306311 public void Dispose ( )
307312 {
308- App . QuickAccessManager . UpdateQuickAccessWidget -= ModifyItemAsync ;
309313 }
310314 }
311315}
0 commit comments