Skip to content
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

Feature: Recycle Bin changing icons in the side bar #10113

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
78cb382
Sidebar now loads an icon for empty and filled recycle bin.
QuaintMako Sep 23, 2022
3b190f1
Recycle Bin Helpers now offer a method to retrieve the adapted recycl…
QuaintMako Sep 23, 2022
ffcdccc
Ordered image res in value order.
QuaintMako Sep 24, 2022
9fe3f7c
Moved RetrieveAdaptedRecycleBinIcon in a more adapted class.
QuaintMako Sep 25, 2022
0067b32
Eliminated NPR warnings.
QuaintMako Sep 25, 2022
facacc9
Extracted a if to remove redundancy
QuaintMako Sep 25, 2022
6f4ff9d
Extracted and simplified method to retrieve icon data.
QuaintMako Sep 25, 2022
c0cd9c3
Reworked locationItem.IsInvalid evaluation.
QuaintMako Sep 25, 2022
7717072
Merge branch 'files-community:main' into 9195_DifferentIconSideBarRec…
QuaintMako Sep 28, 2022
aa18a4f
Now retrieving the correct recycle bin icon when adding it to the sid…
QuaintMako Sep 28, 2022
df88672
An event is now raised when the recycle bin is modified.
QuaintMako Sep 28, 2022
5f7e8ef
Refactored the creation of sidebar sections.
QuaintMako Sep 28, 2022
aadac84
Merge branch '9195_DifferentIconSideBarRecycleBinState' of https://gi…
QuaintMako Sep 28, 2022
72efbe3
Merge branch 'files-community:main' into 9195_DifferentIconSideBarRec…
QuaintMako Sep 30, 2022
ac395c3
Revert "Refactored the creation of sidebar sections."
QuaintMako Sep 30, 2022
d7fe441
Sidebar recycle bin icon now updates after using restore and empty ac…
QuaintMako Oct 3, 2022
4279f2d
Recycle bin changes are now notified in the FileSystemHelpers.
QuaintMako Oct 3, 2022
f659904
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 3, 2022
1f3c2ec
Brought the modifications that were overlooked to simplify last merge.
QuaintMako Oct 3, 2022
0fe3b19
Fixed some tabulation issues.
QuaintMako Oct 3, 2022
08fe06f
Fixed some tabulation issues.
QuaintMako Oct 3, 2022
06766d6
Fixed some tabulation issues.
QuaintMako Oct 3, 2022
931768e
Removed SingleItem load icon, as it was deemed useless.
QuaintMako Oct 6, 2022
61b1287
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 6, 2022
db44a48
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 6, 2022
8b7c9ee
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 7, 2022
8bc21f2
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 12, 2022
d78cf52
Moved a test statement in an upper function.
QuaintMako Oct 12, 2022
3eb2d23
Modified the RaiseRecycleBinChangedEvent method to use ? operator.
QuaintMako Oct 12, 2022
cb89ba3
Made linq request into a foreach loop.
QuaintMako Oct 12, 2022
40ef8b8
Now correctly disposing of RecycleBinChanged event listener.
QuaintMako Oct 12, 2022
abd8775
Made RecycleBinHelpers a static class.
QuaintMako Oct 12, 2022
d1042ca
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 15, 2022
ad402df
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 16, 2022
e898abf
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 19, 2022
4e7a95e
Merge branch 'main' into 9195_DifferentIconSideBarRecycleBinState
QuaintMako Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Files.App/BaseLayout.cs
Expand Up @@ -1021,15 +1021,13 @@ protected void FileListItem_RightTapped(object sender, RightTappedRoutedEventArg
ItemManipulationModel.SetSelectedItem(rightClickedItem);
}

private readonly RecycleBinHelpers recycleBinHelpers = new();

