|
1 | 1 | // Copyright (c) Files Community |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
| 4 | +using CommunityToolkit.WinUI; |
| 5 | + |
4 | 6 | namespace Files.App.Controls |
5 | 7 | { |
6 | | - public sealed partial class SidebarItem : Control |
| 8 | + public sealed partial class SidebarItem |
7 | 9 | { |
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; } |
15 | 12 |
|
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; } |
23 | 15 |
|
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; } |
31 | 18 |
|
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; } |
39 | 21 |
|
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; } |
48 | 24 |
|
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; } |
56 | 27 |
|
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; } |
64 | 30 |
|
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; } |
72 | 33 |
|
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; } |
80 | 36 |
|
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; } |
88 | 39 |
|
89 | 40 | public static void SetTemplateRoot(DependencyObject target, FrameworkElement value) |
90 | 41 | { |
91 | 42 | target.SetValue(TemplateRootProperty, value); |
92 | 43 | } |
| 44 | + |
93 | 45 | public static FrameworkElement GetTemplateRoot(DependencyObject target) |
94 | 46 | { |
95 | 47 | return (FrameworkElement)target.GetValue(TemplateRootProperty); |
96 | 48 | } |
| 49 | + |
97 | 50 | public static readonly DependencyProperty TemplateRootProperty = |
98 | 51 | DependencyProperty.Register("TemplateRoot", typeof(FrameworkElement), typeof(FrameworkElement), new PropertyMetadata(null)); |
99 | 52 |
|
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) |
101 | 69 | { |
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(); |
123 | 71 | } |
124 | 72 | } |
125 | 73 | } |
0 commit comments