Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa committed May 18, 2023
1 parent b529bd1 commit 537681b
Show file tree
Hide file tree
Showing 18 changed files with 215 additions and 206 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// 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 Microsoft.UI.Xaml.Controls;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Files.App.Actions
{
Expand Down
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 : "-";
}
}
90 changes: 44 additions & 46 deletions src/Files.App/Dialogs/AddItemDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,72 +24,70 @@
<converters:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
</ContentDialog.Resources>

<Grid RowSpacing="24">
<Grid x:Name="RootGrid" RowSpacing="24">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

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

<Grid
x:Name="SelectionListContent"
<!-- 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}">
Width="400"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick"
ItemsSource="{x:Bind ViewModel.AddItemsList}">

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

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

<Grid Margin="0,0,10,0" VerticalAlignment="Center">
<!-- Thumbnail -->
<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>
<!-- Item Icon -->
<Viewbox
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" />
<!-- 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>
</Grid>

<StackPanel>
<!-- Content -->
<StackPanel>

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

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

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

</StackPanel>

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

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

</ListView>
</Grid>
</ListView>

</Grid>
</ContentDialog>
12 changes: 9 additions & 3 deletions src/Files.App/Dialogs/AddItemDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

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;
Expand All @@ -24,20 +27,23 @@ public AddItemDialog()
}

public new async Task<DialogResult> ShowAsync()
=> (DialogResult)await base.ShowAsync();
{
return (DialogResult)await base.ShowAsync();
}