protected void InitializeDrag(UIElement containter, ListedItem item)
{
if (item is null)
return;

UninitializeDrag(containter);
if ((item.PrimaryItemAttribute == StorageItemTypes.Folder && !recycleBinHelpers.IsPathUnderRecycleBin(item.ItemPath)) || item.IsExecutable)
if ((item.PrimaryItemAttribute == StorageItemTypes.Folder && !RecycleBinHelpers.IsPathUnderRecycleBin(item.ItemPath)) || item.IsExecutable)
{
containter.AllowDrop = true;
containter.DragOver += Item_DragOver;
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Constants.cs
Expand Up @@ -28,7 +28,6 @@ public static class KnownImageFormats
{
public const string BITMAP_IMAGE_FORMAT = "bitmapimage";
}

public static class ImageRes
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
// See imageres.dll for more icon indexes to add
Expand All @@ -43,7 +42,8 @@ public static class ImageRes
public const int WindowsDrive = 36;
public const int ThisPC = 109;
public const int NetworkDrives = 25;
public const int RecycleBin = 55;
public const int RecycleBin = 54;
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
public const int EmptyRecycleBin = 55;
public const int CloudDrives = 1040;
public const int OneDrive = 1043;
public const int Libraries = 1023;
Expand Down
30 changes: 20 additions & 10 deletions src/Files.App/DataModels/SidebarPinnedModel.cs
Expand Up @@ -3,6 +3,7 @@
using Files.App.Controllers;
using Files.App.DataModels.NavigationControlItems;
using Files.App.Filesystem;
using Files.App.Filesystem.StorageItems;
using Files.App.Helpers;
using Files.Backend.Services.Settings;
using System;
Expand Down Expand Up @@ -229,22 +230,23 @@ public async Task AddItemToSidebarAsync(string path)
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
};

locationItem.IsInvalid = res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path);

if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path))
{
locationItem.IsInvalid = false;
if (res)
if (locationItem.Path == CommonPaths.RecycleBinPath)
{
var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 96u, ThumbnailMode.ListView);
locationItem.IconData = iconData;
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync());
int recycleBinIconIndex = UIHelpers.GetAdaptedRecycleBinIconIndex();
locationItem.IconData = UIHelpers.GetIconResourceInfo(recycleBinIconIndex).IconData;
}

if (locationItem.IconData == null)
else if (res)
{
locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 96u);
locationItem.IconData = await RetrieveItemIconData(path, res);
}

if (locationItem.IconData != null)
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync());
if (locationItem.IconData != null)
{
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync());
}
}
else
Expand All @@ -257,6 +259,14 @@ public async Task AddItemToSidebarAsync(string path)
AddLocationItemToSidebar(locationItem);
}

private async Task<byte[]?> RetrieveItemIconData(string itemPath, FilesystemResult<BaseStorageFolder> result)
{
byte[]? iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(result.Result, 24u, Windows.Storage.FileProperties.ThumbnailMode.ListView);
iconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(itemPath, 24u);

return iconData;
}

/// <summary>
/// Adds the location item to the navigation sidebar
/// </summary>
Expand Down
Expand Up @@ -33,14 +33,11 @@ public class FilesystemOperations : IFilesystemOperations

private IShellPage associatedInstance;

private RecycleBinHelpers recycleBinHelpers;

#region Constructor

public FilesystemOperations(IShellPage associatedInstance)
{
this.associatedInstance = associatedInstance;
recycleBinHelpers = new RecycleBinHelpers();
}

