Skip to content

Commit 2382d81

Browse files
authored
Code Quality: Retarget BladeView to ContentControl (#16853)
1 parent 08d0673 commit 2382d81

File tree

8 files changed

+39
-220
lines changed

8 files changed

+39
-220
lines changed

Directory.Packages.props

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
<PackageVersion Include="FluentFTP" Version="52.0.0" />
2222
<PackageVersion Include="LibGit2Sharp" Version="0.30.0" />
2323
<PackageVersion Include="MessageFormat" Version="7.1.2" />
24-
<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="9.0.1" />
25-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
26-
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
27-
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.1" />
24+
<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="9.0.2" />
25+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
26+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
27+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.2" />
2828
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
2929
<PackageVersion Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="3.0.0" />
30-
<PackageVersion Include="Sentry" Version="5.1.0" />
30+
<PackageVersion Include="Sentry" Version="5.1.1" />
3131
<PackageVersion Include="SevenZipSharp" Version="1.0.2" />
3232
<PackageVersion Include="SQLitePCLRaw.bundle_green" Version="2.1.10" />
3333
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.6.250205002" />
3434
<PackageVersion Include="Microsoft.Graphics.Win2D" Version="1.3.2" />
3535
<PackageVersion Include="TagLibSharp" Version="2.3.0" />
3636
<PackageVersion Include="Tulpep.ActiveDirectoryObjectPicker" Version="3.0.11" />
3737
<PackageVersion Include="WinUIEx" Version="2.5.1" />
38-
<PackageVersion Include="Vanara.Windows.Extensions" Version="4.0.4" />
39-
<PackageVersion Include="Vanara.Windows.Shell" Version="4.0.4" />
38+
<PackageVersion Include="Vanara.Windows.Extensions" Version="4.0.5" />
39+
<PackageVersion Include="Vanara.Windows.Shell" Version="4.0.5" />
4040
<PackageVersion Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
4141
<PackageVersion Include="Microsoft.Management.Infrastructure.Runtime.Win" Version="3.0.0" />
4242
<PackageVersion Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
@@ -45,13 +45,13 @@
4545
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
4646
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.12.0" />
4747
<PackageVersion Include="PolySharp" Version="1.15.0" />
48-
<PackageVersion Include="System.Text.Json" Version="9.0.1" />
49-
<PackageVersion Include="System.IO.Hashing" Version="9.0.1" />
50-
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="9.0.1" />
48+
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
49+
<PackageVersion Include="System.IO.Hashing" Version="9.0.2" />
50+
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="9.0.2" />
5151
<PackageVersion Include="Appium.WebDriver" Version="4.4.5" />
5252
<PackageVersion Include="Axe.Windows" Version="2.4.2" />
53-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
54-
<PackageVersion Include="MSTest.TestAdapter" Version="3.7.3" />
55-
<PackageVersion Include="MSTest.TestFramework" Version="3.7.3" />
53+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
54+
<PackageVersion Include="MSTest.TestAdapter" Version="3.8.2" />
55+
<PackageVersion Include="MSTest.TestFramework" Version="3.8.2" />
5656
</ItemGroup>
5757
</Project>

src/Files.App.Controls/BladeView/BladeItem.Properties.cs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ namespace Files.App.Controls
1717
public partial class BladeItem
1818
{
1919
/// <summary>
20-
/// Identifies the <see cref="TitleBarVisibility"/> dependency property.
21-
/// </summary>
22-
public static readonly DependencyProperty TitleBarVisibilityProperty = DependencyProperty.Register(nameof(TitleBarVisibility), typeof(Visibility), typeof(BladeItem), new PropertyMetadata(default(Visibility)));
23-
24-
/// <summary>
25-
/// Identifies the <see cref="TitleBarBackground"/> dependency property.
20+
/// Identifies the <see cref="CloseButtonBackground"/> dependency property.
2621
/// </summary>
27-
public static readonly DependencyProperty TitleBarBackgroundProperty = DependencyProperty.Register(nameof(TitleBarBackground), typeof(Brush), typeof(BladeItem), new PropertyMetadata(default(Brush)));
22+
public static readonly DependencyProperty CloseButtonBackgroundProperty = DependencyProperty.Register(nameof(CloseButtonBackground), typeof(Brush), typeof(BladeItem), new PropertyMetadata(default(Brush)));
2823

2924
/// <summary>
30-
/// Identifies the <see cref="CloseButtonBackground"/> dependency property.
25+
/// Identifies the <see cref="CloseButtonVisibility"/> dependency property.
3126
/// </summary>
32-
public static readonly DependencyProperty CloseButtonBackgroundProperty = DependencyProperty.Register(nameof(CloseButtonBackground), typeof(Brush), typeof(BladeItem), new PropertyMetadata(default(Brush)));
27+
public static readonly DependencyProperty CloseButtonVisibilityProperty = DependencyProperty.Register(nameof(CloseButtonVisibility), typeof(Visibility), typeof(BladeItem), new PropertyMetadata(default(Visibility)));
3328

3429
/// <summary>
3530
/// Identifies the <see cref="IsOpen"/> dependency property.
@@ -53,21 +48,12 @@ public Brush CloseButtonForeground
5348
}
5449

5550
/// <summary>
56-
/// Gets or sets the visibility of the title bar for this blade
57-
/// </summary>
58-
public Visibility TitleBarVisibility
59-
{
60-
get { return (Visibility)GetValue(TitleBarVisibilityProperty); }
61-
set { SetValue(TitleBarVisibilityProperty, value); }
62-
}
63-
64-
/// <summary>
65-
/// Gets or sets the background color of the title bar
51+
/// Gets or sets the visibility of the close button
6652
/// </summary>
67-
public Brush TitleBarBackground
53+
public Visibility CloseButtonVisibility
6854
{
69-
get { return (Brush)GetValue(TitleBarBackgroundProperty); }
70-
set { SetValue(TitleBarBackgroundProperty, value); }
55+
get { return (Visibility)GetValue(CloseButtonVisibilityProperty); }
56+
set { SetValue(CloseButtonVisibilityProperty, value); }
7157
}
7258

7359
/// <summary>
Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using CommunityToolkit.WinUI;
54
using Microsoft.UI.Xaml.Automation.Peers;
6-
using Microsoft.UI.Xaml.Automation;
75

86
namespace Files.App.Controls
97
{
108
/// <summary>
119
/// The Blade is used as a child in the BladeView
1210
/// </summary>
1311
[TemplatePart(Name = "CloseButton", Type = typeof(Button))]
14-
[TemplatePart(Name = "EnlargeButton", Type = typeof(Button))]
15-
public partial class BladeItem : Expander
12+
public partial class BladeItem : ContentControl
1613
{
1714
private Button _closeButton;
18-
private Button _enlargeButton;
19-
private double _normalModeWidth;
20-
private bool _loaded = false;
21-
2215
/// <summary>
2316
/// Initializes a new instance of the <see cref="BladeItem"/> class.
2417
/// </summary>
2518
public BladeItem()
2619
{
2720
DefaultStyleKey = typeof(BladeItem);
28-
29-
SizeChanged += OnSizeChanged;
30-
Expanding += OnExpanding;
31-
Collapsed += OnCollapsed;
3221
}
3322

3423
/// <summary>
3524
/// Override default OnApplyTemplate to capture child controls
3625
/// </summary>
3726
protected override void OnApplyTemplate()
3827
{
39-
_loaded = true;
28+
base.OnApplyTemplate();
4029

4130
_closeButton = GetTemplateChild("CloseButton") as Button;
42-
_enlargeButton = GetTemplateChild("EnlargeButton") as Button;
4331

4432
if (_closeButton == null)
4533
{
@@ -48,43 +36,7 @@ protected override void OnApplyTemplate()
4836

4937
_closeButton.Click -= CloseButton_Click;
5038
_closeButton.Click += CloseButton_Click;
51-
52-
if (_enlargeButton == null)
53-
{
54-
return;
55-
}
56-
57-
_enlargeButton.Click -= EnlargeButton_Click;
58-
_enlargeButton.Click += EnlargeButton_Click;
59-
}
60-
61-
/// <inheritdoc/>
62-
private void OnExpanding(Expander sender, ExpanderExpandingEventArgs args)
63-
{
64-
if (_loaded)
65-
{
66-
Width = _normalModeWidth;
67-
VisualStateManager.GoToState(this, "Expanded", true);
68-
if (_enlargeButton != null)
69-
{
70-
AutomationProperties.SetName(_enlargeButton, "Expand Blade Item");
71-
}
72-
}
73-
}
74-
75-
/// <inheritdoc/>
76-
private void OnCollapsed(Expander sender, ExpanderCollapsedEventArgs args)
77-
{
78-
if (_loaded)
79-
{
80-
Width = double.NaN;
81-
if (_enlargeButton != null)
82-
{
83-
AutomationProperties.SetName(_enlargeButton, "Collapse Blade Item");
84-
}
85-
}
8639
}
87-
8840
/// <summary>
8941
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
9042
/// </summary>
@@ -94,22 +46,9 @@ protected override AutomationPeer OnCreateAutomationPeer()
9446
return new BladeItemAutomationPeer(this);
9547
}
9648

97-
private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
98-
{
99-
if (IsExpanded)
100-
{
101-
_normalModeWidth = Width;
102-
}
103-
}
104-
10549
private void CloseButton_Click(object sender, RoutedEventArgs e)
10650
{
10751
IsOpen = false;
10852
}
109-
110-
private void EnlargeButton_Click(object sender, RoutedEventArgs e)
111-
{
112-
IsExpanded = !IsExpanded;
113-
}
11453
}
11554
}

src/Files.App.Controls/BladeView/BladeItemAutomationPeer.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ protected override string GetNameCore()
7575
return name;
7676
}
7777

