1
1
using Files . App . Filesystem ;
2
+ using Files . App . UserControls . Widgets ;
2
3
using Files . Shared . Extensions ;
3
4
using System ;
4
5
using System . Collections . Generic ;
@@ -14,6 +15,8 @@ public sealed class JumpListManager
14
15
{
15
16
private JumpList instance = null ;
16
17
private List < string > JumpListItemPaths { get ; set ; }
18
+ private readonly string JumpListRecentGroupHeader = "ms-resource:///Resources/JumpListRecentGroupHeader" ;
19
+ private readonly string JumpListPinnedGroupHeader = "ms-resource:///Resources/JumpListPinnedGroupHeader" ;
17
20
18
21
public JumpListManager ( )
19
22
{
@@ -27,6 +30,9 @@ public async Task InitializeAsync()
27
30
if ( JumpList . IsSupported ( ) )
28
31
{
29
32
instance = await JumpList . LoadCurrentAsync ( ) ;
33
+ App . QuickAccessManager . UpdateQuickAccessWidget += QuickAccessManager_DataChanged ;
34
+
35
+ QuickAccessManager_DataChanged ( null , null ) ;
30
36
31
37
// Disable automatic jumplist. It doesn't work with Files UWP.
32
38
instance . SystemGroupKind = JumpListSystemGroupKind . None ;
@@ -48,14 +54,14 @@ public async void AddFolderToJumpList(string path)
48
54
{
49
55
if ( instance is not null )
50
56
{
51
- AddFolder ( path ) ;
57
+ AddFolder ( path , JumpListRecentGroupHeader ) ;
52
58
await instance . SaveAsync ( ) ;
53
59
}
54
60
}
55
61
catch { }
56
62
}
57
63
58
- private void AddFolder ( string path )
64
+ private void AddFolder ( string path , string group )
59
65
{
60
66
if ( instance is not null )
61
67
{
@@ -65,9 +71,7 @@ private void AddFolder(string path)
65
71
// Jumplist item argument can't end with a slash so append a character that can't exist in a directory name to support listing drives.
66
72
var drive = App . DrivesManager . Drives . Where ( drive => drive . Path == path ) . FirstOrDefault ( ) ;
67
73
if ( drive is null )
68
- {
69
74
return ;
70
- }
71
75
72
76
displayName = drive . Text ;
73
77
path += '?' ;
@@ -76,13 +80,9 @@ private void AddFolder(string path)
76
80
if ( displayName is null )
77
81
{
78
82
if ( path . Equals ( CommonPaths . DesktopPath , StringComparison . OrdinalIgnoreCase ) )
79
- {
80
83
displayName = "ms-resource:///Resources/Desktop" ;
81
- }
82
84
else if ( path . Equals ( CommonPaths . DownloadsPath , StringComparison . OrdinalIgnoreCase ) )
83
- {
84
85
displayName = "ms-resource:///Resources/Downloads" ;
85
- }
86
86
else if ( path . Equals ( CommonPaths . RecycleBinPath , StringComparison . OrdinalIgnoreCase ) )
87
87
{
88
88
var localSettings = ApplicationData . Current . LocalSettings ;
@@ -108,21 +108,28 @@ private void AddFolder(string path)
108
108
}
109
109
}
110
110
else
111
- {
112
111
displayName = Path . GetFileName ( path ) ;
113
- }
114
112
}
115
113
116
114
var jumplistItem = JumpListItem . CreateWithArguments ( path , displayName ) ;
117
115
jumplistItem . Description = jumplistItem . Arguments ;
118
- jumplistItem . GroupName = "ms-resource:///Resources/JumpListRecentGroupHeader" ;
116
+ jumplistItem . GroupName = group ;
119
117
jumplistItem . Logo = new Uri ( "ms-appx:///Assets/FolderIcon.png" ) ;
120
118
121
- // Keep newer items at the top.
122
- instance . Items . Remove ( instance . Items . FirstOrDefault ( x => x . Arguments . Equals ( path , StringComparison . OrdinalIgnoreCase ) ) ) ;
123
- instance . Items . Insert ( 0 , jumplistItem ) ;
124
- JumpListItemPaths . Remove ( JumpListItemPaths . FirstOrDefault ( x => x . Equals ( path , StringComparison . OrdinalIgnoreCase ) ) ) ;
125
- JumpListItemPaths . Add ( path ) ;
119
+ if ( string . Equals ( group , JumpListRecentGroupHeader , StringComparison . OrdinalIgnoreCase ) )
120
+ {
121
+ // Keep newer items at the top.
122
+ instance . Items . Remove ( instance . Items . FirstOrDefault ( x => x . Arguments . Equals ( path , StringComparison . OrdinalIgnoreCase ) ) ) ;
123
+ instance . Items . Insert ( 0 , jumplistItem ) ;
124
+
125
+ JumpListItemPaths . Remove ( JumpListItemPaths . FirstOrDefault ( x => x . Equals ( path , StringComparison . OrdinalIgnoreCase ) ) ) ;
126
+ JumpListItemPaths . Add ( path ) ;
127
+ }
128
+ else
129
+ {
130
+ var pinnedItemsCount = instance . Items . Where ( x => x . GroupName == JumpListPinnedGroupHeader ) . Count ( ) ;
131
+ instance . Items . Insert ( pinnedItemsCount , jumplistItem ) ;
132
+ }
126
133
}
127
134
}
128
135
@@ -133,9 +140,7 @@ public async void RemoveFolder(string path)
133
140
try
134
141
{
135
142
if ( instance is null )
136
- {
137
143
return ;
138
- }
139
144
140
145
if ( JumpListItemPaths . Remove ( path ) )
141
146
{
@@ -146,5 +151,16 @@ public async void RemoveFolder(string path)
146
151
}
147
152
catch { }
148
153
}
154
+
155
+ private async void QuickAccessManager_DataChanged ( object sender , ModifyQuickAccessEventArgs e )
156
+ {
157
+ if ( instance is null )
158
+ return ;
159
+
160
+ var itemsToRemove = instance . Items . Where ( x => string . Equals ( x . GroupName , JumpListPinnedGroupHeader , StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
161
+ itemsToRemove . ForEach ( x => instance . Items . Remove ( x ) ) ;
162
+ App . QuickAccessManager . Model . FavoriteItems . ForEach ( x => AddFolder ( x , JumpListPinnedGroupHeader ) ) ;
163
+ await instance . SaveAsync ( ) ;
164
+ }
149
165
}
150
166
}
0 commit comments