Skip to content

Improve taskbar jumplist #7141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 5, 2022
86 changes: 53 additions & 33 deletions src/Files/Helpers/JumpListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,51 +57,71 @@ public async void AddFolderToJumpList(string path)

private void AddFolder(string path)
{
if (instance != null && !JumpListItemPaths.Contains(path))
if (instance != null)
{
string displayName;
if (path.Equals(CommonPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
{
displayName = "ms-resource:///Resources/Desktop";
}
else if (path.Equals(CommonPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase))
{
displayName = "ms-resource:///Resources/Downloads";
}
else if (path.Equals(CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
string displayName = null;
if (path.EndsWith("\\"))
{
var localSettings = ApplicationData.Current.LocalSettings;
displayName = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin");
// 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.
var drive = App.DrivesManager.Drives.Where(drive => drive.Path == path).FirstOrDefault();
if (drive == null)
{
return;
}

displayName = drive.Text;
path += '?';
}
else if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library))

if (displayName == null)
{
var libName = Path.GetFileNameWithoutExtension(library.Path);
switch (libName)
if (path.Equals(CommonPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
{
displayName = "ms-resource:///Resources/SidebarDesktop";
}
else if (path.Equals(CommonPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase))
{
displayName = "ms-resource:///Resources/SidebarDownloads";
}
else if (path.Equals(CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
{
var localSettings = ApplicationData.Current.LocalSettings;
displayName = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin");
}
else if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library))
{
case "Documents":
case "Pictures":
case "Music":
case "Videos":
// Use localized name
displayName = $"ms-resource:///Resources/Sidebar{libName}";
break;
var libName = Path.GetFileNameWithoutExtension(library.Path);
switch (libName)
{
case "Documents":
case "Pictures":
case "Music":
case "Videos":
// Use localized name
displayName = $"ms-resource:///Resources/Sidebar{libName}";
break;

default:
// Use original name
displayName = library.Text;
break;
default:
// Use original name
displayName = library.Text;
break;
}
}
else
{
displayName = Path.GetFileName(path);
}
}
else
{
displayName = Path.GetFileName(path);
}

var jumplistItem = JumpListItem.CreateWithArguments(path, displayName);
jumplistItem.Description = jumplistItem.Arguments;
jumplistItem.GroupName = "ms-resource:///Resources/JumpListRecentGroupHeader";
jumplistItem.Logo = new Uri("ms-appx:///Assets/FolderIcon.png");
instance.Items.Add(jumplistItem);

// Keep newer items at the top.
instance.Items.Remove(instance.Items.FirstOrDefault(x => x.Arguments.Equals(path, StringComparison.OrdinalIgnoreCase)));
instance.Items.Insert(0, jumplistItem);
JumpListItemPaths.Remove(JumpListItemPaths.FirstOrDefault(x => x.Equals(path, StringComparison.OrdinalIgnoreCase)));
JumpListItemPaths.Add(path);
}
}
Expand Down Expand Up @@ -139,4 +159,4 @@ private async Task RefreshAsync()
}
}
}
}
}
8 changes: 7 additions & 1 deletion src/Files/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ public static async Task AddNewTabByPathAsync(Type type, string path, int atInde
path = "Home".GetLocalized();
}

// Support drives launched through jump list by stripping away the question mark at the end.
if (path.EndsWith("\\?"))
{
path = path.Remove(path.Length - 1);
}

TabItem tabItem = new TabItem()
{
Header = null,
Expand Down Expand Up @@ -515,4 +521,4 @@ public static async void Control_ContentChanged(object sender, TabItemArguments
await UpdateTabInfo(matchingTabItem, e.NavigationArg);
}
}
}
}