78-
name = this.OwnerBladeItem.Header?.ToString();
79-
if (!string.IsNullOrEmpty(name))
80-
{
81-
return name;
82-
}
83-
8478
TextBlock textBlock = this.OwnerBladeItem.FindDescendant<TextBlock>();
8579
if (textBlock != null)
8680
{

src/Files.App.Controls/BladeView/BladeView.Properties.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public partial class BladeView
2626
/// </summary>
2727
public static readonly DependencyProperty BladeModeProperty = DependencyProperty.RegisterAttached(nameof(BladeMode), typeof(BladeMode), typeof(BladeView), new PropertyMetadata(BladeMode.Normal, OnBladeModeChanged));
2828

29-
/// <summary>
30-
/// Identifies the <see cref="AutoCollapseCountThreshold"/> attached property.
31-
/// </summary>
32-
public static readonly DependencyProperty AutoCollapseCountThresholdProperty = DependencyProperty.RegisterAttached(nameof(AutoCollapseCountThreshold), typeof(int), typeof(BladeView), new PropertyMetadata(int.MaxValue, OnOpenBladesChanged));
33-
3429
/// <summary>
3530
/// Gets or sets a collection of visible blades
3631
/// </summary>
@@ -49,24 +44,6 @@ public BladeMode BladeMode
4944
set { SetValue(BladeModeProperty, value); }
5045
}
5146

