Skip to content
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

Code Quality: Refactor Status Center code #13276

Merged
merged 49 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7e79a8f
Update
0x5bfa Aug 28, 2023
6a8eeb4
Update
0x5bfa Aug 28, 2023
d591931
Update
0x5bfa Aug 28, 2023
5acc69b
Update
0x5bfa Aug 28, 2023
e2044ee
Update
0x5bfa Aug 29, 2023
23de240
Update
0x5bfa Aug 29, 2023
0bd8193
merge main into this branch
0x5bfa Aug 29, 2023
62f4627
Update
0x5bfa Aug 29, 2023
ddea7bc
Update
0x5bfa Aug 29, 2023
debc847
Merge branch 'main' into 5bfa/Cleanup-StatusCenter
0x5bfa Aug 29, 2023
a039945
Update
0x5bfa Aug 30, 2023
873dd58
Merge branch '5bfa/Cleanup-StatusCenter' of https://github.com/0x5bfa…
0x5bfa Aug 30, 2023
1b75d89
Update
0x5bfa Aug 30, 2023
072a144
Merge branch 'files-community:main' into 5bfa/Cleanup-StatusCenter
0x5bfa Aug 31, 2023
f4f553e
Update
0x5bfa Aug 31, 2023
57630b4
Merge branch '5bfa/Cleanup-StatusCenter' of https://github.com/0x5bfa…
0x5bfa Aug 31, 2023
fb1f27b
Update
0x5bfa Aug 31, 2023
85c53af
Update
0x5bfa Aug 31, 2023
3c23e18
Update
0x5bfa Sep 1, 2023
7898286
Merge branch 'main' into 5bfa/Cleanup-StatusCenter
0x5bfa Sep 3, 2023
9400514
Update
0x5bfa Sep 3, 2023
4cf7063
Merge branch '5bfa/Cleanup-StatusCenter' of https://github.com/0x5bfa…
0x5bfa Sep 3, 2023
a5d72f2
Update
0x5bfa Sep 4, 2023
5952832
Update
0x5bfa Sep 4, 2023
1e4e7cf
Update
0x5bfa Sep 4, 2023
11de1e8
Remove unsued files
0x5bfa Sep 5, 2023
dbbfa64
Merge branch 'main' into 5bfa/Cleanup-StatusCenter
0x5bfa Sep 5, 2023
c224a08
Update
0x5bfa Sep 5, 2023
380294b
Remove lib deps
0x5bfa Sep 5, 2023
1f9d238
Update src/Files.App/UserControls/AddressToolbar.xaml
0x5bfa Sep 6, 2023
e249517
Update src/Files.App/UserControls/AddressToolbar.xaml
0x5bfa Sep 6, 2023
13feb5e
Update src/Files.App/UserControls/AddressToolbar.xaml
0x5bfa Sep 6, 2023
f324da0
Update
0x5bfa Sep 6, 2023
3306ead
Merge branch '5bfa/Cleanup-StatusCenter' of https://github.com/0x5bfa…
0x5bfa Sep 6, 2023
adf1b95
Update resources
0x5bfa Sep 6, 2023
1a120fe
Update
0x5bfa Sep 6, 2023
ddc5b9c
Update src/Files.Core/Data/Enums/StatusCenterItemKind.cs
0x5bfa Sep 6, 2023
88f9bc0
Update src/Files.Core/Data/Enums/StatusCenterItemIconKind.cs
0x5bfa Sep 7, 2023
b801404
Add path icons
yaira2 Sep 7, 2023
a405172
Update PathIcons.xaml
yaira2 Sep 7, 2023
4beb9eb
Renamed
0x5bfa Sep 7, 2023
7e0052e
Merge branch '5bfa/Cleanup-StatusCenter' of https://github.com/0x5bfa…
0x5bfa Sep 7, 2023
f45729e
Update icon sources
0x5bfa Sep 7, 2023
3eac7f8
Merge branch 'main' into 5bfa/Cleanup-StatusCenter
0x5bfa Sep 7, 2023
f8ee22f
Fix
0x5bfa Sep 9, 2023
fcf2518
Merge branch '5bfa/Cleanup-StatusCenter' of https://github.com/0x5bfa…
0x5bfa Sep 9, 2023
5f5784c
Requested changes
0x5bfa Sep 11, 2023
886e049
Fix
0x5bfa Sep 11, 2023
722e6a4
Fix
0x5bfa Sep 12, 2023
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
2 changes: 1 addition & 1 deletion src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private async void Window_Closed(object sender, WindowEventArgs args)
UIHelpers.CloseAllDialogs();

