Skip to content

Feature: Show size when hovering over recycling bin #10904

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 32 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d9f6acb
Save changes
hecksmosis Dec 30, 2022
e1a8267
Save changes
hecksmosis Dec 31, 2022
5731b85
Merge branch 'main' of https://github.com/files-community/Files into …
hecksmosis Dec 31, 2022
aed1503
save more changes
hecksmosis Jan 1, 2023
5688928
save more changes
hecksmosis Jan 1, 2023
5c346bb
Display recycle bin size in tooltip
hecksmosis Jan 2, 2023
ae350f5
Fix conflicts
hecksmosis Jan 2, 2023
a70b5b1
Refresh in file watcher
hecksmosis Jan 2, 2023
8f9a13e
Update Win32StorageEnumerator.cs
hecksmosis Jan 2, 2023
11aae4e
Update FolderHelpers.cs
hecksmosis Jan 2, 2023
4996838
Update UniversalStorageEnumerator.cs
hecksmosis Jan 2, 2023
4ffccaa
Update Win32StorageEnumerator.cs
hecksmosis Jan 2, 2023
f21dcc8
Update SidebarViewModel.cs
hecksmosis Jan 2, 2023
2989a54
Minor fixes
hecksmosis Jan 2, 2023
4028088
Remove changes to the sidebar
hecksmosis Jan 2, 2023
a6d33c1
Update SidebarControl.xaml.cs
hecksmosis Jan 2, 2023
5f379d2
Remove debug Logger call
hecksmosis Jan 2, 2023
17e2efd
Some refactoring
hecksmosis Jan 3, 2023
5dad5fc
Requested changes
hecksmosis Jan 3, 2023
8def1bb
Revert changes to RecycleBinManager
hecksmosis Jan 3, 2023
533f92e
Requested Changes
hecksmosis Jan 3, 2023
f6f7e4a
Fix spacing
hecksmosis Jan 3, 2023
052704c
Fix spacing
hecksmosis Jan 3, 2023
dba1f69
Merge branch 'main' into recyclebinsize
hecksmosis Jan 4, 2023
77b09c3
Fixed indent
QuaintMako Jan 4, 2023
1a04bf6
Fixed indent
QuaintMako Jan 4, 2023
efc6c25
Merge branch 'main' into recyclebinsize
yaira2 Jan 4, 2023
4dad6b7
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 Jan 8, 2023
288ee4d
Minor changes
gave92 Jan 8, 2023
a183906
Update LocationItem.cs
hecksmosis Jan 8, 2023
e2be6f3
Update Resources.resw
hecksmosis Jan 8, 2023
ca90155
Merge branch 'main' into recyclebinsize
yaira2 Jan 9, 2023
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
42 changes: 40 additions & 2 deletions src/Files.App/DataModels/NavigationControlItems/LocationItem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.WinUI;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Helpers;
using Files.App.Shell;
using Files.Shared;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using System;
using System.IO;
using System.Threading.Tasks;

namespace Files.App.DataModels.NavigationControlItems
{
Expand Down Expand Up @@ -36,7 +40,7 @@ public string Path
}
}

public string ToolTipText { get; private set; }
public virtual string ToolTipText { get; set; }
public FontFamily Font { get; set; }
public NavigationControlItemType ItemType => NavigationControlItemType.Location;
public bool IsDefaultLocation { get; set; }
Expand All @@ -58,5 +62,39 @@ public bool IsExpanded
public ContextMenuOptions MenuOptions { get; set; }

public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);

public static T Create<T>() where T : LocationItem, new()
{
return new T();
}
}

public class RecycleBinLocationItem : LocationItem
{
public void RefreshSpaceUsed(object sender, FileSystemEventArgs e)
{
SpaceUsed = RecycleBinHelpers.GetSize();
}

private ulong spaceUsed;
public ulong SpaceUsed
{
get => spaceUsed;
set
{
SetProperty(ref spaceUsed, value);
App.Window.DispatcherQueue.EnqueueAsync(() => OnPropertyChanged(nameof(ToolTipText)));
}
}

public override string ToolTipText => SpaceUsed.ToSizeString();

public RecycleBinLocationItem()
{
SpaceUsed = RecycleBinHelpers.GetSize();

RecycleBinManager.Default.RecycleBinItemCreated += RefreshSpaceUsed;
RecycleBinManager.Default.RecycleBinItemDeleted += RefreshSpaceUsed;
}
}
}
}
34 changes: 19 additions & 15 deletions src/Files.App/DataModels/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,27 @@ public async Task AddItemToSidebarAsync(string path)
{
var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));
var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item));
var locationItem = new LocationItem
LocationItem locationItem;

