Skip to content

Commit d040c24

Browse files
committed
Revert "Code Quality: Refactored ToolbarViewModel (#13659)"
This reverts commit 60f714f.
1 parent 56399ad commit d040c24

22 files changed

+714
-725
lines changed

src/Files.App/App.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ private IHost ConfigureHost()
144144
.AddSingleton<NetworkDrivesViewModel>()
145145
.AddSingleton<StatusCenterViewModel>()
146146
.AddSingleton<AppearanceViewModel>()
147-
.AddSingleton<PathBreadcrumbViewModel>()
148-
.AddSingleton<AddressToolbarViewModel>()
149147
).Build();
150148
}
151149

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ private void ToolbarViewModel_PropertyChanged(object? sender, PropertyChangedEve
164164
{
165165
switch (e.PropertyName)
166166
{
167-
case nameof(AddressToolbarViewModel.CanGoBack):
168-
case nameof(AddressToolbarViewModel.CanGoForward):
169-
case nameof(AddressToolbarViewModel.CanNavigateToParent):
170-
case nameof(AddressToolbarViewModel.HasItem):
171-
case nameof(AddressToolbarViewModel.CanRefresh):
172-
case nameof(AddressToolbarViewModel.IsSearchBoxVisible):
167+
case nameof(ToolbarViewModel.CanGoBack):
168+
case nameof(ToolbarViewModel.CanGoForward):
169+
case nameof(ToolbarViewModel.CanNavigateToParent):
170+
case nameof(ToolbarViewModel.HasItem):
171+
case nameof(ToolbarViewModel.CanRefresh):
172+
case nameof(ToolbarViewModel.IsSearchBoxVisible):
173173
OnPropertyChanged(e.PropertyName);
174174
break;
175-
case nameof(AddressToolbarViewModel.SelectedItems):
175+
case nameof(ToolbarViewModel.SelectedItems):
176176
UpdateSelectedItems();
177177
break;
178178
}

src/Files.App/Data/EventArguments/PathBoxItemDroppedEventArgs.cs

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

88
namespace Files.App.Data.EventArguments
99
{
10-
public class PathBreadcrumbItemDroppedEventArgs
10+
public class PathBoxItemDroppedEventArgs
1111
{
1212
public DataPackageView Package { get; set; }
1313

src/Files.App/Data/EventArguments/ToolbarPathItemLoadedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public class ToolbarPathItemLoadedEventArgs
1111
{
1212
public MenuFlyout OpenedFlyout { get; set; }
1313

14-
public PathBreadcrumbItem Item { get; set; }
14+
public PathBoxItem Item { get; set; }
1515
}
1616
}

src/Files.App/Data/Items/PathBreadcrumbItem.cs renamed to src/Files.App/Data/Items/PathBoxItem.cs

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

44
namespace Files.App.Data.Items
55
{
6-
public class PathBreadcrumbItem
6+
public class PathBoxItem
77
{
8-
public string? Name { get; set; }
8+
public string? Title { get; set; }
99

1010
public string? Path { get; set; }
1111
}

src/Files.App/Data/Models/AppModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public int TabStripSelectedIndex
3737

3838
if (value >= 0 && value < MainPageViewModel.AppInstances.Count)
3939
{
40-
var mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
41-
mainPageViewModel.SelectedTabItem = MainPageViewModel.AppInstances[value];
40+
Frame rootFrame = (Frame)MainWindow.Instance.Content;
41+
var mainView = (MainPage)rootFrame.Content;
42+
mainView.ViewModel.SelectedTabItem = MainPageViewModel.AppInstances[value];
4243
}
4344
}
4445
}

src/Files.App/Data/TemplateSelectors/PathBreadcrumbItemSelector.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ internal sealed class PathBreadcrumbItemSelector : DataTemplateSelector
1515

1616
public DataTemplate? CurrentItem { get; set; }
1717

18-
protected override DataTemplate? SelectTemplateCore(object item, DependencyObject container)
18+
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
1919
{
2020
var itemsControl = ItemsControl.ItemsControlFromItemContainer(container);
2121

22-
if (itemsControl.ItemsSource is ObservableCollection<PathBreadcrumbItem> items)
22+
if (itemsControl.ItemsSource is ObservableCollection<PathBoxItem> items)
2323
{
2424
return
2525
itemsControl.IndexFromContainer(container) == items.Count - 1
2626
? CurrentItem!
2727
: ParentItems!;
2828
}
29-
30-
return null;
29+
else
30+
{
31+
throw new ArgumentException($"Type of {nameof(itemsControl.ItemsSource)} doesn't match ObservableCollection<{nameof(PathBoxItem)}>");
32+
}
3133
}
3234
}
3335
}

