Files icon indicating copy to clipboard operation
Files copied to clipboard

Code Quality: Replaced manual DP definitions in the Sidebar controls with the Toolkit's source generator

Open 0x5bfa opened this issue 3 months ago • 1 comments

Vision towards NativeAOT in the Sidebar functionalities

The current Quick Access helper and its watcher is powered by the reflection-based Activator to instantiate the Quick Access's IShellFolder to enumerate Quick Access items instead of Win32 CoCreateInstance due to UWP limitations. This is now blocking us from leveraging NAOT for faster startup and Trimming for a smaller package size.

I have already refactored the codebase of the Home page, which is relatively ready for the next Storage Abstraction concept. However, that of the Sidebar controls is not yet at all, which is overly complicated and requires to a major refactoring for the NAOT/Trimming adoption.

The first example of the complication is the specifically implemented receivers of events that come from Quick Access, Drives, etc.

https://github.com/files-community/Files/blob/868a6f1da8c079c0ca08ad25a0f395eb0299cbe5/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs#L607-L633

Secondly, the decoupled control SidebarView takes a view model for it. We should be passing references to DPs controlled in the MainPageViewModel instead of having a dedicated view model for this control.

https://github.com/files-community/Files/blob/868a6f1da8c079c0ca08ad25a0f395eb0299cbe5/src/Files.App/Views/MainPage.xaml#L176-L187

Thirdly, SidebarView is a UserControl instead of a control that derives from Control, so-called being a custom control. As aforementioned, since the control depends on an instance of a dedicated view model, there's a strong bond between this control and the view model. We should make use of events instead and isolate the control from the implementation details of the view model.

https://github.com/files-community/Files/blob/868a6f1da8c079c0ca08ad25a0f395eb0299cbe5/src/Files.App.Controls/Sidebar/SidebarView.xaml.cs#L14


With these reasons, we should be going to refactor the sidebar implementations to get rid of the view model reference and to implement better bindings of sidebar items collection. This PR is the first one of the series of improvements, the next one would refactor the sidebar item models and probably replace the view model.

Resolved / Related Issues

  • Related to #15000

Steps used to test these changes

Since this has no functionality change, this PR can be validated by just deploying and running the app.

  1. Open Files app
  • [ ] Ejected device
  • [x] Opened properties window
  • [x] Pinned item
  • [x] Unpinned item
  • [x] Hid section
  • [ ] Unhid section
  • [x] Opened reorder items dialog
  • [ ] Created library
  • [ ] Restored libraries
  • [x] Loaded shell extensions in the context menu
  • [x] Resized sidebar
  • [x] Double clicked to collapse sidebar
  • [x] Confirmed sidebar state is saved across sessions
  • [x] Confirmed the sidebar collapses on smaller windows
  • [x] Confirmed the expanded state for sidebar sections is saved

0x5bfa avatar Nov 14 '25 17:11 0x5bfa

It looks like unhiding the "Pinned" and "Tags" sidebar sections causes the app to crash.

yaira2 avatar Dec 02 '25 20:12 yaira2