if (string.Equals(path, CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
locationItem = LocationItem.Create<RecycleBinLocationItem>();
else
locationItem = LocationItem.Create<LocationItem>();

locationItem.Font = App.AppModel.SymbolFontFamily;
locationItem.Path = path;
locationItem.Section = SectionType.Favorites;
locationItem.MenuOptions = new ContextMenuOptions
{
Font = App.AppModel.SymbolFontFamily,
Path = path,
Section = SectionType.Favorites,
MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
ShowProperties = true,
ShowUnpinItem = true,
ShowShellItems = true,
ShowEmptyRecycleBin = path == CommonPaths.RecycleBinPath,
},
IsDefaultLocation = false,
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
IsLocationItem = true,
ShowProperties = true,
ShowUnpinItem = true,
ShowShellItems = true,
ShowEmptyRecycleBin = string.Equals(path, CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase)
};

locationItem.IsDefaultLocation = false;
locationItem.Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'));

if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path))
{
locationItem.IsInvalid = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,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 (FileExtensionHelpers.IsShortcutOrUrlFile(source.Path)) // We need to check if it is a shortcut file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
{
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 @@ -376,7 +376,7 @@ public async Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageVi
{
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 @@ -521,7 +521,7 @@ public async Task<ReturnResult> MoveItemsFromClipboard(DataPackageView packageVi
{
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
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
{
var sourceMatch = await recycledSources.Select(x => source.DistinctBy(x => x.Path)
.SingleOrDefault(s => s.Path.Equals(x.Source, StringComparison.OrdinalIgnoreCase))).Where(x => x is not null).ToListAsync();

return new StorageHistory(FileOperationType.Recycle,
sourceMatch,
await recycledSources.Zip(sourceMatch, (rSrc, oSrc) => new { rSrc, oSrc })
Expand Down Expand Up @@ -669,6 +670,7 @@ public async Task<IStorageHistory> RestoreItemsFromTrashAsync(IList<IStorageItem
.Select(src => StorageHelpers.FromPathAndType(
Path.Combine(Path.GetDirectoryName(src.rSrc.Source), Path.GetFileName(src.rSrc.Source).Replace("$R", "$I", StringComparison.Ordinal)),
src.oSrc.ItemType)).ToListAsync(), null, true, cancellationToken);

return new StorageHistory(FileOperationType.Restore,
sourceMatch,
await movedSources.Zip(sourceMatch, (rSrc, oSrc) => new { rSrc, oSrc })
Expand Down Expand Up @@ -748,7 +750,7 @@ private async Task<DialogResult> GetFileListDialog(IEnumerable<string> source, s
{
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
8 changes: 7 additions & 1 deletion src/Files.App/Helpers/RecycleBinHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Files.App.DataModels.NavigationControlItems;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Shell;
Expand All @@ -22,11 +23,16 @@ public class RecycleBinHelpers

#endregion Private Members

public async Task<List<ShellFileItem>> EnumerateRecycleBin()
public static async Task<List<ShellFileItem>> EnumerateRecycleBin()
{
return (await Win32Shell.GetShellFolderAsync(CommonPaths.RecycleBinPath, "Enumerate", 0, int.MaxValue)).Enumerate;
}

public static ulong GetSize()
{
return (ulong)Win32Shell.QueryRecycleBin().BinSize;
}

public async Task<bool> IsRecycleBinItem(IStorageItem item)
{
List<ShellFileItem> recycleBinItems = await EnumerateRecycleBin();
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/UserControls/SidebarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
RightTapped="NavigationViewItem_RightTapped"
SelectsOnInvoked="{x:Bind SelectsOnInvoked}"
Tag="{x:Bind Path}"
ToolTipService.ToolTip="{x:Bind ToolTipText}">
ToolTipService.ToolTip="{x:Bind ToolTipText, Mode=OneWay}">
<NavigationViewItem.Icon>
<ImageIcon Source="{x:Bind Icon, Mode=OneWay}" />
</NavigationViewItem.Icon>
Expand Down Expand Up @@ -1188,6 +1188,6 @@
DriveNavItemTemplate="{StaticResource DriveNavItem}"
FileTagNavItemTemplate="{StaticResource FileTagNavItem}"
LinuxNavItemTemplate="{StaticResource LinuxNavItem}"
LocationNavItemTemplate="{StaticResource LocationNavItem}" />
LocationNavItemTemplate="{StaticResource LocationNavItem}"/>
</NavigationView.MenuItemTemplateSelector>
</NavigationView>
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,4 +1233,4 @@ public class NavItemDataTemplateSelector : DataTemplateSelector
};
}
}
}
}
6 changes: 3 additions & 3 deletions src/Files.App/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public ItemViewModel(FolderSettingsViewModel folderSettingsViewModel)

private async void RecycleBinRefreshRequested(object sender, FileSystemEventArgs e)
{
if (@"Shell:RecycleBinFolder".Equals(CurrentFolder?.ItemPath, StringComparison.OrdinalIgnoreCase))
if (CommonPaths.RecycleBinPath.Equals(CurrentFolder?.ItemPath, StringComparison.OrdinalIgnoreCase))
{
await dispatcherQueue.EnqueueAsync(() =>
{
Expand All @@ -397,7 +397,7 @@ await dispatcherQueue.EnqueueAsync(() =>

private async void RecycleBinItemDeleted(object sender, FileSystemEventArgs e)
{
if (@"Shell:RecycleBinFolder".Equals(CurrentFolder?.ItemPath, StringComparison.OrdinalIgnoreCase))
if (CommonPaths.RecycleBinPath.Equals(CurrentFolder?.ItemPath, StringComparison.OrdinalIgnoreCase))
{
// get the item that immediately follows matching item to be removed
// if the matching item is the last item, try to get the previous item; otherwise, null
Expand All @@ -416,7 +416,7 @@ private async void RecycleBinItemDeleted(object sender, FileSystemEventArgs e)

private async void RecycleBinItemCreated(object sender, FileSystemEventArgs e)
{
if (@"Shell:RecycleBinFolder".Equals(CurrentFolder?.ItemPath, StringComparison.OrdinalIgnoreCase))
if (CommonPaths.RecycleBinPath.Equals(CurrentFolder?.ItemPath, StringComparison.OrdinalIgnoreCase))
{
using var folderItem = SafetyExtensions.IgnoreExceptions(() => new ShellItem(e.FullPath));
if (folderItem is null) return;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,4 +605,4 @@ public GridLength TabControlMargin
set => SetProperty(ref tabControlMargin, value);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Views/ColumnShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ private void FilesystemViewModel_ItemLoadStatusChanged(object sender, ItemLoadSt
// Select previous directory
if (!string.IsNullOrWhiteSpace(e.PreviousDirectory))
{
if (e.PreviousDirectory.Contains(e.Path, StringComparison.Ordinal) && !e.PreviousDirectory.Contains("Shell:RecycleBinFolder", StringComparison.Ordinal))
if (e.PreviousDirectory.Contains(e.Path, StringComparison.Ordinal) && !e.PreviousDirectory.Contains(CommonPaths.RecycleBinPath, StringComparison.Ordinal))
{
// Remove the WorkingDir from previous dir
e.PreviousDirectory = e.PreviousDirectory.Replace(e.Path, string.Empty, StringComparison.Ordinal);
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ private void FilesystemViewModel_ItemLoadStatusChanged(object sender, ItemLoadSt
// Select previous directory
if (!InstanceViewModel.IsPageTypeSearchResults && !string.IsNullOrWhiteSpace(e.PreviousDirectory))
{
if (e.PreviousDirectory.Contains(e.Path, StringComparison.Ordinal) && !e.PreviousDirectory.Contains("Shell:RecycleBinFolder", StringComparison.Ordinal))
if (e.PreviousDirectory.Contains(e.Path, StringComparison.Ordinal) && !e.PreviousDirectory.Contains(CommonPaths.RecycleBinPath, StringComparison.Ordinal))
{
// Remove the WorkingDir from previous dir
e.PreviousDirectory = e.PreviousDirectory.Replace(e.Path, string.Empty, StringComparison.Ordinal);
Expand Down