Skip to content

Commit fb209b0

Browse files
authored
Improved taskbar jumplist (#7141)
1 parent dcd056e commit fb209b0

File tree

2 files changed

+60
-34
lines changed

2 files changed

+60
-34
lines changed

src/Files/Helpers/JumpListManager.cs

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,51 +57,71 @@ public async void AddFolderToJumpList(string path)
5757

5858
private void AddFolder(string path)
5959
{
60-
if (instance != null && !JumpListItemPaths.Contains(path))
60+
if (instance != null)
6161
{
62-
string displayName;
63-
if (path.Equals(CommonPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
64-
{
65-
displayName = "ms-resource:///Resources/Desktop";
66-
}
67-
else if (path.Equals(CommonPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase))
68-
{
69-
displayName = "ms-resource:///Resources/Downloads";
70-
}
71-
else if (path.Equals(CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
62+
string displayName = null;
63+
if (path.EndsWith("\\"))
7264
{
73-
var localSettings = ApplicationData.Current.LocalSettings;
74-
displayName = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin");
65+
// 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+
var drive = App.DrivesManager.Drives.Where(drive => drive.Path == path).FirstOrDefault();
67+
if (drive == null)
68+
{
69+
return;
70+
}
71+
72+
displayName = drive.Text;
73+
path += '?';
7574
}
76-
else if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library))
75+
76+
if (displayName == null)
7777
{
78-
var libName = Path.GetFileNameWithoutExtension(library.Path);
79-
switch (libName)
78+
if (path.Equals(CommonPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
79+
{
80+
displayName = "ms-resource:///Resources/SidebarDesktop";
81+
}
82+
else if (path.Equals(CommonPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase))
83+
{
84+
displayName = "ms-resource:///Resources/SidebarDownloads";
85+
}
86+
else if (path.Equals(CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
87+
{
88+
var localSettings = ApplicationData.Current.LocalSettings;
89+
displayName = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin");
90+
}
91+
else if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library))
8092
{
81-
case "Documents":
82-
case "Pictures":
83-
case "Music":
84-
case "Videos":
85-
// Use localized name
86-
displayName = $"ms-resource:///Resources/Sidebar{libName}";
87-
break;
93+
var libName = Path.GetFileNameWithoutExtension(library.Path);
94+
switch (libName)
95+
{
96+
case "Documents":
97+
case "Pictures":
98+
case "Music":
99+
case "Videos":
100+
// Use localized name
101+
displayName = $"ms-resource:///Resources/Sidebar{libName}";
102+
break;
88103

89-
default:
90-
// Use original name
91-
displayName = library.Text;
92-
break;
104+
default:
105+
// Use original name
106+
displayName = library.Text;
107+
break;
108+
}
109+
}
110+
else
111+
{
112+
displayName = Path.GetFileName(path);
93113
}
94-
}
95-
else
96-
{
97-
displayName = Path.GetFileName(path);
98114
}
99115

100116
var jumplistItem = JumpListItem.CreateWithArguments(path, displayName);
101117
jumplistItem.Description = jumplistItem.Arguments;
102118
jumplistItem.GroupName = "ms-resource:///Resources/JumpListRecentGroupHeader";
103119
jumplistItem.Logo = new Uri("ms-appx:///Assets/FolderIcon.png");
104-
instance.Items.Add(jumplistItem);
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+
JumpListItemPaths.Remove(JumpListItemPaths.FirstOrDefault(x => x.Equals(path, StringComparison.OrdinalIgnoreCase)));
105125
JumpListItemPaths.Add(path);
106126
}
107127
}
@@ -139,4 +159,4 @@ private async Task RefreshAsync()
139159
}
140160
}
141161
}
142-
}
162+
}

src/Files/ViewModels/MainPageViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ public static async Task AddNewTabByPathAsync(Type type, string path, int atInde
182182
path = "Home".GetLocalized();
183183
}
184184

185+
// Support drives launched through jump list by stripping away the question mark at the end.
186+
if (path.EndsWith("\\?"))
187+
{
188+
path = path.Remove(path.Length - 1);
189+
}
190+
185191
TabItem tabItem = new TabItem()
186192
{
187193
Header = null,
@@ -515,4 +521,4 @@ public static async void Control_ContentChanged(object sender, TabItemArguments
515521
await UpdateTabInfo(matchingTabItem, e.NavigationArg);
516522
}
517523
}
518-
}
524+
}

0 commit comments

Comments
 (0)