52-
/// <summary>
53-
/// Gets or sets a value indicating what the overflow amount should be to start auto collapsing blade items
54-
/// </summary>
55-
/// <example>
56-
/// For example we put AutoCollapseCountThreshold = 2
57-
/// This means that each time a blade is added to the bladeview collection,
58-
/// we will validate the amount of added blades that have a title bar visible.
59-
/// If this number get's bigger than AutoCollapseCountThreshold, we will collapse all blades but the last one
60-
/// </example>
61-
/// <remarks>
62-
/// We don't touch blade items that have no title bar
63-
/// </remarks>
64-
public int AutoCollapseCountThreshold
65-
{
66-
get { return (int)GetValue(AutoCollapseCountThresholdProperty); }
67-
set { SetValue(AutoCollapseCountThresholdProperty, value); }
68-
}
69-
7047
private static void OnBladeModeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
7148
{
7249
var bladeView = (BladeView)dependencyObject;

src/Files.App.Controls/BladeView/BladeView.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,6 @@ private void CycleBlades()
105105
}
106106
}
107107
}
108-
109-
// For now we skip this feature when blade mode is set to fullscreen
110-
if (AutoCollapseCountThreshold > 0 && BladeMode != BladeMode.Fullscreen && ActiveBlades.Any())
111-
{
112-
var openBlades = ActiveBlades.Where(item => item.TitleBarVisibility == Visibility.Visible).ToList();
113-
if (openBlades.Count > AutoCollapseCountThreshold)
114-
{
115-
for (int i = 0; i < openBlades.Count - 1; i++)
116-
{
117-
openBlades[i].IsExpanded = false;
118-
}
119-
}
120-
}
121108
}
122109

123110
private BladeItem GetBladeItem(object item)
@@ -161,12 +148,6 @@ await DispatcherQueue.EnqueueAsync(
161148

162149
BladeClosed?.Invoke(this, blade);
163150
ActiveBlades.Remove(blade);
164-
165-
var lastBlade = ActiveBlades.LastOrDefault();
166-
if (lastBlade != null && lastBlade.TitleBarVisibility == Visibility.Visible)
167-
{
168-
lastBlade.IsExpanded = true;
169-
}
170151
}
171152

172153
private ScrollViewer GetScrollViewer()

0 commit comments

Comments
 (0)