// Close all notification banners except in progress
Ioc.Default.GetRequiredService<StatusCenterViewModel>().CloseAllBanner();
Ioc.Default.GetRequiredService<StatusCenterViewModel>().CloseAllCompletedItems();

// Cache the window instead of closing it
MainWindow.Instance.AppWindow.Hide();
Expand Down
20 changes: 20 additions & 0 deletions src/Files.App/Converters/EnumToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml.Data;

namespace Files.App.Converters
{
internal sealed class EnumToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return value?.ToString() ?? string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
24 changes: 15 additions & 9 deletions src/Files.App/Helpers/UI/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Files.App.Helpers
{
public static class UIFilesystemHelpers
{
private static readonly StatusCenterViewModel ongoingTasksViewModel = Ioc.Default.GetRequiredService<StatusCenterViewModel>();
private static readonly StatusCenterViewModel _statusCenterViewModel = Ioc.Default.GetRequiredService<StatusCenterViewModel>();

public static async Task CutItem(IShellPage associatedInstance)
{
Expand All @@ -33,7 +33,7 @@ public static async Task CutItem(IShellPage associatedInstance)
associatedInstance.SlimContentPage.ItemManipulationModel.RefreshItemsOpacity();

var itemsCount = associatedInstance.SlimContentPage.SelectedItems!.Count;
var banner = itemsCount > 50 ? ongoingTasksViewModel.PostOperationBanner(
var banner = itemsCount > 50 ? _statusCenterViewModel.AddItem(
string.Empty,
string.Format("StatusPreparingItemsDetails_Plural".GetLocalizedResource(), itemsCount),
0,
Expand Down Expand Up @@ -98,15 +98,18 @@ await associatedInstance.SlimContentPage.SelectedItems.ToList().ParallelForEachA

await FileOperationsHelpers.SetClipboard(filePaths, DataPackageOperation.Move);

banner?.Remove();
_statusCenterViewModel.CloseItem(banner);
yaira2 marked this conversation as resolved.
Show resolved Hide resolved

return;
}
associatedInstance.SlimContentPage.ItemManipulationModel.RefreshItemsOpacity();
banner?.Remove();

_statusCenterViewModel.CloseItem(banner);

return;
}

banner?.Remove();
_statusCenterViewModel.CloseItem(banner);
}

var onlyStandard = items.All(x => x is StorageFile || x is StorageFolder || x is SystemStorageFile || x is SystemStorageFolder);
Expand Down Expand Up @@ -141,7 +144,7 @@ public static async Task CopyItem(IShellPage associatedInstance)
associatedInstance.SlimContentPage.ItemManipulationModel.RefreshItemsOpacity();

var itemsCount = associatedInstance.SlimContentPage.SelectedItems!.Count;
var banner = itemsCount > 50 ? ongoingTasksViewModel.PostOperationBanner(
var banner = itemsCount > 50 ? _statusCenterViewModel.AddItem(
string.Empty,
string.Format("StatusPreparingItemsDetails_Plural".GetLocalizedResource(), itemsCount),
0,
Expand Down Expand Up @@ -195,14 +198,17 @@ await associatedInstance.SlimContentPage.SelectedItems.ToList().ParallelForEachA

await FileOperationsHelpers.SetClipboard(filePaths, DataPackageOperation.Copy);

banner?.Remove();
_statusCenterViewModel.CloseItem(banner);

return;
}
banner?.Remove();

_statusCenterViewModel.CloseItem(banner);

return;
}

banner?.Remove();
_statusCenterViewModel.CloseItem(banner);
}

var onlyStandard = items.All(x => x is StorageFile || x is StorageFolder || x is SystemStorageFile || x is SystemStorageFolder);
Expand Down
146 changes: 78 additions & 68 deletions src/Files.App/UserControls/AddressToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,7 @@
</ResourceDictionary>
</UserControl.Resources>

<Grid
x:Name="ToolbarGrid"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{ThemeResource App.Theme.AddressBar.BackgroundBrush}"
ColumnSpacing="0">
<Grid x:Name="RootGrid" Background="{ThemeResource App.Theme.AddressBar.BackgroundBrush}">
<Grid Padding="8" ColumnSpacing="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand All @@ -222,6 +217,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!-- Page Navigation Actions -->
<StackPanel
Grid.Row="1"
Orientation="Horizontal"
Expand Down Expand Up @@ -278,6 +274,7 @@
</Button>
</StackPanel>

<!-- Path Box -->
<AutoSuggestBox
x:Name="VisiblePath"
Grid.Column="1"
Expand Down Expand Up @@ -337,6 +334,7 @@
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>

<!-- Path Breadcrumb Bar -->
<Grid
x:Name="ClickablePath"
Grid.Column="1"
Expand Down Expand Up @@ -368,6 +366,7 @@
Glyph="&#xE70D;" />
</Grid>

<!-- Storage Search Box -->
<uc:SearchBox
x:Name="SearchRegion"
Grid.Column="2"
Expand All @@ -384,9 +383,12 @@
SearchBoxViewModel="{x:Bind ViewModel.SearchBoxViewModel, Mode=OneWay}"
Visibility="{x:Bind converters:MultiBooleanConverter.OrConvertToVisibility(ShowSearchBox, ViewModel.IsSearchBoxVisible), Mode=OneWay}" />

<!-- Right Side Action Buttons -->
<StackPanel Grid.Column="3" Orientation="Horizontal">

<!-- Search Button Shwon When The Window Is Small -->
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
<Button
x:Name="SearchButton"
x:Name="ShowSearchButton"
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this was being used in a visual state, I'll open a PR to fix.

AccessKey="I"
AutomationProperties.Name="{x:Bind ViewModel.Commands.Search.Label}"
Command="{x:Bind ViewModel.Commands.Search, Mode=OneWay}"
Expand All @@ -397,65 +399,70 @@
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.SearchButtonGlyph, Mode=OneWay}" />
</Button>

<Grid Visibility="{x:Bind OngoingTasksViewModel.AnyBannersPresent, Mode=OneWay}">
<Button
x:Name="OngoingTasks"
Padding="0"
AccessKey="T"
AutomationProperties.Name="{helpers:ResourceString Name=OngoingTasks}"
Style="{StaticResource AddressToolbarButtonStyle}"
ToolTipService.ToolTip="{helpers:ResourceString Name=OngoingTasks}">
<Button.Content>
<Grid>
<FontIcon
x:Name="OngoingTasksFontIcon"
x:Load="{x:Bind OngoingTasksViewModel.AnyOperationsOngoing, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}"
FontSize="16"
Glyph="&#xF16A;" />

<ProgressRing
x:Name="MedianOperationProgressRing"
Width="20"
Height="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
x:Load="{x:Bind OngoingTasksViewModel.AnyOperationsOngoing, Mode=OneWay}"
IsIndeterminate="False"
Value="{x:Bind OngoingTasksViewModel.MedianOperationProgressValue, Mode=OneWay}" />
</Grid>
</Button.Content>
<Button.Flyout>
<Flyout
contract8Present:ShouldConstrainToRootBounds="False"
AutomationProperties.Name="{helpers:ResourceString Name=OngoingTasks}"
Placement="BottomEdgeAlignedRight">
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="Padding" Value="0" />
<Setter Property="CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
</Style>
</Flyout.FlyoutPresenterStyle>

<uc:StatusCenter
x:Name="OngoingTasksControl"
Width="400"
MinHeight="300"
MaxHeight="500"
x:FieldModifier="public"
IsTabStop="True" />
</Flyout>
</Button.Flyout>
</Button>
<InfoBadge
x:Name="StatusInfoBadge"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Value="{x:Bind OngoingTasksViewModel.InfoBadgeValue, Mode=OneWay}" />
</Grid>

<!-- Install Update Notification -->
<!-- Statuc Center -->
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
<Button
x:Name="UpdateButton"
x:Name="ShowStatusCenterButton"
Padding="0"
AccessKey="T"
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
AutomationProperties.Name="{helpers:ResourceString Name=OngoingTasks}"
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
Style="{StaticResource AddressToolbarButtonStyle}"
ToolTipService.ToolTip="{helpers:ResourceString Name=OngoingTasks}"
Visibility="{x:Bind OngoingTasksViewModel.HasAnyItem, Mode=OneWay}">

<Grid Margin="-16">
yaira2 marked this conversation as resolved.
Show resolved Hide resolved

<FontIcon
x:Name="OngoingTasksFontIcon"
x:Load="{x:Bind OngoingTasksViewModel.HasAnyItemInProgress, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}"
FontSize="16"
Glyph="&#xF16A;" />

<ProgressRing
x:Name="MedianOperationProgressRing"
Width="20"
Height="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
x:Load="{x:Bind OngoingTasksViewModel.HasAnyItemInProgress, Mode=OneWay}"
Background="{ThemeResource SubtleFillColorSecondaryBrush}"
IsIndeterminate="False"
Value="{x:Bind OngoingTasksViewModel.AverageOperationProgressValue, Mode=OneWay}" />

<InfoBadge
x:Name="StatusInfoBadge"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Value="{x:Bind OngoingTasksViewModel.InfoBadgeValue, Mode=OneWay}" />

</Grid>

<Button.Flyout>
<Flyout
contract8Present:ShouldConstrainToRootBounds="False"
AutomationProperties.Name="{helpers:ResourceString Name=OngoingTasks}"
Placement="BottomEdgeAlignedRight">
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="Padding" Value="0" />
<Setter Property="CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
</Style>
</Flyout.FlyoutPresenterStyle>

<uc:StatusCenter
x:Name="OngoingTasksControl"
Width="400"
MinHeight="300"
MaxHeight="500"
x:FieldModifier="public"
IsTabStop="True" />
</Flyout>
</Button.Flyout>

</Button>

<!-- Update The Files App Button When An Update Available -->
<Button
x:Name="UpdateAppButton"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
x:Load="{x:Bind ViewModel.IsUpdateAvailable, Mode=OneWay}"
Expand Down Expand Up @@ -484,9 +491,9 @@
</Grid>
</Button>

<!-- Update Release Notes -->
<!-- Show The Latest Version Release Note -->
<Button
x:Name="ViewReleaseNotesButton"
x:Name="ShowReleaseNotesButton"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
x:Load="{x:Bind ViewModel.IsReleaseNotesVisible, Mode=OneWay}"
Expand All @@ -501,6 +508,7 @@
Glyph="&#xF133;" />
</Button>

<!-- Show The Files App Settings Dialog -->
<Button
x:Name="SettingsButton"
AccessKey="I"
Expand All @@ -520,14 +528,16 @@
</AnimatedIcon.FallbackIconSource>
</AnimatedIcon>
</Button>

</StackPanel>

<!-- One-Time-Shown Statuc Center TeachingTip -->
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
<TeachingTip
x:Name="StatusCenterTeachingTip"
Title="{helpers:ResourceString Name=OngoingTasksTeachingTip/Title}"
IsOpen="False"
Subtitle="{helpers:ResourceString Name=OngoingTasksTeachingTip/Subtitle}"
Target="{x:Bind OngoingTasks}" />
Target="{x:Bind ShowStatusCenterButton}" />
</Grid>

<VisualStateManager.VisualStateGroups>
Expand Down
3 changes: 1 addition & 2 deletions src/Files.App/UserControls/AddressToolbar.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.StatusCenter;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -121,7 +120,7 @@ private void VisiblePath_LostFocus(object _, RoutedEventArgs e)
private void VisiblePath_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
=> ViewModel.VisiblePath_QuerySubmitted(sender, args);

private void OngoingTasksActions_ProgressBannerPosted(object? _, StatusCenterPostItem e)
private void OngoingTasksActions_ProgressBannerPosted(object? _, StatusCenterItem e)
{
if (OngoingTasksViewModel is not null)
OngoingTasksViewModel.ProgressBannerPosted -= OngoingTasksActions_ProgressBannerPosted;
Expand Down
Loading