From 8c758faf6b317e7eedaf09d3326d541ce2a66283 Mon Sep 17 00:00:00 2001
From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com>
Date: Tue, 18 Mar 2025 01:14:59 +0900
Subject: [PATCH 1/3] Initial commit
---
.../Sidebar/SidebarDisplayMode.cs | 2 +
.../Sidebar/SidebarItem.Properties.cs | 136 ++--
.../Sidebar/SidebarItemAutomationPeer.cs | 33 +-
.../Sidebar/SidebarItemDropPosition.cs | 2 +
.../Sidebar/SidebarView.Events.cs | 145 ++++
.../Sidebar/SidebarView.Properties.cs | 112 +--
src/Files.App.Controls/Sidebar/SidebarView.cs | 188 ++++++
.../Sidebar/SidebarView.xaml | 637 +++++++++---------
.../Sidebar/SidebarView.xaml.cs | 246 -------
.../Sidebar/SidebarViewAutomationPeer.cs | 20 +-
src/Files.App.Controls/Themes/Generic.xaml | 3 +-
src/Files.App/Views/MainPage.xaml | 2 +
.../{TestData => Data}/TestSidebarModel.cs | 7 +-
.../TestSidebarViewModel.cs | 7 +-
.../Views/SidebarViewPage.xaml | 11 +-
.../Views/SidebarViewPage.xaml.cs | 16 +-
16 files changed, 770 insertions(+), 797 deletions(-)
create mode 100644 src/Files.App.Controls/Sidebar/SidebarView.Events.cs
create mode 100644 src/Files.App.Controls/Sidebar/SidebarView.cs
delete mode 100644 src/Files.App.Controls/Sidebar/SidebarView.xaml.cs
rename tests/Files.App.UITests/{TestData => Data}/TestSidebarModel.cs (76%)
rename tests/Files.App.UITests/{TestData => Data}/TestSidebarViewModel.cs (83%)
diff --git a/src/Files.App.Controls/Sidebar/SidebarDisplayMode.cs b/src/Files.App.Controls/Sidebar/SidebarDisplayMode.cs
index 6b0bd385b5bb..c389472a68c6 100644
--- a/src/Files.App.Controls/Sidebar/SidebarDisplayMode.cs
+++ b/src/Files.App.Controls/Sidebar/SidebarDisplayMode.cs
@@ -12,10 +12,12 @@ public enum SidebarDisplayMode
/// The sidebar is hidden and moves in from the side when the is set to true.
///
Minimal,
+
///
/// Only the icons of the top most sections are visible.
///
Compact,
+
///
/// The sidebar is expanded and items can also be expanded.
///
diff --git a/src/Files.App.Controls/Sidebar/SidebarItem.Properties.cs b/src/Files.App.Controls/Sidebar/SidebarItem.Properties.cs
index 68b1d440c126..6f8f940bc956 100644
--- a/src/Files.App.Controls/Sidebar/SidebarItem.Properties.cs
+++ b/src/Files.App.Controls/Sidebar/SidebarItem.Properties.cs
@@ -1,125 +1,73 @@
// Copyright (c) Files Community
// Licensed under the MIT License.
+using CommunityToolkit.WinUI;
+
namespace Files.App.Controls
{
- public sealed partial class SidebarItem : Control
+ public sealed partial class SidebarItem
{
- public SidebarView? Owner
- {
- get { return (SidebarView?)GetValue(OwnerProperty); }
- set { SetValue(OwnerProperty, value); }
- }
- public static readonly DependencyProperty OwnerProperty =
- DependencyProperty.Register(nameof(Owner), typeof(SidebarView), typeof(SidebarItem), new PropertyMetadata(null));
+ [GeneratedDependencyProperty]
+ public partial SidebarView? Owner { get; set; }
- public bool IsSelected
- {
- get { return (bool)GetValue(IsSelectedProperty); }
- set { SetValue(IsSelectedProperty, value); }
- }
- public static readonly DependencyProperty IsSelectedProperty =
- DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false, OnPropertyChanged));
+ [GeneratedDependencyProperty]
+ public partial bool IsSelected { get; set; }
- public bool IsExpanded
- {
- get { return (bool)GetValue(IsExpandedProperty); }
- set { SetValue(IsExpandedProperty, value); }
- }
- public static readonly DependencyProperty IsExpandedProperty =
- DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SidebarItem), new PropertyMetadata(true, OnPropertyChanged));
+ [GeneratedDependencyProperty(DefaultValue = true)]
+ public partial bool IsExpanded { get; set; }
- public bool IsInFlyout
- {
- get { return (bool)GetValue(IsInFlyoutProperty); }
- set { SetValue(IsInFlyoutProperty, value); }
- }
- public static readonly DependencyProperty IsInFlyoutProperty =
- DependencyProperty.Register(nameof(IsInFlyout), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false));
+ [GeneratedDependencyProperty]
+ public partial bool IsInFlyout { get; set; }
- public double ChildrenPresenterHeight
- {
- get { return (double)GetValue(ChildrenPresenterHeightProperty); }
- set { SetValue(ChildrenPresenterHeightProperty, value); }
- }
- // Using 30 as a default in case something goes wrong
- public static readonly DependencyProperty ChildrenPresenterHeightProperty =
- DependencyProperty.Register(nameof(ChildrenPresenterHeight), typeof(double), typeof(SidebarItem), new PropertyMetadata(30d));
+ [GeneratedDependencyProperty(DefaultValue = 30d)]
+ public partial double ChildrenPresenterHeight { get; set; }
- public ISidebarItemModel? Item
- {
- get { return (ISidebarItemModel)GetValue(ItemProperty); }
- set { SetValue(ItemProperty, value); }
- }
- public static readonly DependencyProperty ItemProperty =
- DependencyProperty.Register(nameof(Item), typeof(ISidebarItemModel), typeof(SidebarItem), new PropertyMetadata(null));
+ [GeneratedDependencyProperty]
+ public partial ISidebarItemModel? Item { get; set; }
- public bool UseReorderDrop
- {
- get { return (bool)GetValue(UseReorderDropProperty); }
- set { SetValue(UseReorderDropProperty, value); }
- }
- public static readonly DependencyProperty UseReorderDropProperty =
- DependencyProperty.Register(nameof(UseReorderDrop), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false));
+ [GeneratedDependencyProperty]
+ public partial bool UseReorderDrop { get; set; }
- public FrameworkElement? Icon
- {
- get { return (FrameworkElement?)GetValue(IconProperty); }
- set { SetValue(IconProperty, value); }
- }
- public static readonly DependencyProperty IconProperty =
- DependencyProperty.Register(nameof(Icon), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
+ [GeneratedDependencyProperty]
+ public partial FrameworkElement? Icon { get; set; }
- public FrameworkElement? Decorator
- {
- get { return (FrameworkElement?)GetValue(DecoratorProperty); }
- set { SetValue(DecoratorProperty, value); }
- }
- public static readonly DependencyProperty DecoratorProperty =
- DependencyProperty.Register(nameof(Decorator), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
+ [GeneratedDependencyProperty]
+ public partial FrameworkElement? Decorator { get; set; }
- public SidebarDisplayMode DisplayMode
- {
- get { return (SidebarDisplayMode)GetValue(DisplayModeProperty); }
- set { SetValue(DisplayModeProperty, value); }
- }
- public static readonly DependencyProperty DisplayModeProperty =
- DependencyProperty.Register(nameof(DisplayMode), typeof(SidebarDisplayMode), typeof(SidebarItem), new PropertyMetadata(SidebarDisplayMode.Expanded, OnPropertyChanged));
+ [GeneratedDependencyProperty(DefaultValue = SidebarDisplayMode.Expanded)]
+ public partial SidebarDisplayMode DisplayMode { get; set; }
public static void SetTemplateRoot(DependencyObject target, FrameworkElement value)
{
target.SetValue(TemplateRootProperty, value);
}
+
public static FrameworkElement GetTemplateRoot(DependencyObject target)
{
return (FrameworkElement)target.GetValue(TemplateRootProperty);
}
+
public static readonly DependencyProperty TemplateRootProperty =
DependencyProperty.Register("TemplateRoot", typeof(FrameworkElement), typeof(FrameworkElement), new PropertyMetadata(null));
- public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
+ partial void OnDisplayModePropertyChanged(DependencyPropertyChangedEventArgs e)
+ {
+ SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue);
+ }
+
+ partial void OnIsSelectedChanged(bool newValue)
+ {
+ UpdateSelectionState();
+ }
+
+ partial void OnIsExpandedChanged(bool newValue)
+ {
+ UpdateExpansionState();
+ }
+
+ partial void OnItemChanged(ISidebarItemModel? newValue)
{
- if (sender is not SidebarItem item) return;
- if (e.Property == DisplayModeProperty)
- {
- item.SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue);
- }
- else if (e.Property == IsSelectedProperty)
- {
- item.UpdateSelectionState();
- }
- else if (e.Property == IsExpandedProperty)
- {
- item.UpdateExpansionState();
- }
- else if(e.Property == ItemProperty)
- {
- item.HandleItemChange();
- }
- else
- {
- Debug.Write(e.Property.ToString());
- }
+ HandleItemChange();
}
}
}
diff --git a/src/Files.App.Controls/Sidebar/SidebarItemAutomationPeer.cs b/src/Files.App.Controls/Sidebar/SidebarItemAutomationPeer.cs
index 47721f6cc443..e823bc7e918f 100644
--- a/src/Files.App.Controls/Sidebar/SidebarItemAutomationPeer.cs
+++ b/src/Files.App.Controls/Sidebar/SidebarItemAutomationPeer.cs
@@ -11,15 +11,12 @@ namespace Files.App.Controls
{
public sealed partial class SidebarItemAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider, IExpandCollapseProvider, ISelectionItemProvider
{
- public ExpandCollapseState ExpandCollapseState
- {
- get
- {
- if (Owner.HasChildren)
- return Owner.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
- return ExpandCollapseState.LeafNode;
- }
- }
+ public ExpandCollapseState ExpandCollapseState =>
+ Owner.HasChildren
+ ? Owner.IsExpanded
+ ? ExpandCollapseState.Expanded
+ : ExpandCollapseState.Collapsed
+ : ExpandCollapseState.LeafNode;
public bool IsSelected => Owner.IsSelected;
public IRawElementProviderSimple SelectionContainer => ProviderFromPeer(CreatePeerForElement(Owner.Owner));
@@ -27,7 +24,7 @@ public ExpandCollapseState ExpandCollapseState
public SidebarItemAutomationPeer(SidebarItem owner) : base(owner)
{
- this.Owner = owner;
+ Owner = owner;
}
protected override AutomationControlType GetAutomationControlTypeCore()
@@ -49,28 +46,22 @@ protected override object GetPatternCore(PatternInterface patternInterface)
else if (patternInterface == PatternInterface.ExpandCollapse)
{
if (Owner.CollapseEnabled)
- {
return this;
- }
}
+
return base.GetPatternCore(patternInterface);
}
public void Collapse()
{
if (Owner.CollapseEnabled)
- {
Owner.IsExpanded = false;
- }
}
public void Expand()
{
-
if (Owner.CollapseEnabled)
- {
Owner.IsExpanded = true;
- }
}
public void Invoke()
@@ -106,13 +97,11 @@ protected override int GetPositionInSetCore()
private IList GetOwnerCollection()
{
if (Owner.FindAscendant() is SidebarItem parent && parent.Item?.Children is IList list)
- {
return list;
- }
- if (Owner?.Owner is not null && Owner.Owner.ViewModel.SidebarItems is IList items)
- {
+
+ if (Owner?.Owner is not null && Owner.Owner?.ViewModel?.SidebarItems is IList items)
return items;
- }
+
return new List