Skip to content

Commit 9fddcf6

Browse files
committed
Initial commit
1 parent 1a1b651 commit 9fddcf6

16 files changed

+770
-797
lines changed

src/Files.App.Controls/Sidebar/SidebarDisplayMode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ public enum SidebarDisplayMode
1212
/// The sidebar is hidden and moves in from the side when the <see cref="SidebarView.IsPaneOpen"/> is set to <code>true</code>.
1313
/// </summary>
1414
Minimal,
15+
1516
/// <summary>
1617
/// Only the icons of the top most sections are visible.
1718
/// </summary>
1819
Compact,
20+
1921
/// <summary>
2022
/// The sidebar is expanded and items can also be expanded.
2123
/// </summary>
Lines changed: 42 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,73 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using CommunityToolkit.WinUI;
5+
46
namespace Files.App.Controls
57
{
6-
public sealed partial class SidebarItem : Control
8+
public sealed partial class SidebarItem
79
{
8-
public SidebarView? Owner
9-
{
10-
get { return (SidebarView?)GetValue(OwnerProperty); }
11-
set { SetValue(OwnerProperty, value); }
12-
}
13-
public static readonly DependencyProperty OwnerProperty =
14-
DependencyProperty.Register(nameof(Owner), typeof(SidebarView), typeof(SidebarItem), new PropertyMetadata(null));
10+
[GeneratedDependencyProperty]
11+
public partial SidebarView? Owner { get; set; }
1512

16-
public bool IsSelected
17-
{
18-
get { return (bool)GetValue(IsSelectedProperty); }
19-
set { SetValue(IsSelectedProperty, value); }
20-
}
21-
public static readonly DependencyProperty IsSelectedProperty =
22-
DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false, OnPropertyChanged));
13+
[GeneratedDependencyProperty]
14+
public partial bool IsSelected { get; set; }
2315

24-
public bool IsExpanded
25-
{
26-
get { return (bool)GetValue(IsExpandedProperty); }
27-
set { SetValue(IsExpandedProperty, value); }
28-
}
29-
public static readonly DependencyProperty IsExpandedProperty =
30-
DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SidebarItem), new PropertyMetadata(true, OnPropertyChanged));
16+
[GeneratedDependencyProperty(DefaultValue = true)]
17+
public partial bool IsExpanded { get; set; }
3118

32-
public bool IsInFlyout
33-
{
34-
get { return (bool)GetValue(IsInFlyoutProperty); }
35-
set { SetValue(IsInFlyoutProperty, value); }
36-
}
37-
public static readonly DependencyProperty IsInFlyoutProperty =
38-
DependencyProperty.Register(nameof(IsInFlyout), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false));
19+
[GeneratedDependencyProperty]
20+
public partial bool IsInFlyout { get; set; }
3921

40-
public double ChildrenPresenterHeight
41-
{
42-
get { return (double)GetValue(ChildrenPresenterHeightProperty); }
43-
set { SetValue(ChildrenPresenterHeightProperty, value); }
44-
}
45-
// Using 30 as a default in case something goes wrong
46-
public static readonly DependencyProperty ChildrenPresenterHeightProperty =
47-
DependencyProperty.Register(nameof(ChildrenPresenterHeight), typeof(double), typeof(SidebarItem), new PropertyMetadata(30d));
22+
[GeneratedDependencyProperty(DefaultValue = 30d)]
23+
public partial double ChildrenPresenterHeight { get; set; }
4824

49-
public ISidebarItemModel? Item
50-
{
51-
get { return (ISidebarItemModel)GetValue(ItemProperty); }
52-
set { SetValue(ItemProperty, value); }
53-
}
54-
public static readonly DependencyProperty ItemProperty =
55-
DependencyProperty.Register(nameof(Item), typeof(ISidebarItemModel), typeof(SidebarItem), new PropertyMetadata(null));
25+
[GeneratedDependencyProperty]
26+
public partial ISidebarItemModel? Item { get; set; }
5627

57-
public bool UseReorderDrop
58-
{
59-
get { return (bool)GetValue(UseReorderDropProperty); }
60-
set { SetValue(UseReorderDropProperty, value); }
61-
}
62-
public static readonly DependencyProperty UseReorderDropProperty =
63-
DependencyProperty.Register(nameof(UseReorderDrop), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false));
28+
[GeneratedDependencyProperty]
29+
public partial bool UseReorderDrop { get; set; }
6430

65-
public FrameworkElement? Icon
66-
{
67-
get { return (FrameworkElement?)GetValue(IconProperty); }
68-
set { SetValue(IconProperty, value); }
69-
}
70-
public static readonly DependencyProperty IconProperty =
71-
DependencyProperty.Register(nameof(Icon), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
31+
[GeneratedDependencyProperty]
32+
public partial FrameworkElement? Icon { get; set; }
7233

73-
public FrameworkElement? Decorator
74-
{
75-
get { return (FrameworkElement?)GetValue(DecoratorProperty); }
76-
set { SetValue(DecoratorProperty, value); }
77-
}
78-
public static readonly DependencyProperty DecoratorProperty =
79-
DependencyProperty.Register(nameof(Decorator), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
34+
[GeneratedDependencyProperty]
35+
public partial FrameworkElement? Decorator { get; set; }
8036

81-
public SidebarDisplayMode DisplayMode
82-
{
83-
get { return (SidebarDisplayMode)GetValue(DisplayModeProperty); }
84-
set { SetValue(DisplayModeProperty, value); }
85-
}
86-
public static readonly DependencyProperty DisplayModeProperty =
87-
DependencyProperty.Register(nameof(DisplayMode), typeof(SidebarDisplayMode), typeof(SidebarItem), new PropertyMetadata(SidebarDisplayMode.Expanded, OnPropertyChanged));
37+
[GeneratedDependencyProperty(DefaultValue = SidebarDisplayMode.Expanded)]
38+
public partial SidebarDisplayMode DisplayMode { get; set; }
8839

8940
public static void SetTemplateRoot(DependencyObject target, FrameworkElement value)
9041
{
9142
target.SetValue(TemplateRootProperty, value);
9243
}
44+
9345
public static FrameworkElement GetTemplateRoot(DependencyObject target)
9446
{
9547
return (FrameworkElement)target.GetValue(TemplateRootProperty);
9648
}
49+
9750
public static readonly DependencyProperty TemplateRootProperty =
9851
DependencyProperty.Register("TemplateRoot", typeof(FrameworkElement), typeof(FrameworkElement), new PropertyMetadata(null));
9952

100-
public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
53+
partial void OnDisplayModePropertyChanged(DependencyPropertyChangedEventArgs e)
54+
{
55+
SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue);
56+
}
57+
58+
partial void OnIsSelectedChanged(bool newValue)
59+
{
60+
UpdateSelectionState();
61+
}
62+
63+
partial void OnIsExpandedChanged(bool newValue)
64+
{
65+
UpdateExpansionState();
66+
}
67+
68+
partial void OnItemChanged(ISidebarItemModel? newValue)
10169
{
102-
if (sender is not SidebarItem item) return;
103-
if (e.Property == DisplayModeProperty)
104-
{
105-
item.SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue);
106-
}
107-
else if (e.Property == IsSelectedProperty)
108-
{
109-
item.UpdateSelectionState();
110-
}
111-
else if (e.Property == IsExpandedProperty)
112-
{
113-
item.UpdateExpansionState();
114-
}
115-
else if(e.Property == ItemProperty)
116-
{
117-
item.HandleItemChange();
118-
}
119-
else
120-
{
121-
Debug.Write(e.Property.ToString());
122-
}
70+
HandleItemChange();
12371
}
12472
}
12573
}

src/Files.App.Controls/Sidebar/SidebarItemAutomationPeer.cs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@ namespace Files.App.Controls
1111
{
1212
public sealed partial class SidebarItemAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider, IExpandCollapseProvider, ISelectionItemProvider
1313
{
14-
public ExpandCollapseState ExpandCollapseState
15-
{
16-
get
17-
{
18-
if (Owner.HasChildren)
19-
return Owner.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
20-
return ExpandCollapseState.LeafNode;
21-
}
22-
}
14+
public ExpandCollapseState ExpandCollapseState =>
15+
Owner.HasChildren
16+
? Owner.IsExpanded
17+
? ExpandCollapseState.Expanded
18+
: ExpandCollapseState.Collapsed
19+
: ExpandCollapseState.LeafNode;
2320
public bool IsSelected => Owner.IsSelected;
2421
public IRawElementProviderSimple SelectionContainer => ProviderFromPeer(CreatePeerForElement(Owner.Owner));
2522

2623
private new SidebarItem Owner { get; init; }
2724

2825
public SidebarItemAutomationPeer(SidebarItem owner) : base(owner)
2926
{
30-
this.Owner = owner;
27+
Owner = owner;
3128
}
3229

3330
protected override AutomationControlType GetAutomationControlTypeCore()
@@ -49,28 +46,22 @@ protected override object GetPatternCore(PatternInterface patternInterface)
4946
else if (patternInterface == PatternInterface.ExpandCollapse)
5047
{
5148
if (Owner.CollapseEnabled)
52-
{
5349
return this;
54-
}
5550
}
51+
5652
return base.GetPatternCore(patternInterface);
5753
}
5854

5955
public void Collapse()
6056
{
6157
if (Owner.CollapseEnabled)
62-
{
6358
Owner.IsExpanded = false;
64-
}
6559
}
6660

6761
public void Expand()
6862
{
69-
7063
if (Owner.CollapseEnabled)
71-
{
7264
Owner.IsExpanded = true;
73-
}
7465
}
7566

7667
public void Invoke()
@@ -106,13 +97,11 @@ protected override int GetPositionInSetCore()
10697
private IList GetOwnerCollection()
10798
{
10899
if (Owner.FindAscendant<SidebarItem>() is SidebarItem parent && parent.Item?.Children is IList list)
109-
{
110100
return list;
111-
}
112-
if (Owner?.Owner is not null && Owner.Owner.ViewModel.SidebarItems is IList items)
113-
{
101+
102+
if (Owner?.Owner is not null && Owner.Owner?.ViewModel?.SidebarItems is IList items)
114103
return items;
115-
}
104+
116105
return new List<object>();
117106
}
118107
}

src/Files.App.Controls/Sidebar/SidebarItemDropPosition.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ public enum SidebarItemDropPosition
1212
/// The item was dropped on the top of the sidebar item indicating it should be moved/inserted above this item.
1313
/// </summary>
1414
Top,
15+
1516
/// <summary>
1617
/// The item was dropped on the bottom of the sidebar item indicating it should be moved/inserted below this item.
1718
/// </summary>
1819
Bottom,
20+
1921
/// <summary>
2022
/// The item was dropped on the center of the sidebar item indicating it should be moved/inserted as a child of this item.
2123
/// </summary>

0 commit comments

Comments
 (0)