src/Files.App/UserControls/AddressToolbar.xaml

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
77
xmlns:contract8Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,8)"
8+
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
89
xmlns:converters="using:Files.App.Converters"
10+
xmlns:converters1="using:CommunityToolkit.WinUI.UI.Converters"
911
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
12+
xmlns:extensions="using:CommunityToolkit.WinUI.UI"
1013
xmlns:helpers="using:Files.App.Helpers"
1114
xmlns:items="using:Files.App.Data.Items"
1215
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
16+
xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers"
1317
xmlns:uc="using:Files.App.UserControls"
14-
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
15-
xmlns:wctextensions="using:CommunityToolkit.WinUI.UI"
16-
xmlns:wcttriggers="using:CommunityToolkit.WinUI.UI.Triggers"
18+
x:Name="NavToolbar"
1719
Height="50"
18-
DataContext="{x:Bind ViewModel, Mode=OneWay}"
20+
d:DesignHeight="50"
21+
d:DesignWidth="800"
1922
Loading="NavToolbar_Loading"
2023
mc:Ignorable="d">
2124

2225
<UserControl.Resources>
2326
<ResourceDictionary>
2427
<converters:NullToTrueConverter x:Key="NullToFalseConverter" Inverse="True" />
25-
<wctconverters:BoolNegationConverter x:Key="BoolNegationConverter" />
28+
<converters1:BoolNegationConverter x:Key="BoolNegationConverter" />
2629

2730
<ResourceDictionary.MergedDictionaries>
2831
<ResourceDictionary>
@@ -223,39 +226,39 @@
223226
x:Name="Back"
224227
x:FieldModifier="public"
225228
AccessKey="B"
226-
AutomationProperties.FullDescription="{x:Bind Commands.NavigateBack.Description, Mode=OneWay}"
227-
AutomationProperties.Name="{x:Bind Commands.NavigateBack.Label, Mode=OneWay}"
228-
Command="{x:Bind Commands.NavigateBack, Mode=OneWay}"
229-
IsEnabled="{x:Bind Commands.NavigateBack.IsExecutable, Mode=OneWay}"
229+
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateBack.Description, Mode=OneWay}"
230+
AutomationProperties.Name="{x:Bind ViewModel.Commands.NavigateBack.Label, Mode=OneWay}"
231+
Command="{x:Bind ViewModel.Commands.NavigateBack, Mode=OneWay}"
232+
IsEnabled="{x:Bind ViewModel.Commands.NavigateBack.IsExecutable, Mode=OneWay}"
230233
Style="{StaticResource AddressToolbarButtonStyle}"
231-
ToolTipService.ToolTip="{x:Bind Commands.NavigateBack.LabelWithHotKey, Mode=OneWay}">
232-
<FontIcon FontSize="14" Glyph="{x:Bind Commands.NavigateBack.Glyph.BaseGlyph, Mode=OneWay}" />
234+
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.NavigateBack.LabelWithHotKey, Mode=OneWay}">
235+
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.Commands.NavigateBack.Glyph.BaseGlyph, Mode=OneWay}" />
233236
</Button>
234237

