Skip to content

Code Quality: Renamed user control class names #14810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Files.App/Data/Contexts/ContentPage/ContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ private void ToolbarViewModel_PropertyChanged(object? sender, PropertyChangedEve
{
switch (e.PropertyName)
{
case nameof(ToolbarViewModel.CanGoBack):
case nameof(ToolbarViewModel.CanGoForward):
case nameof(ToolbarViewModel.CanNavigateToParent):
case nameof(ToolbarViewModel.HasItem):
case nameof(ToolbarViewModel.CanRefresh):
case nameof(ToolbarViewModel.IsSearchBoxVisible):
case nameof(AddressToolbarViewModel.CanGoBack):
case nameof(AddressToolbarViewModel.CanGoForward):
case nameof(AddressToolbarViewModel.CanNavigateToParent):
case nameof(AddressToolbarViewModel.HasItem):
case nameof(AddressToolbarViewModel.CanRefresh):
case nameof(AddressToolbarViewModel.IsSearchBoxVisible):
OnPropertyChanged(e.PropertyName);
break;
case nameof(ToolbarViewModel.SelectedItems):
case nameof(AddressToolbarViewModel.SelectedItems):
UpdateSelectedItems();
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Views;
using Microsoft.UI.Xaml.Controls;
using Windows.ApplicationModel.DataTransfer;

namespace Files.App.UserControls
namespace Files.App.Data.Contracts
{
public interface IAddressToolbar
public interface IAddressToolbarViewModel
{
public bool IsSearchBoxVisible { get; set; }

public bool IsEditModeEnabled { get; set; }

/// <summary>
/// Boolean to determine if the command palette is open
/// Gets or sets the value that indicates whether the command palette is open.
/// </summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the comment be kept?

Copy link
Member Author

@0x5bfa 0x5bfa Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add back and add comments to all of them in the next time for sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this one back before I merge?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

public bool IsCommandPaletteOpen { get; set; }

Expand Down Expand Up @@ -50,6 +46,6 @@ public interface IAddressToolbar

public void SwitchSearchBoxVisibility();

public ISearchBox SearchBox { get; }
public ISearchBoxViewModel SearchBox { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

using Windows.Foundation;

namespace Files.App.UserControls
namespace Files.App.Data.Contracts
{
public interface ISearchBox
public interface ISearchBoxViewModel
{
event TypedEventHandler<ISearchBox, SearchBoxTextChangedEventArgs> TextChanged;
event TypedEventHandler<ISearchBoxViewModel, SearchBoxTextChangedEventArgs> TextChanged;

event TypedEventHandler<ISearchBox, SearchBoxQuerySubmittedEventArgs> QuerySubmitted;
event TypedEventHandler<ISearchBoxViewModel, SearchBoxQuerySubmittedEventArgs> QuerySubmitted;

event EventHandler<ISearchBox> Escaped;
event EventHandler<ISearchBoxViewModel> Escaped;

bool WasQuerySubmitted { get; set; }

Expand Down
21 changes: 13 additions & 8 deletions src/Files.App/Extensions/Fractions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using System;
using System.Linq;

namespace Files.App.Helpers
namespace Files.App.Extensions
{
/// <summary>
/// Some simple helper methods to convert doubles to fractions
/// Provides extension to convert doubles to fractions
/// </summary>
public static class Fractions
{
public static string ToFractions(this double number, int precision = 4)
{
int w, n, d;
RoundToMixedFraction(number, precision, out w, out n, out d);
RoundToMixedFraction(number, precision, out var w, out var n, out var d);

var ret = $"{w}";

if (w > 0)
{
if (n > 0)
Expand All @@ -26,6 +24,7 @@ public static string ToFractions(this double number, int precision = 4)
if (n > 0)
ret = $"{n}/{d}";
}

return ret;
}

Expand All @@ -34,23 +33,29 @@ private static void RoundToMixedFraction(double input, int accuracy, out int who
double dblAccuracy = accuracy;
whole = (int)(Math.Truncate(input));
var fraction = Math.Abs(input - whole);

if (fraction == 0)
{
numerator = 0;
denominator = 1;

return;
}

var n = Enumerable.Range(0, accuracy + 1).SkipWhile(e => (e / dblAccuracy) < fraction).First();
var hi = n / dblAccuracy;
var lo = (n - 1) / dblAccuracy;
if ((fraction - lo) < (hi - fraction)) n--;

if (n == accuracy)
{
whole++;
numerator = 0;
denominator = 1;

return;
}

var gcd = GCD(n, accuracy);
numerator = n / gcd;
denominator = accuracy / gcd;
Expand All @@ -61,4 +66,4 @@ private static int GCD(int a, int b)
return b == 0 ? a : GCD(b, a % b);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Helpers;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.UserControls
namespace Files.App.Extensions
{
public class ImageFromBytes : DependencyObject
{
Expand All @@ -20,7 +19,11 @@ public static void SetSourceBytes(DependencyObject obj, byte[] value)
}

public static readonly DependencyProperty SourceBytesProperty =
DependencyProperty.RegisterAttached("SourceBytes", typeof(byte[]), typeof(ImageFromBytes), new PropertyMetadata(null, OnSourceBytesChangedAsync));
DependencyProperty.RegisterAttached(
"SourceBytes",
typeof(byte[]),
typeof(ImageFromBytes),
new PropertyMetadata(null, OnSourceBytesChangedAsync));

private static async void OnSourceBytesChangedAsync(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;

namespace Files.App.Views
namespace Files.App.Helpers
{
internal class NavigationInteractionTracker : IDisposable
{
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/UserControls/AddressToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public bool ShowSearchBox

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

Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public InnerNavigationToolbar()

public AppModel AppModel => App.AppModel;

public ToolbarViewModel? ViewModel
public AddressToolbarViewModel? ViewModel
{
get => (ToolbarViewModel)GetValue(ViewModelProperty);
get => (AddressToolbarViewModel)GetValue(ViewModelProperty);
set => SetValue(ViewModelProperty, value);
}

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

public bool ShowViewControlButton
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/PathBreadcrumb.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Files.App.UserControls
{
[DependencyProperty<ToolbarViewModel>("ViewModel")]
[DependencyProperty<AddressToolbarViewModel>("ViewModel")]
public sealed partial class PathBreadcrumb : UserControl
{
public PathBreadcrumb()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Copyright (c) 2023 Files Community. Licensed under the MIT License. See the LICENSE. -->
<UserControl
x:Class="Files.App.UserControls.StatusBarControl"
x:Class="Files.App.UserControls.StatusBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:Files.App.Converters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Files.App.UserControls
{
public sealed partial class StatusBarControl : UserControl
public sealed partial class StatusBar : UserControl
{
public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();

Expand All @@ -19,7 +19,7 @@ public DirectoryPropertiesViewModel? DirectoryPropertiesViewModel

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

public SelectedItemsPropertiesViewModel? SelectedItemsPropertiesViewModel
{
Expand All @@ -28,7 +28,7 @@ public SelectedItemsPropertiesViewModel? SelectedItemsPropertiesViewModel
}

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

public bool ShowInfoText
{
Expand All @@ -38,9 +38,9 @@ public bool ShowInfoText

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

public StatusBarControl()
public StatusBar()
{
InitializeComponent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Files.App.ViewModels.UserControls
{
public class ToolbarViewModel : ObservableObject, IAddressToolbar, IDisposable
public class AddressToolbarViewModel : ObservableObject, IAddressToolbarViewModel, IDisposable
{
private const int MAX_SUGGESTIONS = 10;

Expand Down Expand Up @@ -45,11 +45,11 @@ public class ToolbarViewModel : ObservableObject, IAddressToolbar, IDisposable

public event ToolbarPathItemLoadedEventHandler? ToolbarPathItemLoaded;

public event IAddressToolbar.ItemDraggedOverPathItemEventHandler? ItemDraggedOverPathItem;
public event IAddressToolbarViewModel.ItemDraggedOverPathItemEventHandler? ItemDraggedOverPathItem;

public event EventHandler? EditModeEnabled;

public event IAddressToolbar.ToolbarQuerySubmittedEventHandler? PathBoxQuerySubmitted;
public event IAddressToolbarViewModel.ToolbarQuerySubmittedEventHandler? PathBoxQuerySubmitted;

public event AddressBarTextEnteredEventHandler? AddressBarTextEntered;

Expand Down Expand Up @@ -201,7 +201,7 @@ public Style LayoutOpacityIcon

private PointerRoutedEventArgs? pointerRoutedEventArgs;

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

private ISearchBox searchBox = new SearchBoxViewModel();
public ISearchBox SearchBox
private ISearchBoxViewModel searchBox = new SearchBoxViewModel();
public ISearchBoxViewModel SearchBox
{
get => searchBox;
set => SetProperty(ref searchBox, value);
Expand Down Expand Up @@ -347,7 +347,7 @@ public async Task PathBoxItem_DragOver(object sender, DragEventArgs e)
dragOverPath = pathBoxItem.Path;
dragOverTimer.Stop();

if (dragOverPath != (this as IAddressToolbar).PathComponents.LastOrDefault()?.Path)
if (dragOverPath != (this as IAddressToolbarViewModel).PathComponents.LastOrDefault()?.Path)
{
dragOverTimer.Debounce(() =>
{
Expand Down Expand Up @@ -482,7 +482,7 @@ public void VisiblePath_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuer
{
PathBoxQuerySubmitted?.Invoke(this, new ToolbarQuerySubmittedEventArgs() { QueryText = args.QueryText });

(this as IAddressToolbar).IsEditModeEnabled = false;
(this as IAddressToolbarViewModel).IsEditModeEnabled = false;
}

public void PathBoxItem_PointerPressed(object sender, PointerRoutedEventArgs e)
Expand Down Expand Up @@ -594,7 +594,7 @@ public void SearchRegion_LostFocus(object sender, RoutedEventArgs e)
CloseSearchBox();
}

private void SearchRegion_Escaped(object? sender, ISearchBox searchBox)
private void SearchRegion_Escaped(object? sender, ISearchBoxViewModel searchBox)
=> CloseSearchBox(true);

public IAsyncRelayCommand? OpenNewWindowCommand { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/ViewModels/UserControls/SearchBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Files.App.ViewModels.UserControls
{
public class SearchBoxViewModel : ObservableObject, ISearchBox
public class SearchBoxViewModel : ObservableObject, ISearchBoxViewModel
{
private string query;
public string Query
Expand All @@ -20,11 +20,11 @@ public string Query

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

public event TypedEventHandler<ISearchBox, SearchBoxTextChangedEventArgs>? TextChanged;
public event TypedEventHandler<ISearchBoxViewModel, SearchBoxTextChangedEventArgs>? TextChanged;

public event TypedEventHandler<ISearchBox, SearchBoxQuerySubmittedEventArgs>? QuerySubmitted;
public event TypedEventHandler<ISearchBoxViewModel, SearchBoxQuerySubmittedEventArgs>? QuerySubmitted;

public event EventHandler<ISearchBox>? Escaped;
public event EventHandler<ISearchBoxViewModel>? Escaped;

private readonly SuggestionComparer suggestionComparer = new SuggestionComparer();

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@
Unloaded="PreviewPane_Unloaded" />

<!-- Status Bar -->
<uc:StatusBarControl
x:Name="StatusBarControl"
<uc:StatusBar
x:Name="StatusBar"
Grid.Row="4"
Grid.ColumnSpan="3"
x:Load="False"
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ private void PaneHolder_PropertyChanged(object? sender, PropertyChangedEventArgs

private void UpdateStatusBarProperties()
{
if (StatusBarControl is not null)
if (StatusBar is not null)
{
StatusBarControl.DirectoryPropertiesViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.DirectoryPropertiesViewModel;
StatusBarControl.SelectedItemsPropertiesViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.SelectedItemsPropertiesViewModel;
StatusBar.DirectoryPropertiesViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.DirectoryPropertiesViewModel;
StatusBar.SelectedItemsPropertiesViewModel = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.SelectedItemsPropertiesViewModel;
}
}

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

// Defers the status bar loading until after the page has loaded to improve startup perf
FindName(nameof(StatusBarControl));
FindName(nameof(StatusBar));
FindName(nameof(InnerNavigationToolbar));
FindName(nameof(TabControl));
FindName(nameof(NavToolbar));
Expand Down
Loading