private async void AddItemDialog_Loaded(object sender, RoutedEventArgs e)
{
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();
ViewModel.ResultType = ((AddItemDialogListItemViewModel)e.ClickedItem)?.ItemResult
?? throw new ArgumentNullException("ItemResult", $"{nameof(AddItemDialog)}.{nameof(ListView_ItemClick)}.e.ClickedItem was null.");

Hide();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Dialogs/CreateArchiveDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dataitems="using:Files.App.Data.Items"
xmlns:helpers="using:Files.App.Helpers"
xmlns:local="using:Files.App.Dialogs"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{helpers:ResourceString Name=CreateArchive}"
d:DesignHeight="300"
d:DesignWidth="400"
CloseButtonText="{helpers:ResourceString Name=Cancel}"
Closing="ContentDialog_Closing"
CornerRadius="{StaticResource OverlayCornerRadius}"
Expand Down Expand Up @@ -131,7 +129,7 @@
SelectedItem="{x:Bind ViewModel.SplittingSize, Mode=TwoWay}"
SelectedValuePath="Key">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="local:SplittingSizeItem">
<DataTemplate x:DataType="dataitems:SevenZipSplittingSizeItem">

<StackPanel Orientation="Horizontal" Spacing="4">
<TextBlock Text="{x:Bind Label}" />
Expand All @@ -158,11 +156,13 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!-- Header -->
<TextBlock
Grid.Column="0"
VerticalAlignment="Center"
Text="{helpers:ResourceString Name=Password}" />

<!-- Password Entering -->
<PasswordBox
x:Name="PasswordBox"
Grid.Column="1"
Expand Down
19 changes: 8 additions & 11 deletions src/Files.App/Dialogs/CreateArchiveDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

namespace Files.App.Dialogs
{
/// <summary>
/// Represents an <see cref="ContentDialog"/> UI for archive creation.
/// </summary>
public sealed partial class CreateArchiveDialog : ContentDialog
{
private bool canCreate = false;
public bool CanCreate => canCreate;
public bool CanCreate;

public string FileName
{
Expand Down Expand Up @@ -84,7 +86,7 @@ private void ContentDialog_Closing(ContentDialog _, ContentDialogClosingEventArg
ViewModel.PropertyChanged -= ViewModel_PropertyChanged;

if (e.Result is ContentDialogResult.Primary)
canCreate = true;
CanCreate = true;
}

private void PasswordBox_Loading(FrameworkElement _, object e)
Expand Down Expand Up @@ -137,8 +139,8 @@ public CompressionLevelItem CompressionLevel
public bool CanSplit
=> FileFormat.Key is ArchiveFormats.SevenZip;

private SplittingSizeItem splittingSize;
public SplittingSizeItem SplittingSize
private SevenZipSplittingSizeItem splittingSize;
public SevenZipSplittingSizeItem SplittingSize
{
get => splittingSize;
set => SetProperty(ref splittingSize, value);
Expand Down Expand Up @@ -184,7 +186,7 @@ public string Password
}
.ToImmutableList();

public IImmutableList<SplittingSizeItem> SplittingSizes { get; } = new List<SplittingSizeItem>
public IImmutableList<SevenZipSplittingSizeItem> SplittingSizes { get; } = new List<SevenZipSplittingSizeItem>
{
new(ArchiveSplittingSizes.None, "Do not split".GetLocalizedResource()),
new(ArchiveSplittingSizes.Mo10, ToSizeText(10)),
Expand Down Expand Up @@ -216,9 +218,4 @@ public record CompressionLevelItem(ArchiveCompressionLevels Key, string Label);
}
}

internal record SplittingSizeItem(ArchiveSplittingSizes Key, string Label, string Description = "")
{
public string Separator
=> string.IsNullOrEmpty(Description) ? string.Empty : "-";
}
}
43 changes: 26 additions & 17 deletions src/Files.App/Dialogs/CreateShortcutDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{helpers:ResourceString Name=NewShortcutDialogTitle}"
DataContext="{x:Bind ViewModel, Mode=OneWay}"
DefaultButton="Primary"
IsPrimaryButtonEnabled="{x:Bind ViewModel.IsLocationValid, Mode=OneWay}"
PrimaryButtonCommand="{x:Bind ViewModel.PrimaryButtonCommand}"
Expand All @@ -16,37 +17,43 @@
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">

<Border Width="400">
<Grid
x:Name="DestinationPathGrid"
ColumnSpacing="8"
RowSpacing="8">
<Grid
x:Name="RootGrid"
Width="400"
RowSpacing="8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<!-- Description -->
<TextBlock
Grid.Row="0"
Margin="0,0,0,20"
Text="{helpers:ResourceString Name=NewShortcutDialogDescription}"
TextWrapping="Wrap" />

<!-- Path Box Form -->
<Grid Grid.Row="1" ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<!-- Header -->
<TextBlock
Grid.ColumnSpan="2"
Margin="0,0,0,20"
Text="{helpers:ResourceString Name=NewShortcutDialogDescription}"
TextWrapping="Wrap" />

<TextBlock
Grid.Row="1"
Grid.Row="0"
Grid.ColumnSpan="2"
Text="{helpers:ResourceString Name=NewShortcutDialogPrompt}" />

<!-- Path Box -->
<!-- TextBox -->
<TextBox
x:Name="DestinationItemPath"
Grid.Row="2"
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Stretch"
PlaceholderText="C:\Users\"
Expand All @@ -60,13 +67,15 @@
</TextBox.Resources>
</TextBox>

<!-- Browse Button -->
<Button
x:Name="SelectDestination"
Grid.Row="2"
Grid.Row="1"
Grid.Column="1"
Command="{x:Bind ViewModel.SelectDestinationCommand}"
Content="{helpers:ResourceString Name=Browse}" />

</Grid>
</Border>

</Grid>
</ContentDialog>
16 changes: 8 additions & 8 deletions src/Files.App/Dialogs/CreateShortcutDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ namespace Files.App.Dialogs
{
public sealed partial class CreateShortcutDialog : ContentDialog, IDialog<CreateShortcutDialogViewModel>
{
public CreateShortcutDialogViewModel ViewModel
{
get => (CreateShortcutDialogViewModel)DataContext;
set => DataContext = value;
}
public CreateShortcutDialogViewModel ViewModel { get; set; }

public CreateShortcutDialog()
{
InitializeComponent();
this.Closing += CreateShortcutDialog_Closing;

Closing += CreateShortcutDialog_Closing;

InvalidPathWarning.SetBinding(TeachingTip.TargetProperty, new Binding()
{
Expand All @@ -28,11 +25,14 @@ public CreateShortcutDialog()
}

public new async Task<DialogResult> ShowAsync()
=> (DialogResult)await base.ShowAsync();
{
return (DialogResult)await base.ShowAsync();
}

private void CreateShortcutDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
this.Closing -= CreateShortcutDialog_Closing;
Closing -= CreateShortcutDialog_Closing;

InvalidPathWarning.IsOpen = false;
}
}
Expand Down
Loading

0 comments on commit 537681b

Please sign in to comment.