1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . IO ;
4+ using System . Linq ;
5+ using System . Threading . Tasks ;
6+ using Windows . UI . StartScreen ;
7+ using Windows . Storage ;
8+ using Files . Common ;
9+
10+ namespace Files . Helpers
11+ {
12+ public sealed class JumpListManager
13+ {
14+ private JumpList _instance = null ;
15+ private List < string > JumpListItemPaths { get ; set ; }
16+ public JumpListManager ( )
17+ {
18+ Initialize ( ) ;
19+ }
20+
21+ private async void Initialize ( )
22+ {
23+ if ( JumpList . IsSupported ( ) )
24+ {
25+ _instance = await JumpList . LoadCurrentAsync ( ) ;
26+
27+ // Disable automatic jumplist. It doesn't work with Files UWP.
28+ _instance . SystemGroupKind = JumpListSystemGroupKind . None ;
29+ JumpListItemPaths = _instance . Items . Select ( item => item . Arguments ) . ToList ( ) ;
30+ }
31+ }
32+
33+ public async void AddFolderToJumpList ( string path )
34+ {
35+ await AddFolder ( path ) ;
36+ await _instance ? . SaveAsync ( ) ;
37+ }
38+
39+ private Task AddFolder ( string path )
40+ {
41+ if ( ! JumpListItemPaths . Contains ( path ) && _instance != null )
42+ {
43+ string displayName ;
44+ if ( path . Equals ( App . AppSettings . DesktopPath , StringComparison . OrdinalIgnoreCase ) )
45+ {
46+ displayName = "ms-resource:///Resources/SidebarDesktop" ;
47+ }
48+ else if ( path . Equals ( App . AppSettings . DownloadsPath , StringComparison . OrdinalIgnoreCase ) )
49+ {
50+ displayName = "ms-resource:///Resources/SidebarDownloads" ;
51+ }
52+ else if ( path . Equals ( App . AppSettings . DocumentsPath , StringComparison . OrdinalIgnoreCase ) )
53+ {
54+ displayName = "ms-resource:///Resources/SidebarDocuments" ;
55+ }
56+ else if ( path . Equals ( App . AppSettings . PicturesPath , StringComparison . OrdinalIgnoreCase ) )
57+ {
58+ displayName = "ms-resource:///Resources/SidebarPictures" ;
59+ }
60+ else if ( path . Equals ( App . AppSettings . MusicPath , StringComparison . OrdinalIgnoreCase ) )
61+ {
62+ displayName = "ms-resource:///Resources/SidebarMusic" ;
63+ }
64+ else if ( path . Equals ( App . AppSettings . VideosPath , StringComparison . OrdinalIgnoreCase ) )
65+ {
66+ displayName = "ms-resource:///Resources/SidebarVideos" ;
67+ }
68+ else if ( path . Equals ( App . AppSettings . RecycleBinPath , StringComparison . OrdinalIgnoreCase ) )
69+ {
70+ var localSettings = ApplicationData . Current . LocalSettings ;
71+ displayName = localSettings . Values . Get ( "RecycleBin_Title" , "Recycle Bin" ) ;
72+ }
73+ else
74+ {
75+ displayName = Path . GetFileName ( path ) ;
76+ }
77+
78+ var jumplistItem = JumpListItem . CreateWithArguments ( path , displayName ) ;
79+ jumplistItem . Description = jumplistItem . Arguments ;
80+ jumplistItem . GroupName = "ms-resource:///Resources/JumpListRecentGroupHeader" ;
81+ jumplistItem . Logo = new Uri ( "ms-appx:///Assets/FolderIcon.png" ) ;
82+ _instance . Items . Add ( jumplistItem ) ;
83+ JumpListItemPaths . Add ( path ) ;
84+ }
85+
86+ return Task . CompletedTask ;
87+ }
88+
89+ public async void RemoveFolder ( string path )
90+ {
91+ if ( JumpListItemPaths . Contains ( path ) )
92+ {
93+ JumpListItemPaths . Remove ( path ) ;
94+ await UpdateAsync ( ) ;
95+ }
96+ }
97+
98+ private async Task UpdateAsync ( )
99+ {
100+ if ( _instance != null )
101+ {
102+ // Clear all items to avoid localization issues
103+ _instance ? . Items . Clear ( ) ;
104+
105+ foreach ( string path in JumpListItemPaths )
106+ {
107+ await AddFolder ( path ) ;
108+ }
109+
110+ await _instance . SaveAsync ( ) ;
111+ }
112+ }
113+ }
114+ }
0 commit comments