Skip to content

Code Quality: Continued working on Shelf Pane#17308

Open
d2dyno1 wants to merge 10 commits intofiles-community:mainfrom
d2dyno1:d2dyno/shelf_imp
Open

Code Quality: Continued working on Shelf Pane#17308
d2dyno1 wants to merge 10 commits intofiles-community:mainfrom
d2dyno1:d2dyno/shelf_imp

Conversation

@d2dyno1
Copy link
Member

@d2dyno1 d2dyno1 commented Jul 24, 2025

Resolved / Related Issues

This PR introduces minor changes, unless additional changes are requested. The file watcher was implemented quite some time ago and already works properly, thanks to #16900 and #16728. This PR focuses solely on re-enabling this feature, but can be iterated upon to accommodate any undocumented missing features (if any? - not that I'm aware of)

  • Re-enabled the command for showing the Shelf pane in production
  • Add a "Create link" menu option when dropping an item from the shelf to a folder
  • Add a delete bulk action
  • Add a copy and cut bulk actions
  • Add "View in parent folder" menu option
  • Fixed Shelf's file watcher reference counter logic

Steps used to test these changes

Stability is a top priority for Files and all changes are required to go through testing before being merged into the repo. Please include a list of steps that you used to test this PR.

  1. Opened Files
  2. Confirmed the action shows up appropriately
  3. Confirmed the menu and bulk actions work properly
  4. Confirmed that deleting two (or more) files from the same folder using the bulk delete action properly removes them from the Shelf

@d2dyno1 d2dyno1 marked this pull request as ready for review July 30, 2025 00:04
@yaira2
Copy link
Member

yaira2 commented Jul 30, 2025

@d2dyno1 thank you for the PR! We're not ready to enable this just yet as I still need to add the resize logic.

  • I noticed there are a few new buttons at the bottom of the pane, was this a deliberate change? The original spec had them placed in a context menu, but we never really talked this through. Curious to hear your thoughts.
  • Does the file watcher update the list if items are deleted or renamed externally?

Add "View in parent folder" menu option

This is a nice touch 🙂

@yaira2 yaira2 added the ready for review Pull requests that are ready for review label Jul 30, 2025
@yaira2 yaira2 changed the title Re-enable shelf action feature Code Quality: Continued working on Shelf Pane Jul 30, 2025
@d2dyno1
Copy link
Member Author

d2dyno1 commented Aug 1, 2025

@d2dyno1 thank you for the PR! We're not ready to enable this just yet as I still need to add the resize logic.

If time allows, I can add the resizing logic in this PR (borrowing it from the preview pane).


  • I noticed there are a few new buttons at the bottom of the pane, was this a deliberate change? The original spec had them placed in a context menu, but we never really talked this through. Curious to hear your thoughts.

The buttons were an inspiration from the original spec and I think they can stay for when we roll out the Shelf feature. We can gather feedback on them and the behavior can always be changed in the future. It's not set in stone 🙂


  • Does the file watcher update the list if items are deleted or renamed externally?

Yes, the implementation is based on FileSystemWatcher which does observe the changes across the file system.


Add "View in parent folder" menu option

This is a nice touch 🙂

😉 @yaira2

@yaira2
Copy link
Member

yaira2 commented Aug 4, 2025

If time allows, I can add the resizing logic in this PR (borrowing it from the preview pane).

That would be great, thanks! Aside from the actual resizing of the pane, there are other behaviors that I need to finalize such as smaller window sizes etc.

@yaira2
Copy link
Member

yaira2 commented Aug 4, 2025

Is renaming an item supposed to remove it from the list?

@mdtauk
Copy link
Contributor

mdtauk commented Aug 4, 2025

Where do you plan to put the open shelf toggle button?

@yaira2
Copy link
Member

yaira2 commented Aug 4, 2025

Where do you plan to put the open shelf toggle button?

It's next to the Status Center button.

@mdtauk
Copy link
Contributor

mdtauk commented Aug 4, 2025

Where do you plan to put the open shelf toggle button?

It's next to the Status Center button.

Thats fine, I was going to say we should avoid putting it into the toolbar, as those are kind of scoped to the view panes, and the shelf is separate from those.

@yaira2 yaira2 force-pushed the main branch 2 times, most recently from 97999e5 to 806f922 Compare September 9, 2025 21:12
@yaira2 yaira2 added changes requested Changes are needed for this pull request and removed ready for review Pull requests that are ready for review labels Nov 17, 2025
Comment on lines +20 to +25
if (statusCenterItem is not null)
{
statusCenterItem.Progress.EnumerationCompleted = true;
statusCenterItem.Progress.ItemsCount = items.Count;
statusCenterItem.Progress.ReportStatus(FileSystemStatusCode.InProgress);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The progress bar's total item count is set to 0, causing a division-by-zero exception when calculating progress for copy/cut operations with over 50 items.
Severity: CRITICAL

Suggested Fix

In TransferHelpers.cs on lines 23 and 96, change statusCenterItem.Progress.ItemsCount = items.Count; to statusCenterItem.Progress.ItemsCount = itemsCount; to use the variable that holds the correct total count.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/Files.App/Helpers/TransferHelpers.cs#L20-L25

Potential issue: In `ExecuteTransferAsync`, when handling more than 50 items, a status
center item is created. Its `Progress.ItemsCount` is incorrectly initialized to
`items.Count`, which is 0, instead of using the correct `itemsCount` variable. When the
progress is updated via `AddProcessedItemsCount(1)` and `Report()` is called, the
progress percentage calculation `(value.ProcessedItemsCount * 100.0 / value.ItemsCount)`
attempts to divide by zero. This will throw an exception and crash the application
during any copy or cut operation involving more than 50 items.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +36 to +40
var result = storable switch
{
IFile => await shellViewModel.GetFileFromPathAsync(storable.Id).OnSuccess(x => items.Add(x)),
IFolder => await shellViewModel.GetFolderFromPathAsync(storable.Id).OnSuccess(x => items.Add(x)),
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The switch expression in ExecuteTransferAsync lacks a default case, which will cause a SwitchExpressionException if an item is neither an IFile nor an IFolder.
Severity: MEDIUM

Suggested Fix

Add a default case to the switch expression to handle unexpected types. For consistency with BulkDeleteAsync, consider throwing an ArgumentOutOfRangeException, for example: _ => throw new ArgumentOutOfRangeException(nameof(storable)).

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/Files.App/Helpers/TransferHelpers.cs#L36-L40

Potential issue: The `switch` expression in `ExecuteTransferAsync` (lines 36-40) handles
`IFile` and `IFolder` types but lacks a default case. If an item from the shelf is of a
type that is neither `IFile` nor `IFolder`, the switch expression will not find a
matching arm and will throw a `SwitchExpressionException` at runtime. This will crash
the copy or cut operation. A similar operation, `BulkDeleteAsync`, correctly includes a
default case that throws an `ArgumentOutOfRangeException`, suggesting this was an
oversight.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes requested Changes are needed for this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants