Skip to content

Commit 6aca445

Browse files
committed
Init
1 parent 868a6f1 commit 6aca445

File tree

5 files changed

+131
-252
lines changed

5 files changed

+131
-252
lines changed
Lines changed: 40 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,41 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using CommunityToolkit.WinUI;
5+
46
namespace Files.App.Controls
57
{
68
public sealed partial class SidebarItem : Control
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
{
@@ -95,31 +46,26 @@ public static FrameworkElement GetTemplateRoot(DependencyObject target)
9546
return (FrameworkElement)target.GetValue(TemplateRootProperty);
9647
}
9748
public static readonly DependencyProperty TemplateRootProperty =
98-
DependencyProperty.Register("TemplateRoot", typeof(FrameworkElement), typeof(FrameworkElement), new PropertyMetadata(null));
49+
DependencyProperty.Register("TemplateRoot", typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
50+
51+
partial void OnIsSelectedPropertyChanged(DependencyPropertyChangedEventArgs e)
52+
{
53+
UpdateSelectionState();
54+
}
55+
56+
partial void OnIsExpandedPropertyChanged(DependencyPropertyChangedEventArgs e)
57+
{
58+
UpdateExpansionState();
59+
}
60+
61+
partial void OnItemPropertyChanged(DependencyPropertyChangedEventArgs e)
62+
{
63+
HandleItemChange();
64+
}
9965

100-
public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
66+
partial void OnDisplayModePropertyChanged(DependencyPropertyChangedEventArgs e)
10167
{
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-
}
68+
SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue);
12369
}
12470
}
12571
}

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@ public ExpandCollapseState ExpandCollapseState
1515
{
1616
get
1717
{
18-
if (Owner.HasChildren)
19-
return Owner.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
20-
return ExpandCollapseState.LeafNode;
18+
return Owner.HasChildren
19+
? Owner.IsExpanded
20+
? ExpandCollapseState.Expanded
21+
: ExpandCollapseState.Collapsed
22+
: ExpandCollapseState.LeafNode;
2123
}
2224
}
23-
public bool IsSelected => Owner.IsSelected;
24-
public IRawElementProviderSimple SelectionContainer => ProviderFromPeer(CreatePeerForElement(Owner.Owner));
25+
26+
public bool IsSelected
27+
=> Owner.IsSelected;
28+
29+
public IRawElementProviderSimple SelectionContainer
30+
=> ProviderFromPeer(CreatePeerForElement(Owner.Owner));
2531

2632
private new SidebarItem Owner { get; init; }
2733

2834
public SidebarItemAutomationPeer(SidebarItem owner) : base(owner)
2935
{
30-
this.Owner = owner;
36+
Owner = owner;
3137
}
3238

3339
protected override AutomationControlType GetAutomationControlTypeCore()
@@ -59,18 +65,13 @@ protected override object GetPatternCore(PatternInterface patternInterface)
5965
public void Collapse()
6066
{
6167
if (Owner.CollapseEnabled)
62-
{
6368
Owner.IsExpanded = false;
64-
}
6569
}
6670

6771
public void Expand()
6872
{
69-
7073
if (Owner.CollapseEnabled)
71-
{
7274
Owner.IsExpanded = true;
73-
}
7475
}
7576

7677
public void Invoke()
@@ -106,13 +107,10 @@ protected override int GetPositionInSetCore()
106107
private IList GetOwnerCollection()
107108
{
108109
if (Owner.FindAscendant<SidebarItem>() is SidebarItem parent && parent.Item?.Children is IList list)
109-
{
110110
return list;
111-
}
112111
if (Owner?.Owner is not null && Owner.Owner.ViewModel.SidebarItems is IList items)
113-
{
114112
return items;
115-
}
113+
116114
return new List<object>();
117115
}
118116
}
Lines changed: 30 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,55 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using CommunityToolkit.WinUI;
5+
46
namespace Files.App.Controls
57
{
68
public sealed partial class SidebarView
79
{
8-
public SidebarDisplayMode DisplayMode
9-
{
10-
get { return (SidebarDisplayMode)GetValue(DisplayModeProperty); }
11-
set { SetValue(DisplayModeProperty, value); }
12-
}
13-
public static readonly DependencyProperty DisplayModeProperty =
14-
DependencyProperty.Register(nameof(DisplayMode), typeof(SidebarDisplayMode), typeof(SidebarView), new PropertyMetadata(SidebarDisplayMode.Expanded, OnPropertyChanged));
10+
[GeneratedDependencyProperty(DefaultValue = SidebarDisplayMode.Expanded)]
11+
public partial SidebarDisplayMode DisplayMode { get; set; }
1512

16-
public UIElement InnerContent
17-
{
18-
get { return (UIElement)GetValue(InnerContentProperty); }
19-
set { SetValue(InnerContentProperty, value); }
20-
}
21-
public static readonly DependencyProperty InnerContentProperty =
22-
DependencyProperty.Register(nameof(InnerContent), typeof(UIElement), typeof(SidebarView), new PropertyMetadata(null));
13+
[GeneratedDependencyProperty]
14+
public partial UIElement? InnerContent { get; set; }
2315

24-
public UIElement SidebarContent
25-
{
26-
get { return (UIElement)GetValue(SidebarContentProperty); }
27-
set { SetValue(SidebarContentProperty, value); }
28-
}
29-
public static readonly DependencyProperty SidebarContentProperty =
30-
DependencyProperty.Register("SidebarContent", typeof(UIElement), typeof(SidebarView), new PropertyMetadata(null));
16+
[GeneratedDependencyProperty]
17+
public partial UIElement? SidebarContent { get; set; }
3118

32-
public UIElement Footer
33-
{
34-
get { return (UIElement)GetValue(FooterProperty); }
35-
set { SetValue(FooterProperty, value); }
36-
}
37-
public static readonly DependencyProperty FooterProperty =
38-
DependencyProperty.Register("Footer", typeof(UIElement), typeof(SidebarView), new PropertyMetadata(null));
19+
[GeneratedDependencyProperty]
20+
public partial UIElement? Footer { get; set; }
3921

40-
public bool IsPaneOpen
41-
{
42-
get { return (bool)GetValue(IsPaneOpenProperty); }
43-
set { SetValue(IsPaneOpenProperty, value); }
44-
}
45-
public static readonly DependencyProperty IsPaneOpenProperty =
46-
DependencyProperty.Register(nameof(IsPaneOpen), typeof(bool), typeof(SidebarView), new PropertyMetadata(false, OnPropertyChanged));
22+
[GeneratedDependencyProperty]
23+
public partial bool IsPaneOpen { get; set; }
4724

48-
public double OpenPaneLength
49-
{
50-
get { return (double)GetValue(OpenPaneLengthProperty); }
51-
set
52-
{
53-
SetValue(OpenPaneLengthProperty, value);
54-
NegativeOpenPaneLength = -value;
55-
}
56-
}
57-
public static readonly DependencyProperty OpenPaneLengthProperty =
58-
DependencyProperty.Register(nameof(OpenPaneLength), typeof(double), typeof(SidebarView), new PropertyMetadata(240d, OnPropertyChanged));
25+
[GeneratedDependencyProperty(DefaultValue = 240D)]
26+
public partial double OpenPaneLength { get; set; }
5927

60-
public double NegativeOpenPaneLength
61-
{
62-
get { return (double)GetValue(NegativeOpenPaneLengthProperty); }
63-
set { SetValue(NegativeOpenPaneLengthProperty, value); }
64-
}
65-
public static readonly DependencyProperty NegativeOpenPaneLengthProperty =
66-
DependencyProperty.Register(nameof(NegativeOpenPaneLength), typeof(double), typeof(SidebarView), new PropertyMetadata(null));
28+
[GeneratedDependencyProperty]
29+
public partial double NegativeOpenPaneLength { get; set; }
6730

68-
public ISidebarViewModel ViewModel
69-
{
70-
get => (ISidebarViewModel)GetValue(ViewModelProperty);
71-
set => SetValue(ViewModelProperty, value);
72-
}
73-
public static readonly DependencyProperty ViewModelProperty =
74-
DependencyProperty.Register(nameof(ViewModel), typeof(ISidebarViewModel), typeof(SidebarView), new PropertyMetadata(null));
31+
[GeneratedDependencyProperty]
32+
public partial ISidebarViewModel? ViewModel { get; set; }
33+
34+
[GeneratedDependencyProperty]
35+
public partial ISidebarItemModel? SelectedItem { get; set; }
7536

76-
public ISidebarItemModel SelectedItem
37+
[GeneratedDependencyProperty]
38+
public partial object? MenuItemsSource { get; set; }
39+
40+
partial void OnDisplayModePropertyChanged(DependencyPropertyChangedEventArgs e)
7741
{
78-
get => (ISidebarItemModel)GetValue(SelectedItemProperty);
79-
set
80-
{
81-
SetValue(SelectedItemProperty, value);
82-
}
42+
UpdateDisplayMode();
8343
}
84-
public static readonly DependencyProperty SelectedItemProperty =
85-
DependencyProperty.Register(nameof(SelectedItem), typeof(ISidebarItemModel), typeof(SidebarView), new PropertyMetadata(null));
8644

87-
public object MenuItemsSource
45+
partial void OnIsPaneOpenPropertyChanged(DependencyPropertyChangedEventArgs e)
8846
{
89-
get => (object)GetValue(MenuItemsSourceProperty);
90-
set => SetValue(MenuItemsSourceProperty, value);
47+
UpdateMinimalMode();
9148
}
92-
public static readonly DependencyProperty MenuItemsSourceProperty =
93-
DependencyProperty.Register(nameof(MenuItemsSource), typeof(object), typeof(SidebarView), new PropertyMetadata(null));
9449

95-
public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
50+
partial void OnOpenPaneLengthPropertyChanged(DependencyPropertyChangedEventArgs e)
9651
{
97-
if (sender is not SidebarView control) return;
98-
99-
if (e.Property == OpenPaneLengthProperty)
100-
{
101-
control.UpdateOpenPaneLengthColumn();
102-
}
103-
else if (e.Property == DisplayModeProperty)
104-
{
105-
control.UpdateDisplayMode();
106-
}
107-
else if (e.Property == IsPaneOpenProperty)
108-
{
109-
control.UpdateMinimalMode();
110-
}
52+
UpdateOpenPaneLengthColumn();
11153
}
11254
}
11355
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ public SidebarViewAutomationPeer(SidebarView owner) : base(owner)
2121
protected override object GetPatternCore(PatternInterface patternInterface)
2222
{
2323
if (patternInterface == PatternInterface.Selection)
24-
{
2524
return this;
26-
}
25+
2726
return base.GetPatternCore(patternInterface);
2827
}
2928

3029
public IRawElementProviderSimple[] GetSelection()
3130
{
3231
if (Owner.SelectedItemContainer != null)
33-
return
34-
[
35-
ProviderFromPeer(CreatePeerForElement(Owner.SelectedItemContainer))
36-
];
32+
return [ProviderFromPeer(CreatePeerForElement(Owner.SelectedItemContainer))];
33+
3734
return [];
3835
}
3936
}

0 commit comments

Comments
 (0)