#endregion Constructor
Expand Down Expand Up @@ -495,7 +492,7 @@ private ContentDialog SetContentDialogRoot(ContentDialog contentDialog)
bool permanently,
CancellationToken cancellationToken)
{
bool deleteFromRecycleBin = recycleBinHelpers.IsPathUnderRecycleBin(source.Path);
bool deleteFromRecycleBin = RecycleBinHelpers.IsPathUnderRecycleBin(source.Path);

FilesystemResult fsResult = FileSystemStatusCode.InProgress;

Expand Down Expand Up @@ -549,7 +546,7 @@ await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
if (!permanently)
{
// Enumerate Recycle Bin
IEnumerable<ShellFileItem> nameMatchItems, items = await recycleBinHelpers.EnumerateRecycleBin();
IEnumerable<ShellFileItem> nameMatchItems, items = await RecycleBinHelpers.EnumerateRecycleBin();

// Get name matching files
if (Path.GetExtension(source.Path) == ".lnk" || Path.GetExtension(source.Path) == ".url") // We need to check if it is a shortcut file
Expand Down Expand Up @@ -861,7 +858,6 @@ private static async Task<BaseStorageFolder> MoveDirectoryAsync(BaseStorageFolde

public void Dispose()
{
recycleBinHelpers = null;
associatedInstance = null;
}

Expand Down Expand Up @@ -964,7 +960,7 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
break;
}

if (recycleBinHelpers.IsPathUnderRecycleBin(source[i].Path))
if (RecycleBinHelpers.IsPathUnderRecycleBin(source[i].Path))
{
permanently = true;
}
Expand Down
Expand Up @@ -37,8 +37,6 @@ public class FilesystemHelpers : IFilesystemHelpers

private ItemManipulationModel itemManipulationModel => associatedInstance.SlimContentPage?.ItemManipulationModel;

private RecycleBinHelpers recycleBinHelpers;

private readonly CancellationToken cancellationToken;

private Task<NamedPipeAsAppServiceConnection> ServiceConnection => AppServiceConnectionHelper.Instance;
Expand Down Expand Up @@ -87,7 +85,6 @@ public FilesystemHelpers(IShellPage associatedInstance, CancellationToken cancel
this.associatedInstance = associatedInstance;
this.cancellationToken = cancellationToken;
this.filesystemOperations = new ShellFilesystemOperations(this.associatedInstance);
this.recycleBinHelpers = new RecycleBinHelpers();
}

#endregion Constructor
Expand Down Expand Up @@ -123,18 +120,18 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat

var returnStatus = ReturnResult.InProgress;

var deleteFromRecycleBin = source.Select(item => item.Path).Any(path => recycleBinHelpers.IsPathUnderRecycleBin(path));
var canBeSentToBin = !deleteFromRecycleBin && await recycleBinHelpers.HasRecycleBin(source.FirstOrDefault()?.Path);
var deleteFromRecycleBin = source.Select(item => item.Path).Any(path => RecycleBinHelpers.IsPathUnderRecycleBin(path));
var canBeSentToBin = !deleteFromRecycleBin && await RecycleBinHelpers.HasRecycleBin(source.FirstOrDefault()?.Path);

if (((!permanently && !canBeSentToBin) || UserSettingsService.PreferencesSettingsService.ShowConfirmDeleteDialog) && showDialog) // Check if the setting to show a confirmation dialog is on
{
var incomingItems = new List<BaseFileSystemDialogItemViewModel>();
List<ShellFileItem> binItems = null;
foreach (var src in source)
{
if (recycleBinHelpers.IsPathUnderRecycleBin(src.Path))
if (RecycleBinHelpers.IsPathUnderRecycleBin(src.Path))
{
binItems ??= await recycleBinHelpers.EnumerateRecycleBin();
binItems ??= await RecycleBinHelpers.EnumerateRecycleBin();
if (!binItems.IsEmpty()) // Might still be null because we're deserializing the list from Json
{
var matchingItem = binItems.FirstOrDefault(x => x.RecyclePath == src.Path); // Get original file name
Expand Down Expand Up @@ -190,6 +187,7 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
sw.Stop();

PostBannerHelpers.PostBanner_Delete(source, returnStatus, permanently, token.IsCancellationRequested, itemsDeleted);
RecycleBinHelpers.RaiseRecycleBinChangedEvent();

return returnStatus;
}
Expand Down Expand Up @@ -239,6 +237,8 @@ public async Task<ReturnResult> RestoreItemsFromTrashAsync(IEnumerable<IStorageI

sw.Stop();

RecycleBinHelpers.RaiseRecycleBinChangedEvent();

return returnStatus;
}

Expand Down Expand Up @@ -385,9 +385,9 @@ public async Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageVi
List<ShellFileItem> binItems = null;
foreach (var item in source)
{
if (recycleBinHelpers.IsPathUnderRecycleBin(item.Path))
if (RecycleBinHelpers.IsPathUnderRecycleBin(item.Path))
{
binItems ??= await recycleBinHelpers.EnumerateRecycleBin();
binItems ??= await RecycleBinHelpers.EnumerateRecycleBin();
if (!binItems.IsEmpty()) // Might still be null because we're deserializing the list from Json
{
var matchingItem = binItems.FirstOrDefault(x => x.RecyclePath == item.Path); // Get original file name
Expand Down Expand Up @@ -532,9 +532,9 @@ public async Task<ReturnResult> MoveItemsFromClipboard(DataPackageView packageVi
List<ShellFileItem> binItems = null;
foreach (var item in source)
{
if (recycleBinHelpers.IsPathUnderRecycleBin(item.Path))
if (RecycleBinHelpers.IsPathUnderRecycleBin(item.Path))
{
binItems ??= await recycleBinHelpers.EnumerateRecycleBin();
binItems ??= await RecycleBinHelpers.EnumerateRecycleBin();
if (!binItems.IsEmpty()) // Might still be null because we're deserializing the list from Json
{
var matchingItem = binItems.FirstOrDefault(x => x.RecyclePath == item.Path); // Get original file name
Expand Down Expand Up @@ -668,7 +668,7 @@ public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packag

ReturnResult returnStatus = ReturnResult.InProgress;

source = source.Where(x => !recycleBinHelpers.IsPathUnderRecycleBin(x.Path)); // Can't recycle items already in recyclebin
source = source.Where(x => !RecycleBinHelpers.IsPathUnderRecycleBin(x.Path)); // Can't recycle items already in recyclebin
returnStatus = await DeleteItemsAsync(source, showDialog, false, registerHistory);

return returnStatus;
Expand Down Expand Up @@ -852,7 +852,6 @@ public void Dispose()

associatedInstance = null;
filesystemOperations = null;
recycleBinHelpers = null;
}

#endregion IDisposable
Expand Down
Expand Up @@ -31,8 +31,6 @@ public class ShellFilesystemOperations : IFilesystemOperations

private FilesystemOperations filesystemOperations;

private RecycleBinHelpers recycleBinHelpers;

private IDialogService DialogService { get; } = Ioc.Default.GetRequiredService<IDialogService>();

private readonly JsonElement defaultJson = JsonSerializer.SerializeToElement("{}");
Expand All @@ -45,7 +43,6 @@ public ShellFilesystemOperations(IShellPage associatedInstance)
{
this.associatedInstance = associatedInstance;
filesystemOperations = new FilesystemOperations(associatedInstance);
recycleBinHelpers = new RecycleBinHelpers();
}

#endregion Constructor
Expand Down Expand Up @@ -335,7 +332,7 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
}

var deleleFilePaths = source.Select(s => s.Path).Distinct();
var deleteFromRecycleBin = source.Any() ? recycleBinHelpers.IsPathUnderRecycleBin(source.ElementAt(0).Path) : false;
var deleteFromRecycleBin = source.Any() ? RecycleBinHelpers.IsPathUnderRecycleBin(source.ElementAt(0).Path) : false;
permanently |= deleteFromRecycleBin;

if (deleteFromRecycleBin)
Expand Down Expand Up @@ -809,9 +806,9 @@ private async Task<DialogResult> GetFileListDialog(IEnumerable<string> source, s
List<ShellFileItem> binItems = null;
foreach (var src in source)
{
if (recycleBinHelpers.IsPathUnderRecycleBin(src))
if (RecycleBinHelpers.IsPathUnderRecycleBin(src))
{
binItems ??= await recycleBinHelpers.EnumerateRecycleBin();
binItems ??= await RecycleBinHelpers.EnumerateRecycleBin();
if (!binItems.IsEmpty()) // Might still be null because we're deserializing the list from Json
{
var matchingItem = binItems.FirstOrDefault(x => x.RecyclePath == src); // Get original file name
Expand Down Expand Up @@ -842,7 +839,6 @@ public void Dispose()
filesystemOperations?.Dispose();

filesystemOperations = null;
recycleBinHelpers = null;
associatedInstance = null;
}

Expand Down