28
28
using Windows . ApplicationModel . Core ;
29
29
using Windows . UI . Core ;
30
30
using Windows . Storage . Search ;
31
+ using Windows . UI . Xaml . Input ;
31
32
32
33
namespace Files
33
34
{
34
35
sealed partial class App : Application
35
36
{
36
37
public static ProHome selectedTabInstance { get ; set ; }
37
38
DeviceWatcher watcher ;
39
+ public static ObservableCollection < SidebarItem > sideBarItems = new ObservableCollection < SidebarItem > ( ) ;
40
+
38
41
public App ( )
39
42
{
40
43
this . InitializeComponent ( ) ;
@@ -61,12 +64,10 @@ public App()
61
64
if ( localSettings . Values [ "theme" ] . ToString ( ) == "Light" )
62
65
{
63
66
SettingsPages . Personalization . TV . ThemeValue = ApplicationTheme . Light ;
64
- //Debug.WriteLine("Theme Requested as Light");
65
67
}
66
68
else if ( localSettings . Values [ "theme" ] . ToString ( ) == "Dark" )
67
69
{
68
70
SettingsPages . Personalization . TV . ThemeValue = ApplicationTheme . Dark ;
69
- //Debug.WriteLine("Theme Requested as Dark");
70
71
}
71
72
else
72
73
{
@@ -75,19 +76,15 @@ public App()
75
76
if ( color == Colors . White )
76
77
{
77
78
SettingsPages . Personalization . TV . ThemeValue = ApplicationTheme . Light ;
78
- // Debug.WriteLine("Theme Requested as Default (Light)");
79
-
80
79
}
81
80
else
82
81
{
83
82
SettingsPages . Personalization . TV . ThemeValue = ApplicationTheme . Dark ;
84
- //Debug.WriteLine("Theme Requested as Default (Dark)");
85
83
}
86
84
}
87
85
}
88
86
89
87
this . RequestedTheme = SettingsPages . Personalization . TV . ThemeValue ;
90
- //Debug.WriteLine("!!Requested Theme!!" + RequestedTheme.ToString());
91
88
92
89
if ( localSettings . Values [ "FavoritesDisplayed_Start" ] == null )
93
90
{
@@ -119,8 +116,7 @@ public App()
119
116
localSettings . Values [ "DrivesDisplayed_NewTab" ] = false ;
120
117
}
121
118
122
- //FindDrives();
123
-
119
+ PopulatePinnedSidebarItems ( ) ;
124
120
}
125
121
126
122
public void PopulateDrivesListWithLocalDisks ( )
@@ -320,6 +316,151 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
320
316
}
321
317
}
322
318
319
+ public static List < string > LinesToRemoveFromFile = new List < string > ( ) ;
320
+
321
+ public async void PopulatePinnedSidebarItems ( )
322
+ {
323
+
324
+ AddDefaultLocations ( ) ;
325
+
326
+ StorageFile ListFile ;
327
+ StorageFolder cacheFolder = ApplicationData . Current . LocalCacheFolder ;
328
+ try
329
+ {
330
+ ListFile = await cacheFolder . GetFileAsync ( "PinnedItems.txt" ) ;
331
+ }
332
+ catch ( FileNotFoundException )
333
+ {
334
+ ListFile = await cacheFolder . CreateFileAsync ( "PinnedItems.txt" ) ;
335
+ }
336
+
337
+ if ( ListFile != null )
338
+ {
339
+ var ListFileLines = await FileIO . ReadLinesAsync ( ListFile ) ;
340
+ foreach ( string locationPath in ListFileLines )
341
+ {
342
+ try
343
+ {
344
+ StorageFolder fol = await StorageFolder . GetFolderFromPathAsync ( locationPath ) ;
345
+ var name = fol . DisplayName ;
346
+ var content = name ;
347
+ var icon = "\uE8B7 " ;
348
+
349
+ bool isDuplicate = false ;
350
+ foreach ( SidebarItem sbi in sideBarItems )
351
+ {
352
+ if ( ! string . IsNullOrWhiteSpace ( sbi . Path ) && ! sbi . isDefaultLocation )
353
+ {
354
+ if ( sbi . Path . ToString ( ) == locationPath )
355
+ {
356
+ isDuplicate = true ;
357
+
358
+ }
359
+ }
360
+ }
361
+
362
+ if ( ! isDuplicate )
363
+ {
364
+ sideBarItems . Add ( new SidebarItem ( ) { isDefaultLocation = false , Text = name , IconGlyph = icon , Path = locationPath } ) ;
365
+ }
366
+ }
367
+ catch ( UnauthorizedAccessException e )
368
+ {
369
+ Debug . WriteLine ( e . Message ) ;
370
+ }
371
+ catch ( FileNotFoundException e )
372
+ {
373
+ Debug . WriteLine ( "Pinned item was deleted and will be removed from the file lines list soon: " + e . Message ) ;
374
+ LinesToRemoveFromFile . Add ( locationPath ) ;
375
+ }
376
+ catch ( System . Runtime . InteropServices . COMException e )
377
+ {
378
+ Debug . WriteLine ( "Pinned item's drive was ejected and will be removed from the file lines list soon: " + e . Message ) ;
379
+ LinesToRemoveFromFile . Add ( locationPath ) ;
380
+ }
381
+ }
382
+
383
+ RemoveStaleSidebarItems ( ) ;
384
+ }
385
+ }
386
+
387
+ private void AddDefaultLocations ( )
388
+ {
389
+ sideBarItems . Add ( new SidebarItem ( ) { Text = "Home" , IconGlyph = "\uE737 " , isDefaultLocation = true } ) ;
390
+ sideBarItems . Add ( new SidebarItem ( ) { Text = "Desktop" , IconGlyph = "\uE8FC " , isDefaultLocation = true } ) ;
391
+ sideBarItems . Add ( new SidebarItem ( ) { Text = "Downloads" , IconGlyph = "\uE896 " , isDefaultLocation = true } ) ;
392
+ sideBarItems . Add ( new SidebarItem ( ) { Text = "Documents" , IconGlyph = "\uE8A5 " , isDefaultLocation = true } ) ;
393
+ sideBarItems . Add ( new SidebarItem ( ) { Text = "Pictures" , IconGlyph = "\uEB9F " , isDefaultLocation = true } ) ;
394
+ sideBarItems . Add ( new SidebarItem ( ) { Text = "Music" , IconGlyph = "\uEC4F " , isDefaultLocation = true } ) ;
395
+ sideBarItems . Add ( new SidebarItem ( ) { Text = "Videos" , IconGlyph = "\uE8B2 " , isDefaultLocation = true } ) ;
396
+ }
397
+
398
+ public static async void RemoveStaleSidebarItems ( )
399
+ {
400
+ StorageFile ListFile ;
401
+ StorageFolder cacheFolder = ApplicationData . Current . LocalCacheFolder ;
402
+ try
403
+ {
404
+ ListFile = await cacheFolder . GetFileAsync ( "PinnedItems.txt" ) ;
405
+ }
406
+ catch ( FileNotFoundException )
407
+ {
408
+ ListFile = await cacheFolder . CreateFileAsync ( "PinnedItems.txt" ) ;
409
+ }
410
+
411
+ if ( ListFile != null )
412
+ {
413
+ var ListFileLines = await FileIO . ReadLinesAsync ( ListFile ) ;
414
+ foreach ( string path in LinesToRemoveFromFile )
415
+ {
416
+ ListFileLines . Remove ( path ) ;
417
+ }
418
+
419
+ await FileIO . WriteLinesAsync ( ListFile , ListFileLines ) ;
420
+ ListFileLines = await FileIO . ReadLinesAsync ( ListFile ) ;
421
+
422
+ // Remove unpinned items from sidebar
423
+ var sideBarItems_Copy = sideBarItems . ToList ( ) ;
424
+ foreach ( SidebarItem location in sideBarItems )
425
+ {
426
+ if ( ! location . isDefaultLocation )
427
+ {
428
+ if ( ! ListFileLines . Contains ( location . Path . ToString ( ) ) )
429
+ {
430
+ sideBarItems_Copy . Remove ( location ) ;
431
+ }
432
+ }
433
+
434
+ }
435
+ sideBarItems . Clear ( ) ;
436
+ foreach ( SidebarItem correctItem in sideBarItems_Copy )
437
+ {
438
+ sideBarItems . Add ( correctItem ) ;
439
+ }
440
+ LinesToRemoveFromFile . Clear ( ) ;
441
+ }
442
+ }
443
+
444
+ public static SidebarItem rightClickedItem ;
445
+
446
+ public static async void FlyoutItem_Click ( object sender , RoutedEventArgs e )
447
+ {
448
+ StorageFolder cacheFolder = ApplicationData . Current . LocalCacheFolder ;
449
+ var ListFile = await cacheFolder . GetFileAsync ( "PinnedItems.txt" ) ;
450
+ var ListFileLines = await FileIO . ReadLinesAsync ( ListFile ) ;
451
+ foreach ( string path in ListFileLines )
452
+ {
453
+ if ( path == App . rightClickedItem . Path . ToString ( ) )
454
+ {
455
+ App . LinesToRemoveFromFile . Add ( path ) ;
456
+ RemoveStaleSidebarItems ( ) ;
457
+ return ;
458
+ }
459
+ }
460
+ }
461
+
462
+
463
+
323
464
public static Windows . UI . Xaml . UnhandledExceptionEventArgs exceptionInfo { get ; set ; }
324
465
public static string exceptionStackTrace { get ; set ; }
325
466
public Dialogs . ExceptionDialog exceptionDialog ;
0 commit comments