Skip to content

Fix: Fixed issue with pinning and unpinning shell items in Favorites #11967

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 17 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Files.App/DataModels/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public async void LoadAsync(object? sender, FileSystemEventArgs e)
{
App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false;
await LoadAsync();
App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(null, new ModifyQuickAccessEventArgs((await QuickAccessService.GetPinnedFoldersAsync()).Select(x => x.FilePath).ToArray(), true)
App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(null, new ModifyQuickAccessEventArgs((await QuickAccessService.GetPinnedFoldersAsync()).ToArray(), true)
{
Reset = true
});
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/CommonPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class CommonPaths

public static readonly string RecentItemsPath = Environment.GetFolderPath(Environment.SpecialFolder.Recent);

public static Dictionary<string, string> ShellPlaces = new Dictionary<string, string>() {
public static Dictionary<string, string> ShellPlaces = new() {
{ "::{645FF040-5081-101B-9F08-00AA002F954E}", RecycleBinPath },
{ "::{5E5F29CE-E0A8-49D3-AF32-7A7BDC173478}", "Home" /*MyComputerPath*/ },
{ "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", MyComputerPath },
Expand Down
32 changes: 14 additions & 18 deletions src/Files.App/ServicesImplementation/JumpListService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Files.App.Extensions;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Helpers;
using Files.Shared.Extensions;
Expand Down Expand Up @@ -109,8 +109,12 @@ private void AddFolder(string path, string group, JumpList instance)
{
if (instance is not null)
{
string displayName = null;
if (path.EndsWith("\\"))
string? displayName = null;

if (path.StartsWith("\\\\SHELL", StringComparison.OrdinalIgnoreCase))
displayName = "ThisPC".GetLocalizedResource();

if (path.EndsWith('\\'))
{
// 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();
Expand All @@ -128,6 +132,8 @@ private void AddFolder(string path, string group, JumpList instance)
displayName = "ms-resource:///Resources/Desktop";
else if (path.Equals(CommonPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase))
displayName = "ms-resource:///Resources/Downloads";
else if (path.Equals(CommonPaths.NetworkFolderPath, StringComparison.OrdinalIgnoreCase))
displayName = "Network".GetLocalizedResource();
else if (path.Equals(CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
displayName = "RecycleBin".GetLocalizedResource();
else if (path.Equals(CommonPaths.MyComputerPath, StringComparison.OrdinalIgnoreCase))
Expand All @@ -137,28 +143,18 @@ private void AddFolder(string path, string group, JumpList instance)
else if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library))
{
var libName = Path.GetFileNameWithoutExtension(library.Path);
switch (libName)
displayName = libName switch
{
case "Documents":
case "Pictures":
case "Music":
case "Videos":
// Use localized name
displayName = $"ms-resource:///Resources/{libName}";
break;

default:
// Use original name
displayName = library.Text;
break;
}
"Documents" or "Pictures" or "Music" or "Videos" => $"ms-resource:///Resources/{libName}",// Use localized name
_ => library.Text,// Use original name
};
}
else
displayName = Path.GetFileName(path);
}

var jumplistItem = JumpListItem.CreateWithArguments(path, displayName);
jumplistItem.Description = jumplistItem.Arguments;
jumplistItem.Description = jumplistItem.Arguments ?? string.Empty;
jumplistItem.GroupName = group;
jumplistItem.Logo = new Uri("ms-appx:///Assets/FolderIcon.png");

Expand Down
23 changes: 20 additions & 3 deletions src/Files.App/ServicesImplementation/QuickAccessService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Files.App.Helpers;
using Files.App.Filesystem.StorageItems;
using Files.App.Helpers;
using Files.App.Shell;
using Files.App.UserControls.Widgets;
using Files.Shared;
using Files.Shared.Extensions;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Input;

namespace Files.App.ServicesImplementation
{
Expand Down Expand Up @@ -53,8 +56,22 @@ public async Task UnpinFromSidebar(string[] folderPaths)

foreach (dynamic? fi in f2.Items())
{
if (folderPaths.Contains((string)fi.Path)
|| (string.Equals(fi.Path, "::{645FF040-5081-101B-9F08-00AA002F954E}") && folderPaths.Contains(CommonPaths.RecycleBinPath)))
if (ShellStorageFolder.IsShellPath((string)fi.Path))
{
var folder = await ShellStorageFolder.FromPathAsync((string)fi.Path);
var path = folder.Path;

if (folderPaths.Contains(path) || (path.StartsWith(@"\\SHELL\") && folderPaths.Any(x => x.StartsWith(@"\\SHELL\")))) // Fix for the Linux header
{
await SafetyExtensions.IgnoreExceptions(async () =>
{
await fi.InvokeVerb("unpinfromhome");
});
continue;
}
}

if (folderPaths.Contains((string)fi.Path))
{
await SafetyExtensions.IgnoreExceptions(async () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ await DispatcherQueue.EnqueueAsync(async () =>
{
var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
var lastIndex = ItemsAdded.IndexOf(ItemsAdded.FirstOrDefault(x => !x.IsPinned));
var isPinned = (bool?)e.Items.Where(x => x.FilePath == itemToAdd).FirstOrDefault().Properties["System.Home.IsPinned"] ?? false;
var isPinned = (bool?)e.Items.Where(x => x.FilePath == itemToAdd).FirstOrDefault()?.Properties["System.Home.IsPinned"] ?? false;

ItemsAdded.Insert(isPinned && lastIndex >= 0 ? lastIndex : ItemsAdded.Count, new FolderCardItem(item, Path.GetFileName(item.Text), isPinned)
{
Expand Down