Skip to content

Commit 3a3a718

Browse files
authored
Code Quality: Renamed user control class names (#14810)
1 parent 9743a4a commit 3a3a718

19 files changed

+76
-72
lines changed

src/Files.App/Data/Contexts/ContentPage/ContentPageContext.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ private void ToolbarViewModel_PropertyChanged(object? sender, PropertyChangedEve
160160
{
161161
switch (e.PropertyName)
162162
{
163-
case nameof(ToolbarViewModel.CanGoBack):
164-
case nameof(ToolbarViewModel.CanGoForward):
165-
case nameof(ToolbarViewModel.CanNavigateToParent):
166-
case nameof(ToolbarViewModel.HasItem):
167-
case nameof(ToolbarViewModel.CanRefresh):
168-
case nameof(ToolbarViewModel.IsSearchBoxVisible):
163+
case nameof(AddressToolbarViewModel.CanGoBack):
164+
case nameof(AddressToolbarViewModel.CanGoForward):
165+
case nameof(AddressToolbarViewModel.CanNavigateToParent):
166+
case nameof(AddressToolbarViewModel.HasItem):
167+
case nameof(AddressToolbarViewModel.CanRefresh):
168+
case nameof(AddressToolbarViewModel.IsSearchBoxVisible):
169169
OnPropertyChanged(e.PropertyName);
170170
break;
171-
case nameof(ToolbarViewModel.SelectedItems):
171+
case nameof(AddressToolbarViewModel.SelectedItems):
172172
UpdateSelectedItems();
173173
break;
174174
}

src/Files.App/UserControls/IAddressToolbar.cs renamed to src/Files.App/Data/Contracts/IAddressToolbarViewModel.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.Views;
5-
using Microsoft.UI.Xaml.Controls;
6-
using Windows.ApplicationModel.DataTransfer;
7-
8-
namespace Files.App.UserControls
4+
namespace Files.App.Data.Contracts
95
{
10-
public interface IAddressToolbar
6+
public interface IAddressToolbarViewModel
117
{
128
public bool IsSearchBoxVisible { get; set; }
139

1410
public bool IsEditModeEnabled { get; set; }
1511

1612
/// <summary>
17-
/// Boolean to determine if the command palette is open
13+
/// Gets or sets the value that indicates whether the command palette is open.
1814
/// </summary>
1915
public bool IsCommandPaletteOpen { get; set; }
2016

@@ -50,6 +46,6 @@ public interface IAddressToolbar
5046

5147
public void SwitchSearchBoxVisibility();
5248

53-
public ISearchBox SearchBox { get; }
49+
public ISearchBoxViewModel SearchBox { get; }
5450
}
5551
}

src/Files.App/UserControls/ISearchBox.cs renamed to src/Files.App/Data/Contracts/ISearchBoxViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
using Windows.Foundation;
55

6-
namespace Files.App.UserControls
6+
namespace Files.App.Data.Contracts
77
{
8-
public interface ISearchBox
8+
public interface ISearchBoxViewModel
99
{
10-
event TypedEventHandler<ISearchBox, SearchBoxTextChangedEventArgs> TextChanged;
10+
event TypedEventHandler<ISearchBoxViewModel, SearchBoxTextChangedEventArgs> TextChanged;
1111

12-
event TypedEventHandler<ISearchBox, SearchBoxQuerySubmittedEventArgs> QuerySubmitted;
12+
event TypedEventHandler<ISearchBoxViewModel, SearchBoxQuerySubmittedEventArgs> QuerySubmitted;
1313

14-
event EventHandler<ISearchBox> Escaped;
14+
event EventHandler<ISearchBoxViewModel> Escaped;
1515

1616
bool WasQuerySubmitted { get; set; }
1717

src/Files.App/Extensions/Fractions.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using System;
5-
using System.Linq;
6-
7-
namespace Files.App.Helpers
4+
namespace Files.App.Extensions
85
{
96
/// <summary>
10-
/// Some simple helper methods to convert doubles to fractions
7+
/// Provides extension to convert doubles to fractions
118
/// </summary>
129
public static class Fractions
1310
{
1411
public static string ToFractions(this double number, int precision = 4)
1512
{
16-
int w, n, d;
17-
RoundToMixedFraction(number, precision, out w, out n, out d);
13+
RoundToMixedFraction(number, precision, out var w, out var n, out var d);
14+
1815
var ret = $"{w}";
16+
1917
if (w > 0)
2018
{
2119
if (n > 0)
@@ -26,6 +24,7 @@ public static string ToFractions(this double number, int precision = 4)
2624
if (n > 0)
2725
ret = $"{n}/{d}";
2826
}
27+
2928
return ret;
3029
}
3130

@@ -34,23 +33,29 @@ private static void RoundToMixedFraction(double input, int accuracy, out int who
3433
double dblAccuracy = accuracy;
3534
whole = (int)(Math.Truncate(input));
3635
var fraction = Math.Abs(input - whole);
36+
3737
if (fraction == 0)
3838
{
3939
numerator = 0;
4040
denominator = 1;
41+
4142
return;
4243
}
44+
4345
var n = Enumerable.Range(0, accuracy + 1).SkipWhile(e => (e / dblAccuracy) < fraction).First();
4446
var hi = n / dblAccuracy;
4547
var lo = (n - 1) / dblAccuracy;
4648
if ((fraction - lo) < (hi - fraction)) n--;
49+
4750
if (n == accuracy)
4851
{
4952
whole++;
5053
numerator = 0;
5154
denominator = 1;
55+
5256
return;
5357
}
58+
5459
var gcd = GCD(n, accuracy);
5560
numerator = n / gcd;
5661
denominator = accuracy / gcd;
@@ -61,4 +66,4 @@ private static int GCD(int a, int b)
6166
return b == 0 ? a : GCD(b, a % b);
6267
}
6368
}
64-
}
69+
}

src/Files.App/UserControls/ImageFromBytes.cs renamed to src/Files.App/Extensions/ImageFromBytes.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.Helpers;
54
using Microsoft.UI.Xaml;
65
using Microsoft.UI.Xaml.Controls;
76

8-
namespace Files.App.UserControls
7+
namespace Files.App.Extensions
98
{
109
public class ImageFromBytes : DependencyObject
1110
{
@@ -20,7 +19,11 @@ public static void SetSourceBytes(DependencyObject obj, byte[] value)
2019
}
2120

2221
public static readonly DependencyProperty SourceBytesProperty =
23-
DependencyProperty.RegisterAttached("SourceBytes", typeof(byte[]), typeof(ImageFromBytes), new PropertyMetadata(null, OnSourceBytesChangedAsync));
22+
DependencyProperty.RegisterAttached(
23+
"SourceBytes",
24+
typeof(byte[]),
25+
typeof(ImageFromBytes),
26+
new PropertyMetadata(null, OnSourceBytesChangedAsync));
2427

2528
private static async void OnSourceBytesChangedAsync(DependencyObject d, DependencyPropertyChangedEventArgs e)
2629
{

src/Files.App/Views/NavigationInteractionTracker.cs renamed to src/Files.App/Helpers/Navigation/NavigationInteractionTracker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using System.Diagnostics.CodeAnalysis;
1111
using System.Numerics;
1212

13-
namespace Files.App.Views
13+
namespace Files.App.Helpers
1414
{
1515
internal class NavigationInteractionTracker : IDisposable
1616
{

src/Files.App/UserControls/AddressToolbar.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public bool ShowSearchBox
4545

4646
// Using a DependencyProperty as the backing store for ViewModel. This enables animation, styling, binding, etc...
4747
public static readonly DependencyProperty ViewModelProperty =
48-
DependencyProperty.Register(nameof(ViewModel), typeof(ToolbarViewModel), typeof(AddressToolbar), new PropertyMetadata(null));
49-
public ToolbarViewModel? ViewModel
48+
DependencyProperty.Register(nameof(ViewModel), typeof(AddressToolbarViewModel), typeof(AddressToolbar), new PropertyMetadata(null));
49+
public AddressToolbarViewModel? ViewModel
5050
{
51-
get => (ToolbarViewModel)GetValue(ViewModelProperty);
51+
get => (AddressToolbarViewModel)GetValue(ViewModelProperty);
5252
set => SetValue(ViewModelProperty, value);
5353
}
5454

src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public InnerNavigationToolbar()
2727

2828
public AppModel AppModel => App.AppModel;
2929

30-
public ToolbarViewModel? ViewModel
30+
public AddressToolbarViewModel? ViewModel
3131
{
32-
get => (ToolbarViewModel)GetValue(ViewModelProperty);
32+
get => (AddressToolbarViewModel)GetValue(ViewModelProperty);
3333
set => SetValue(ViewModelProperty, value);
3434
}
3535

3636
// Using a DependencyProperty as the backing store for ViewModel. This enables animation, styling, binding, etc...
3737
public static readonly DependencyProperty ViewModelProperty =
38-
DependencyProperty.Register(nameof(ViewModel), typeof(ToolbarViewModel), typeof(InnerNavigationToolbar), new PropertyMetadata(null));
38+
DependencyProperty.Register(nameof(ViewModel), typeof(AddressToolbarViewModel), typeof(InnerNavigationToolbar), new PropertyMetadata(null));
3939

4040
public bool ShowViewControlButton
4141
{

src/Files.App/UserControls/PathBreadcrumb.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Files.App.UserControls
99
{
10-
[DependencyProperty<ToolbarViewModel>("ViewModel")]
10+
[DependencyProperty<AddressToolbarViewModel>("ViewModel")]
1111
public sealed partial class PathBreadcrumb : UserControl
1212
{
1313
public PathBreadcrumb()

src/Files.App/UserControls/StatusBarControl.xaml renamed to src/Files.App/UserControls/StatusBar.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- Copyright (c) 2023 Files Community. Licensed under the MIT License. See the LICENSE. -->
22
<UserControl
3-
x:Class="Files.App.UserControls.StatusBarControl"
3+
x:Class="Files.App.UserControls.StatusBar"
44
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
xmlns:converters="using:Files.App.Converters"

src/Files.App/UserControls/StatusBarControl.xaml.cs renamed to src/Files.App/UserControls/StatusBar.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Files.App.UserControls
99
{
10-
public sealed partial class StatusBarControl : UserControl
10+
public sealed partial class StatusBar : UserControl
1111
{
1212
public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();
1313

@@ -19,7 +19,7 @@ public DirectoryPropertiesViewModel? DirectoryPropertiesViewModel
1919

2020
// Using a DependencyProperty as the backing store for DirectoryPropertiesViewModel. This enables animation, styling, binding, etc...
2121
public static readonly DependencyProperty DirectoryPropertiesViewModelProperty =
22-
DependencyProperty.Register(nameof(DirectoryPropertiesViewModel), typeof(DirectoryPropertiesViewModel), typeof(StatusBarControl), new PropertyMetadata(null));
22+
DependencyProperty.Register(nameof(DirectoryPropertiesViewModel), typeof(DirectoryPropertiesViewModel), typeof(StatusBar), new PropertyMetadata(null));
2323

2424
public SelectedItemsPropertiesViewModel? SelectedItemsPropertiesViewModel
2525
{
@@ -28,7 +28,7 @@ public SelectedItemsPropertiesViewModel? SelectedItemsPropertiesViewModel
2828
}
2929

3030
public static readonly DependencyProperty SelectedItemsPropertiesViewModelProperty =
31-
DependencyProperty.Register(nameof(SelectedItemsPropertiesViewModel), typeof(SelectedItemsPropertiesViewModel), typeof(StatusBarControl), new PropertyMetadata(null));
31+
DependencyProperty.Register(nameof(SelectedItemsPropertiesViewModel), typeof(SelectedItemsPropertiesViewModel), typeof(StatusBar), new PropertyMetadata(null));
3232

3333
public bool ShowInfoText
3434
{
@@ -38,9 +38,9 @@ public bool ShowInfoText
3838

3939
// Using a DependencyProperty as the backing store for HideInfoText. This enables animation, styling, binding, etc...
4040
public static readonly DependencyProperty ShowInfoTextProperty =
41-
DependencyProperty.Register(nameof(ShowInfoText), typeof(bool), typeof(StatusBarControl), new PropertyMetadata(null));
41+
DependencyProperty.Register(nameof(ShowInfoText), typeof(bool), typeof(StatusBar), new PropertyMetadata(null));
4242

43-
public StatusBarControl()
43+
public StatusBar()
4444
{
4545
InitializeComponent();
4646
}

src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs renamed to src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Files.App.ViewModels.UserControls
1717
{
18-
public class ToolbarViewModel : ObservableObject, IAddressToolbar, IDisposable
18+
public class AddressToolbarViewModel : ObservableObject, IAddressToolbarViewModel, IDisposable
1919
{
2020
private const int MAX_SUGGESTIONS = 10;
2121

@@ -45,11 +45,11 @@ public class ToolbarViewModel : ObservableObject, IAddressToolbar, IDisposable
4545

4646
public event ToolbarPathItemLoadedEventHandler? ToolbarPathItemLoaded;
4747

48-
public event IAddressToolbar.ItemDraggedOverPathItemEventHandler? ItemDraggedOverPathItem;
48+
public event IAddressToolbarViewModel.ItemDraggedOverPathItemEventHandler? ItemDraggedOverPathItem;
4949

5050
public event EventHandler? EditModeEnabled;
5151

52-
public event IAddressToolbar.ToolbarQuerySubmittedEventHandler? PathBoxQuerySubmitted;
52+
public event IAddressToolbarViewModel.ToolbarQuerySubmittedEventHandler? PathBoxQuerySubmitted;
5353

5454
public event AddressBarTextEnteredEventHandler? AddressBarTextEntered;
5555

@@ -201,7 +201,7 @@ public Style LayoutOpacityIcon
201201

202202
private PointerRoutedEventArgs? pointerRoutedEventArgs;
203203

204-
public ToolbarViewModel()
204+
public AddressToolbarViewModel()
205205
{
206206
RefreshClickCommand = new RelayCommand<RoutedEventArgs>(e => RefreshRequested?.Invoke(this, EventArgs.Empty));
207207
ViewReleaseNotesAsyncCommand = new AsyncRelayCommand(ViewReleaseNotesAsync);
@@ -268,8 +268,8 @@ private void UserSettingsService_OnSettingChangedEvent(object? sender, SettingCh
268268
private DispatcherQueue dispatcherQueue;
269269
private DispatcherQueueTimer dragOverTimer;
270270

271-
private ISearchBox searchBox = new SearchBoxViewModel();
272-
public ISearchBox SearchBox
271+
private ISearchBoxViewModel searchBox = new SearchBoxViewModel();
272+
public ISearchBoxViewModel SearchBox
273273
{
274274
get => searchBox;
275275
set => SetProperty(ref searchBox, value);
@@ -347,7 +347,7 @@ public async Task PathBoxItem_DragOver(object sender, DragEventArgs e)
347347
dragOverPath = pathBoxItem.Path;
348348
dragOverTimer.Stop();
349349

350-
if (dragOverPath != (this as IAddressToolbar).PathComponents.LastOrDefault()?.Path)
350+
if (dragOverPath != (this as IAddressToolbarViewModel).PathComponents.LastOrDefault()?.Path)
351351
{
352352
dragOverTimer.Debounce(() =>
353353
{
@@ -482,7 +482,7 @@ public void VisiblePath_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuer
482482
{
483483
PathBoxQuerySubmitted?.Invoke(this, new ToolbarQuerySubmittedEventArgs() { QueryText = args.QueryText });
484484

485-
(this as IAddressToolbar).IsEditModeEnabled = false;
485+
(this as IAddressToolbarViewModel).IsEditModeEnabled = false;
486486
}
487487

488488
public void PathBoxItem_PointerPressed(object sender, PointerRoutedEventArgs e)
@@ -594,7 +594,7 @@ public void SearchRegion_LostFocus(object sender, RoutedEventArgs e)
594594
CloseSearchBox();
595595
}
596596

597-
private void SearchRegion_Escaped(object? sender, ISearchBox searchBox)
597+
private void SearchRegion_Escaped(object? sender, ISearchBoxViewModel searchBox)
598598
=> CloseSearchBox(true);
599599

600600
public IAsyncRelayCommand? OpenNewWindowCommand { get; set; }

src/Files.App/ViewModels/UserControls/SearchBoxViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Files.App.ViewModels.UserControls
1111
{
12-
public class SearchBoxViewModel : ObservableObject, ISearchBox
12+
public class SearchBoxViewModel : ObservableObject, ISearchBoxViewModel
1313
{
1414
private string query;
1515
public string Query
@@ -20,11 +20,11 @@ public string Query
2020

2121
public bool WasQuerySubmitted { get; set; } = false;
2222

23-
public event TypedEventHandler<ISearchBox, SearchBoxTextChangedEventArgs>? TextChanged;
23+
public event TypedEventHandler<ISearchBoxViewModel, SearchBoxTextChangedEventArgs>? TextChanged;
2424

25-
public event TypedEventHandler<ISearchBox, SearchBoxQuerySubmittedEventArgs>? QuerySubmitted;
25+
public event TypedEventHandler<ISearchBoxViewModel, SearchBoxQuerySubmittedEventArgs>? QuerySubmitted;
2626

27-
public event EventHandler<ISearchBox>? Escaped;
27+
public event EventHandler<ISearchBoxViewModel>? Escaped;
2828

2929
private readonly SuggestionComparer suggestionComparer = new SuggestionComparer();
3030

src/Files.App/Views/MainPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@
268268
Unloaded="PreviewPane_Unloaded" />
269269

270270
<!-- Status Bar -->
271-
<uc:StatusBarControl
272-
x:Name="StatusBarControl"
271+
<uc:StatusBar
272+
x:Name="StatusBar"
273273
Grid.Row="4"
274274
Grid.ColumnSpan="3"
275275
x:Load="False"

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ private void PaneHolder_PropertyChanged(object? sender, PropertyChangedEventArgs
205205

206206
private void UpdateStatusBarProperties()
207207
{
208-
if (StatusBarControl is not null)
208+
if (StatusBar is not null)
209209
{
210-
StatusBarControl.DirectoryPropertiesViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.DirectoryPropertiesViewModel;
211-
StatusBarControl.SelectedItemsPropertiesViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.SelectedItemsPropertiesViewModel;
210+
StatusBar.DirectoryPropertiesViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.DirectoryPropertiesViewModel;
211+
StatusBar.SelectedItemsPropertiesViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.SelectedItemsPropertiesViewModel;
212212
}
213213
}
214214

@@ -291,7 +291,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
291291
MainWindow.Instance.AppWindow.Changed += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
292292

293293
// Defers the status bar loading until after the page has loaded to improve startup perf
294-
FindName(nameof(StatusBarControl));
294+
FindName(nameof(StatusBar));
295295
FindName(nameof(InnerNavigationToolbar));
296296
FindName(nameof(TabControl));
297297
FindName(nameof(NavToolbar));

0 commit comments

Comments
 (0)