235238
<Button
236239
x:Name="Forward"
237240
x:FieldModifier="public"
238241
AccessKey="F"
239-
AutomationProperties.FullDescription="{x:Bind Commands.NavigateForward.Description, Mode=OneWay}"
240-
AutomationProperties.Name="{x:Bind Commands.NavigateForward.Label, Mode=OneWay}"
241-
Command="{x:Bind Commands.NavigateForward, Mode=OneWay}"
242-
IsEnabled="{x:Bind Commands.NavigateForward.IsExecutable, Mode=OneWay}"
242+
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateForward.Description, Mode=OneWay}"
243+
AutomationProperties.Name="{x:Bind ViewModel.Commands.NavigateForward.Label, Mode=OneWay}"
244+
Command="{x:Bind ViewModel.Commands.NavigateForward, Mode=OneWay}"
245+
IsEnabled="{x:Bind ViewModel.Commands.NavigateForward.IsExecutable, Mode=OneWay}"
243246
Style="{StaticResource AddressToolbarButtonStyle}"
244-
ToolTipService.ToolTip="{x:Bind Commands.NavigateForward.LabelWithHotKey, Mode=OneWay}">
245-
<FontIcon FontSize="14" Glyph="{x:Bind Commands.NavigateForward.Glyph.BaseGlyph, Mode=OneWay}" />
247+
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.NavigateForward.LabelWithHotKey, Mode=OneWay}">
248+
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.Commands.NavigateForward.Glyph.BaseGlyph, Mode=OneWay}" />
246249
</Button>
247250

248251
<Button
249252
x:Name="Up"
250253
x:FieldModifier="public"
251254
AccessKey="U"
252-
AutomationProperties.FullDescription="{x:Bind Commands.NavigateUp.Description, Mode=OneWay}"
253-
AutomationProperties.Name="{x:Bind Commands.NavigateUp.Label, Mode=OneWay}"
254-
Command="{x:Bind Commands.NavigateUp, Mode=OneWay}"
255-
IsEnabled="{x:Bind Commands.NavigateUp.IsExecutable, Mode=OneWay}"
255+
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateUp.Description, Mode=OneWay}"
256+
AutomationProperties.Name="{x:Bind ViewModel.Commands.NavigateUp.Label, Mode=OneWay}"
257+
Command="{x:Bind ViewModel.Commands.NavigateUp, Mode=OneWay}"
258+
IsEnabled="{x:Bind ViewModel.Commands.NavigateUp.IsExecutable, Mode=OneWay}"
256259
Style="{StaticResource AddressToolbarButtonStyle}"
257-
ToolTipService.ToolTip="{x:Bind Commands.NavigateUp.LabelWithHotKey, Mode=OneWay}">
258-
<FontIcon FontSize="14" Glyph="{x:Bind Commands.NavigateUp.Glyph.BaseGlyph, Mode=OneWay}" />
260+
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.NavigateUp.LabelWithHotKey, Mode=OneWay}">
261+
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.Commands.NavigateUp.Glyph.BaseGlyph, Mode=OneWay}" />
259262
</Button>
260263

261264
<Button
@@ -338,7 +341,7 @@
338341
MinHeight="33"
339342
HorizontalAlignment="Stretch"
340343
VerticalAlignment="Center"
341-
wctextensions:FrameworkElementExtensions.Cursor="Hand"
344+
extensions:FrameworkElementExtensions.Cursor="Hand"
342345
x:Load="{x:Bind ViewModel.ClickablePathLoaded, Mode=OneWay}"
343346
Background="{ThemeResource TextControlBackground}"
344347
BorderBrush="{ThemeResource ControlElevationBorderBrush}"
@@ -350,19 +353,17 @@
350353
<ColumnDefinition Width="*" />
351354
<ColumnDefinition Width="Auto" />
352355
</Grid.ColumnDefinitions>
353-
354356
<uc:PathBreadcrumb
355357
Grid.Column="0"
356358
VerticalAlignment="Stretch"
357359
HorizontalContentAlignment="Stretch"
358-
VerticalContentAlignment="Stretch" />
359-
360+
VerticalContentAlignment="Stretch"
361+
ViewModel="{x:Bind ViewModel, Mode=OneWay}" />
360362
<FontIcon
361363
Grid.Column="1"
362364
Margin="12"
363365
FontSize="16"
364366
Glyph="&#xE70D;" />
365-
366367
</Grid>
367368

