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: Cleanup App.Dialogs #12381

Closed
wants to merge 8 commits into from
Closed
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
32 changes: 16 additions & 16 deletions src/Files.App/Actions/Content/Archives/CompressIntoArchiveAction.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Contexts;
using Files.App.Dialogs;
using Files.App.Extensions;
using Files.App.Filesystem.Archive;
using Files.App.Helpers;
using Files.App.ViewModels.Dialogs;
using Files.Backend.Services;
using Files.Backend.ViewModels.Dialogs;
using Microsoft.UI.Xaml.Controls;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class CompressIntoArchiveAction : BaseUIAction, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

private readonly IDialogService dialogService = Ioc.Default.GetRequiredService<IDialogService>();

private readonly CreateArchiveDialogViewModel viewModel = new();

public string Label => "CreateArchive".GetLocalizedResource();

public string Description => "CompressIntoArchiveDescription".GetLocalizedResource();
Expand All @@ -35,24 +37,22 @@ public async Task ExecuteAsync()
{
var (sources, directory, fileName) = ArchiveHelpers.GetCompressDestination(context.ShellPage);

var dialog = new CreateArchiveDialog
{
FileName = fileName,
};
var result = await dialog.TryShowAsync();
viewModel.FileName = fileName;

var result = await dialogService.ShowDialogAsync(viewModel);

if (!dialog.CanCreate || result != ContentDialogResult.Primary)
if (!viewModel.CanCreate || result != DialogResult.Primary)
return;

IArchiveCreator creator = new ArchiveCreator
{
Sources = sources,
Directory = directory,
FileName = dialog.FileName,
Password = dialog.Password,
FileFormat = dialog.FileFormat,
CompressionLevel = dialog.CompressionLevel,
SplittingSize = dialog.SplittingSize,
FileName = viewModel.FileName,
Password = viewModel.Password,
FileFormat = viewModel.FileFormat.Key,
CompressionLevel = viewModel.CompressionLevel.Key,
SplittingSize = viewModel.SplittingSize.Key,
};

await ArchiveHelpers.CompressArchiveAsync(creator);
Expand Down
7 changes: 1 addition & 6 deletions src/Files.App/Actions/Open/OpenSettingsAction.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.Backend.Services;
using Files.Backend.ViewModels.Dialogs;
using System.Threading.Tasks;

namespace Files.App.Actions
{
Expand All @@ -25,8 +21,7 @@ internal class OpenSettingsAction : BaseUIAction, IAction

public async Task ExecuteAsync()
{
var dialog = dialogService.GetDialog(viewModel);
await dialog.TryShowAsync();
await dialogService.ShowDialogAsync(viewModel);
}
}
}
13 changes: 13 additions & 0 deletions src/Files.App/Data/Items/SevenZipSplittingSizeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Filesystem.Archive;

namespace Files.App.Data.Items
{
public record SevenZipSplittingSizeItem(ArchiveSplittingSizes Key, string Label, string Description = "")
{
public string Separator
=> string.IsNullOrEmpty(Description) ? string.Empty : "-";
}
}
106 changes: 61 additions & 45 deletions src/Files.App/Dialogs/AddItemDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Grid.RowSpan="4"
BorderThickness="0"
CornerRadius="{StaticResource OverlayCornerRadius}"
DataContext="{x:Bind ViewModel, Mode=OneWay}"
Loaded="AddItemDialog_Loaded"
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}"
SecondaryButtonText="{helpers:ResourceString Name=Cancel}"
Expand All @@ -23,55 +24,70 @@
<converters:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
</ContentDialog.Resources>

<Grid RowSpacing="25">
<Grid x:Name="RootGrid" RowSpacing="24">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="SubtitleArea">
<TextBlock x:Name="Description" Text="{helpers:ResourceString Name=AddDialogDescription/Text}" />
</Grid>
<Grid
x:Name="SelectionListContent"

<!-- Description -->
<TextBlock Grid.Row="0" Text="{helpers:ResourceString Name=AddDialogDescription/Text}" />

<!-- Items ListView -->
<ListView
x:Name="AddItemsListView"
Grid.Row="1"
HorizontalAlignment="Stretch">
<ListView
x:Name="AddItemsListView"
Width="400"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick"
ItemsSource="{x:Bind ViewModel.AddItemsList}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="vm:AddItemDialogListItemViewModel">
<Grid Height="50">
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<Grid Margin="0,0,10,0" VerticalAlignment="Center">
<Viewbox
x:Name="IconRoot"
Width="24"
Height="24"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<FontIcon Glyph="{x:Bind Glyph, Mode=OneWay}" />
</Viewbox>
<Image
Width="24"
Height="24"
Margin="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Source="{x:Bind Icon, Mode=OneWay, Converter={StaticResource ImageModelToImageConverter}}"
Stretch="Uniform" />
</Grid>
<StackPanel>
<TextBlock Text="{x:Bind Header, Mode=OneWay}" />
<TextBlock Foreground="Gray" Text="{x:Bind SubHeader, Mode=OneWay}" />
</StackPanel>
Width="400"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick"
ItemsSource="{x:Bind ViewModel.AddItemsList}">

<ListView.ItemTemplate>
<DataTemplate x:DataType="vm:AddItemDialogListItemViewModel">
<Grid Height="48">

<StackPanel VerticalAlignment="Center" Orientation="Horizontal">

<!-- Thumbnail -->
<Grid Margin="0,0,12,0" VerticalAlignment="Center">

<!-- Item Icon -->
<Viewbox
Width="24"
Height="24"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<FontIcon Glyph="{x:Bind Glyph, Mode=OneWay}" />
</Viewbox>

<!-- Item Image -->
<Image
Width="24"
Height="24"
Margin="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Source="{x:Bind Icon, Mode=OneWay, Converter={StaticResource ImageModelToImageConverter}}"
Stretch="Uniform" />

</Grid>

<!-- Content -->
<StackPanel>

<TextBlock Text="{x:Bind Header, Mode=OneWay}" />

<TextBlock Foreground="Gray" Text="{x:Bind SubHeader, Mode=OneWay}" />

</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>

</StackPanel>

</Grid>
</DataTemplate>
</ListView.ItemTemplate>

</ListView>

</Grid>
</ContentDialog>
</ContentDialog>
41 changes: 21 additions & 20 deletions src/Files.App/Dialogs/AddItemDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.DependencyInjection;
using Files.Backend.Services;
using Files.Backend.ViewModels.Dialogs;
using Files.Backend.ViewModels.Dialogs.AddItemDialog;
using Files.Shared.Enums;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Threading.Tasks;

// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace Files.App.Dialogs
{
/// <summary>
/// Represents an <see cref="ContentDialog"/> UI for storage item addition.
/// </summary>
public sealed partial class AddItemDialog : ContentDialog, IDialog<AddItemDialogViewModel>
{
private readonly IAddItemService addItemService = Ioc.Default.GetRequiredService<IAddItemService>();
private readonly IAddItemService _addItemService;

public AddItemDialogViewModel ViewModel
{
get => (AddItemDialogViewModel)DataContext;
set => DataContext = value;
}
public AddItemDialogViewModel ViewModel { get; set; }

public AddItemDialog()
{
InitializeComponent();
}

public new async Task<DialogResult> ShowAsync() => (DialogResult)await base.ShowAsync();
// Dependency Injection
_addItemService = Ioc.Default.GetRequiredService<IAddItemService>();
}

private void ListView_ItemClick(object sender, ItemClickEventArgs e)
public new async Task<DialogResult> ShowAsync()
{
ViewModel.ResultType = (e.ClickedItem as AddItemDialogListItemViewModel).ItemResult;
Hide();
return (DialogResult)await base.ShowAsync();
}

private async void AddItemDialog_Loaded(object sender, RoutedEventArgs e)
{
var itemTypes = await addItemService.GetNewEntriesAsync();
var itemTypes = await _addItemService.GetNewEntriesAsync();
await ViewModel.AddItemsToList(itemTypes);

// Focus on the list view so users can use keyboard navigation
// Focus on the ListView so that the users can use keyboard navigation
AddItemsListView.Focus(FocusState.Programmatic);
}

private void ListView_ItemClick(object sender, ItemClickEventArgs e)
{
ViewModel.ResultType = ((AddItemDialogListItemViewModel)e.ClickedItem)?.ItemResult
?? throw new ArgumentNullException("ItemResult", $"{nameof(AddItemDialog)}.{nameof(ListView_ItemClick)}.e.ClickedItem was null.");

Hide();
}
}
}
}
Loading