368369
<!-- Storage Search Box -->
@@ -389,11 +390,11 @@
389390
<Button
390391
x:Name="ShowSearchButton"
391392
AccessKey="I"
392-
AutomationProperties.Name="{x:Bind Commands.Search.Label}"
393-
Command="{x:Bind Commands.Search, Mode=OneWay}"
394-
IsEnabled="{x:Bind Commands.Search.IsExecutable}"
393+
AutomationProperties.Name="{x:Bind ViewModel.Commands.Search.Label}"
394+
Command="{x:Bind ViewModel.Commands.Search, Mode=OneWay}"
395+
IsEnabled="{x:Bind ViewModel.Commands.Search.IsExecutable}"
395396
Style="{StaticResource AddressToolbarButtonStyle}"
396-
ToolTipService.ToolTip="{x:Bind Commands.Search.LabelWithHotKey, Mode=OneWay}"
397+
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.Search.LabelWithHotKey, Mode=OneWay}"
397398
Visibility="Collapsed">
398399
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.SearchButtonGlyph, Mode=OneWay}" />
399400
</Button>
@@ -406,15 +407,15 @@
406407
AutomationProperties.Name="{helpers:ResourceString Name=StatusCenter}"
407408
Style="{StaticResource AddressToolbarButtonStyle}"
408409
ToolTipService.ToolTip="{helpers:ResourceString Name=StatusCenter}"
409-
Visibility="{x:Bind StatusCenterViewModel.HasAnyItem, Mode=OneWay}">
410+
Visibility="{x:Bind OngoingTasksViewModel.HasAnyItem, Mode=OneWay}">
410411

411412
<Grid Margin="-16">
412413

413414
<uc:OpacityIcon
414415
x:Name="StatusCenterIcon"
415416
Width="16"
416417
Height="16"
417-
x:Load="{x:Bind StatusCenterViewModel.HasAnyItemInProgress, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}"
418+
x:Load="{x:Bind OngoingTasksViewModel.HasAnyItemInProgress, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}"
418419
Style="{StaticResource ColorIconStatusCenter}" />
419420

420421
<ProgressRing
@@ -423,16 +424,16 @@
423424
Height="20"
424425
HorizontalAlignment="Center"
425426
VerticalAlignment="Center"
426-
x:Load="{x:Bind StatusCenterViewModel.HasAnyItemInProgress, Mode=OneWay}"
427+
x:Load="{x:Bind OngoingTasksViewModel.HasAnyItemInProgress, Mode=OneWay}"
427428
Background="{ThemeResource SubtleFillColorSecondaryBrush}"
428429
IsIndeterminate="False"
429-
Value="{x:Bind StatusCenterViewModel.AverageOperationProgressValue, Mode=OneWay}" />
430+
Value="{x:Bind OngoingTasksViewModel.AverageOperationProgressValue, Mode=OneWay}" />
430431

431432
<InfoBadge
432433
x:Name="StatusInfoBadge"
433434
HorizontalAlignment="Right"
434435
VerticalAlignment="Top"
435-
Value="{x:Bind StatusCenterViewModel.InfoBadgeValue, Mode=OneWay}" />
436+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeValue, Mode=OneWay}" />
436437

437438
</Grid>
438439

@@ -513,11 +514,11 @@
513514
x:Name="SettingsButton"
514515
AccessKey="I"
515516
AutomationProperties.AutomationId="SettingsButton"
516-
AutomationProperties.Name="{x:Bind Commands.OpenSettings.Label, Mode=OneWay}"
517-
Command="{x:Bind Commands.OpenSettings, Mode=OneWay}"
517+
AutomationProperties.Name="{x:Bind ViewModel.Commands.OpenSettings.Label, Mode=OneWay}"
518+
Command="{x:Bind ViewModel.Commands.OpenSettings, Mode=OneWay}"
518519
Style="{StaticResource AddressToolbarButtonStyle}"
519520
ToolTipService.Placement="Bottom"
520-
ToolTipService.ToolTip="{x:Bind Commands.OpenSettings.LabelWithHotKey, Mode=OneWay}"
521+
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.OpenSettings.LabelWithHotKey, Mode=OneWay}"
521522
Visibility="{x:Bind ShowSettingsButton, Mode=OneWay}">
522523
<AnimatedIcon x:Name="SettingAnimatedIcon" Height="16">
523524
<AnimatedIcon.Source>
@@ -544,13 +545,13 @@
544545
<VisualStateGroup>
545546
<VisualState x:Name="SearchBoxAlwaysShown">
546547
<VisualState.StateTriggers>
547-
<wcttriggers:IsEqualStateTrigger Value="{x:Bind ShowSearchBox, Mode=OneWay}" To="True" />
548+
<triggers:IsEqualStateTrigger Value="{x:Bind ShowSearchBox, Mode=OneWay}" To="True" />
548549
</VisualState.StateTriggers>
549550
</VisualState>
550551

551552
<VisualState x:Name="SearchBoxCollapse">
552553
<VisualState.StateTriggers>
553-
<wcttriggers:IsEqualStateTrigger Value="{x:Bind ShowSearchBox, Mode=OneWay}" To="False" />
554+
<triggers:IsEqualStateTrigger Value="{x:Bind ShowSearchBox, Mode=OneWay}" To="False" />
554555
</VisualState.StateTriggers>
555556
<VisualState.Setters>
556557
<Setter Target="ShowSearchButton.Visibility" Value="Visible" />
@@ -562,31 +563,43 @@
562563
<VisualStateGroup>
563564
<VisualState x:Name="TasksSuccess">
564565
<VisualState.StateTriggers>
565-
<wcttriggers:IsEqualStateTrigger Value="{x:Bind StatusCenterViewModel.InfoBadgeState, Mode=OneWay}" To="0" />
566+
<triggers:CompareStateTrigger
567+
Comparison="Equal"
568+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}"
569+
To="0" />
566570
</VisualState.StateTriggers>
567571
<VisualState.Setters>
568572
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource SuccessIconInfoBadgeStyle}" />
569573
</VisualState.Setters>
570574
</VisualState>
571575
<VisualState x:Name="TasksOnging">
572576
<VisualState.StateTriggers>
573-
<wcttriggers:IsEqualStateTrigger Value="{x:Bind StatusCenterViewModel.InfoBadgeState, Mode=OneWay}" To="1" />
577+
<triggers:CompareStateTrigger
578+
Comparison="Equal"
579+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}"
580+
To="1" />
574581
</VisualState.StateTriggers>
575582
<VisualState.Setters>
576583
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource AttentionValueInfoBadgeStyle}" />
577584
</VisualState.Setters>
578585
</VisualState>
579586
<VisualState x:Name="TasksFailure">
580587
<VisualState.StateTriggers>
581-
<wcttriggers:IsEqualStateTrigger Value="{x:Bind StatusCenterViewModel.InfoBadgeState, Mode=OneWay}" To="2" />
588+
<triggers:CompareStateTrigger
589+
Comparison="Equal"
590+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}"
591+
To="2" />
582592
</VisualState.StateTriggers>
583593
<VisualState.Setters>
584594
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource CriticalValueInfoBadgeStyle}" />
585595
</VisualState.Setters>
586596
</VisualState>
587597
<VisualState x:Name="TasksCompletionWithFailure">
588598
<VisualState.StateTriggers>
589-
<wcttriggers:IsEqualStateTrigger Value="{x:Bind StatusCenterViewModel.InfoBadgeState, Mode=OneWay}" To="3" />
599+
<triggers:CompareStateTrigger
600+
Comparison="Equal"
601+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}"
602+
To="3" />
590603
</VisualState.StateTriggers>
591604
<VisualState.Setters>
592605
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource CriticalIconInfoBadgeStyle}" />
@@ -596,4 +609,4 @@
596609
</VisualStateManager.VisualStateGroups>
597610
</Grid>
598611

599-
</UserControl>
612+
</UserControl>

0 commit comments

Comments
 (0)