-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Feature: Added advanced options when creating archives #10524
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
yaira2
merged 29 commits into
files-community:main
from
cinqmilleans:CompressArchiveDialog
Nov 27, 2022
Merged
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
53ba92f
dialog
cinqmilleans 36bef7d
do not compress
cinqmilleans eccc2cd
visual
cinqmilleans 8a49070
fix light mode
cinqmilleans b64d000
remove unused code
cinqmilleans a391d9a
review 1
cinqmilleans 38f0aa2
style
cinqmilleans b311015
remove icon
cinqmilleans 73e1b73
perf
cinqmilleans d9696e8
name
cinqmilleans 731e78e
level
cinqmilleans 98a43da
restore thread
cinqmilleans a7c60b5
rename title
cinqmilleans 5d8939f
Merge branch 'files-community:main' into CompressArchiveDialog
cinqmilleans 572a5b1
use viewmodel
cinqmilleans 49b2b71
improves visibility
cinqmilleans e348c51
Archive XAML
yaira2 189001b
clean focus
cinqmilleans 68004d2
combobox label
cinqmilleans 32032b3
width 160
cinqmilleans c633383
compress others formats
cinqmilleans aa320e8
style
cinqmilleans 9aee64c
csproj
cinqmilleans be129d6
remove xz and bzip2
cinqmilleans e96dfb8
remove tar and gz
cinqmilleans 43b490f
Merge branch 'main' into CompressArchiveDialog
yaira2 e270369
use x:Bind
cinqmilleans 77842c0
Merge branch 'CompressArchiveDialog' of https://github.com/cinqmillea…
cinqmilleans 85d1b87
remove binding
cinqmilleans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<ContentDialog | ||
x:Class="Files.App.Dialogs.CompressArchiveDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:converters="using:Files.App.Converters" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:helpers="using:Files.App.Helpers" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:settings="using:Files.App.UserControls.Settings" | ||
Title="{helpers:ResourceString Name=CreateArchive}" | ||
d:DesignHeight="300" | ||
d:DesignWidth="400" | ||
CloseButtonText="{helpers:ResourceString Name=Cancel}" | ||
Closing="ContentDialog_Closing" | ||
CornerRadius="{StaticResource OverlayCornerRadius}" | ||
DefaultButton="Primary" | ||
IsPrimaryButtonEnabled="True" | ||
Loaded="ContentDialog_Loaded" | ||
PrimaryButtonText="{helpers:ResourceString Name=Create}" | ||
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}" | ||
Style="{StaticResource DefaultContentDialogStyle}" | ||
mc:Ignorable="d"> | ||
|
||
<ContentDialog.Resources> | ||
<ResourceDictionary> | ||
<converters:VisibilityInvertConverter x:Key="VisibilityInvertConverter" /> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="/ResourceDictionaries/RightAlignedToggleSwitchStyle.xaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</ContentDialog.Resources> | ||
|
||
<StackPanel Spacing="24"> | ||
|
||
<Grid Margin="12,16,12,0" ColumnSpacing="8"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
<TextBox | ||
x:Name="FileNameBox" | ||
Width="340" | ||
VerticalAlignment="Bottom" | ||
Header="{helpers:ResourceString Name=ArchiveName}" | ||
PlaceholderText="{helpers:ResourceString Name=EnterName}" | ||
Text="{x:Bind FileName, Mode=TwoWay}" /> | ||
<ComboBox | ||
x:Name="FileFormatSelector" | ||
Grid.Column="1" | ||
MinWidth="100" | ||
VerticalAlignment="Bottom" | ||
ItemsSource="{x:Bind FileFormats}" | ||
SelectedValue="{x:Bind FileFormat, Mode=TwoWay}" | ||
SelectedValuePath="Key" | ||
SelectionChanged="FileFormatSelector_SelectionChanged"> | ||
<ComboBox.ItemTemplate> | ||
<DataTemplate> | ||
<Grid ColumnSpacing="24"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
<TextBlock Text="{Binding Label}" /> | ||
<TextBlock | ||
Grid.Column="1" | ||
VerticalAlignment="Bottom" | ||
FontSize="12" | ||
FontWeight="Light" | ||
Text="{Binding Description}" | ||
TextWrapping="Wrap" | ||
Visibility="{Binding IsDropDownOpen, ElementName=FileFormatSelector}" /> | ||
</Grid> | ||
</DataTemplate> | ||
</ComboBox.ItemTemplate> | ||
</ComboBox> | ||
</Grid> | ||
|
||
<ScrollViewer | ||
Height="268" | ||
Margin="0" | ||
Padding="12,0" | ||
HorizontalAlignment="Stretch" | ||
VerticalScrollBarVisibility="Visible" | ||
VerticalScrollMode="Enabled"> | ||
<StackPanel | ||
Grid.Row="1" | ||
Grid.ColumnSpan="2" | ||
Spacing="4"> | ||
<StackPanel.ChildrenTransitions> | ||
<TransitionCollection> | ||
<EntranceThemeTransition /> | ||
</TransitionCollection> | ||
</StackPanel.ChildrenTransitions> | ||
|
||
<settings:SettingsBlockControl Title="{helpers:ResourceString Name=DoNotCompress}" HorizontalAlignment="Stretch"> | ||
<settings:SettingsBlockControl.Icon> | ||
<FontIcon Glyph="" /> | ||
</settings:SettingsBlockControl.Icon> | ||
<ToggleSwitch | ||
x:Name="DoNotCompressSwitch" | ||
HorizontalAlignment="Right" | ||
IsOn="{x:Bind DoNotCompress, Mode=TwoWay}" | ||
Style="{StaticResource RightAlignedToggleSwitchStyle}" /> | ||
</settings:SettingsBlockControl> | ||
|
||
<settings:SettingsBlockControl | ||
Title="{helpers:ResourceString Name=SplittingSize}" | ||
HorizontalAlignment="Stretch" | ||
Description="{helpers:ResourceString Name=SplitArchiveDescription}"> | ||
<settings:SettingsBlockControl.Icon> | ||
<FontIcon Glyph="" /> | ||
</settings:SettingsBlockControl.Icon> | ||
<ComboBox | ||
x:Name="SplittingSizeSelector" | ||
HorizontalAlignment="Right" | ||
DisplayMemberPath="Label" | ||
IsEnabled="False" | ||
ItemsSource="{x:Bind SplittingSizes}" | ||
SelectedValue="{x:Bind SplittingSize, Mode=TwoWay}" | ||
SelectedValuePath="Key" /> | ||
</settings:SettingsBlockControl> | ||
|
||
<StackPanel> | ||
<settings:SettingsBlockControl Title="{helpers:ResourceString Name=Encryption}" HorizontalAlignment="Stretch"> | ||
<settings:SettingsBlockControl.Icon> | ||
<FontIcon Glyph="" /> | ||
</settings:SettingsBlockControl.Icon> | ||
<ToggleSwitch | ||
x:Name="EncryptionSwitch" | ||
HorizontalAlignment="Right" | ||
Style="{StaticResource RightAlignedToggleSwitchStyle}" | ||
Toggled="EncryptionSwitch_Toggled" /> | ||
</settings:SettingsBlockControl> | ||
<Grid | ||
HorizontalAlignment="Stretch" | ||
Background="{StaticResource ExpanderDropDownBackground}" | ||
BorderBrush="{StaticResource ExpanderDropDownBorderBrush}" | ||
BorderThickness="{StaticResource ExpanderDropdownDownBorderThickness}" | ||
CornerRadius="{StaticResource ControlCornerRadius}" | ||
Visibility="{Binding IsOn, ElementName=EncryptionSwitch, Mode=OneWay}"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
<TextBlock | ||
Margin="24,0" | ||
VerticalAlignment="Center" | ||
Text="{helpers:ResourceString Name=Password}" /> | ||
<PasswordBox | ||
x:Name="PasswordBox" | ||
Grid.Column="1" | ||
MinWidth="160" | ||
MaxWidth="280" | ||
Margin="16,8" | ||
HorizontalAlignment="Right" | ||
IsPasswordRevealButtonEnabled="True" | ||
Password="{x:Bind Password, Mode=TwoWay}" | ||
PasswordChanging="PasswordBox_PasswordChanging" | ||
PasswordRevealMode="Peek" | ||
PlaceholderText="{helpers:ResourceString Name=Password}" /> | ||
</Grid> | ||
</StackPanel> | ||
|
||
</StackPanel> | ||
</ScrollViewer> | ||
|
||
</StackPanel> | ||
|
||
</ContentDialog> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using Files.App.Extensions; | ||
using Files.App.Filesystem.Archive; | ||
using Files.Backend.Models; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using Windows.Foundation.Metadata; | ||
|
||
namespace Files.App.Dialogs | ||
{ | ||
public sealed partial class CompressArchiveDialog : ContentDialog | ||
{ | ||
public static readonly DependencyProperty FileNameProperty = DependencyProperty | ||
.Register(nameof(FileName), typeof(string), typeof(CompressArchiveDialog), new(string.Empty)); | ||
|
||
public static readonly DependencyProperty PasswordProperty = DependencyProperty | ||
.Register(nameof(Password), typeof(string), typeof(CompressArchiveDialog), new(string.Empty)); | ||
|
||
public static readonly DependencyProperty FileFormatProperty = DependencyProperty | ||
.Register(nameof(FileFormat), typeof(ArchiveFormats), typeof(CompressArchiveDialog), new(ArchiveFormats.Zip)); | ||
|
||
public static readonly DependencyProperty DoNotCompressProperty = DependencyProperty | ||
.Register(nameof(DoNotCompress), typeof(bool), typeof(CompressArchiveDialog), new(false)); | ||
|
||
public static readonly DependencyProperty SplittingSizeProperty = DependencyProperty | ||
.Register(nameof(SplittingSize), typeof(ArchiveSplittingSizes), typeof(CompressArchiveDialog), new(ArchiveSplittingSizes.None)); | ||
|
||
private bool canCreate = false; | ||
public bool CanCreate => canCreate; | ||
|
||
public string FileName | ||
{ | ||
get => (string)GetValue(FileNameProperty); | ||
set => SetValue(FileNameProperty, value); | ||
} | ||
|
||
public string Password | ||
{ | ||
get => (string)GetValue(PasswordProperty); | ||
set => SetValue(PasswordProperty, value); | ||
} | ||
|
||
public ArchiveFormats FileFormat | ||
{ | ||
get => (ArchiveFormats)GetValue(FileFormatProperty); | ||
set => SetValue(FileFormatProperty, (int)value); | ||
} | ||
|
||
public bool DoNotCompress | ||
{ | ||
get => (bool)GetValue(DoNotCompressProperty); | ||
set => SetValue(DoNotCompressProperty, value); | ||
} | ||
|
||
public ArchiveSplittingSizes SplittingSize | ||
{ | ||
get => (ArchiveSplittingSizes)GetValue(SplittingSizeProperty); | ||
set => SetValue(SplittingSizeProperty, (int)value); | ||
} | ||
|
||
private IImmutableList<FileFormatItem> FileFormats { get; } = new List<FileFormatItem> | ||
{ | ||
new(ArchiveFormats.Zip, ".zip", "CompressionFormatZipDescription".GetLocalizedResource()), | ||
new(ArchiveFormats.SevenZip, ".7z", "CompressionFormatSevenZipDescription".GetLocalizedResource()), | ||
}.ToImmutableList(); | ||
|
||
private IImmutableList<SplittingSizeItem> SplittingSizes { get; } = new List<SplittingSizeItem> | ||
{ | ||
new(ArchiveSplittingSizes.None, "Do not split".GetLocalizedResource()), | ||
new(ArchiveSplittingSizes.Mo10, ToSizeText(10)), | ||
new(ArchiveSplittingSizes.Mo100, ToSizeText(100)), | ||
new(ArchiveSplittingSizes.Cd650, ToSizeText(650, "CD".GetLocalizedResource())), | ||
new(ArchiveSplittingSizes.Cd700, ToSizeText(700, "CD".GetLocalizedResource())), | ||
new(ArchiveSplittingSizes.Mo1024, ToSizeText(1024)), | ||
new(ArchiveSplittingSizes.Fat4092, ToSizeText(4092, "FAT".GetLocalizedResource())), | ||
new(ArchiveSplittingSizes.Dvd4480, ToSizeText(4480, "DVD".GetLocalizedResource())), | ||
new(ArchiveSplittingSizes.Mo5120, ToSizeText(5120)), | ||
new(ArchiveSplittingSizes.Dvd8128, ToSizeText(8128, "DVD".GetLocalizedResource())), | ||
new(ArchiveSplittingSizes.Bd23040, ToSizeText(23040, "Bluray".GetLocalizedResource())), | ||
}.ToImmutableList(); | ||
|
||
public CompressArchiveDialog() => InitializeComponent(); | ||
|
||
public new Task<ContentDialogResult> ShowAsync() => SetContentDialogRoot(this).ShowAsync().AsTask(); | ||
|
||
private static ContentDialog SetContentDialogRoot(ContentDialog contentDialog) | ||
{ | ||
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) | ||
contentDialog.XamlRoot = App.Window.Content.XamlRoot; // WinUi3 | ||
return contentDialog; | ||
} | ||
|
||
private static string ToSizeText(ulong size) => ByteSize.FromMebiBytes(size).ShortString; | ||
private static string ToSizeText(ulong size, string labelKey) => $"{ToSizeText(size)} - {labelKey}"; | ||
|
||
private void ContentDialog_Loaded(object _, RoutedEventArgs e) | ||
{ | ||
Loaded -= ContentDialog_Loaded; | ||
|
||
FileFormatSelector.SelectedItem = FileFormats.First(format => format.Key == FileFormat); | ||
DoNotCompressSwitch.IsOn = DoNotCompress; | ||
SplittingSizeSelector.SelectedItem = SplittingSizes.First(size => size.Key == SplittingSize); | ||
SplittingSizeSelector.IsEnabled = FileFormat is ArchiveFormats.SevenZip; | ||
EncryptionSwitch.IsOn = Password.Length > 0; | ||
|
||
FileNameBox.SelectionStart = FileNameBox.Text.Length; | ||
FileNameBox.Focus(FocusState.Programmatic); | ||
} | ||
private void ContentDialog_Closing(ContentDialog _, ContentDialogClosingEventArgs e) | ||
{ | ||
Closing -= ContentDialog_Closing; | ||
FileFormatSelector.SelectionChanged -= FileFormatSelector_SelectionChanged; | ||
|
||
if (e.Result is ContentDialogResult.Primary) | ||
canCreate = true; | ||
} | ||
|
||
private void FileFormatSelector_SelectionChanged(object _, SelectionChangedEventArgs e) | ||
{ | ||
SplittingSizeSelector.IsEnabled = FileFormat is ArchiveFormats.SevenZip; | ||
} | ||
private void EncryptionSwitch_Toggled(object _, RoutedEventArgs e) | ||
{ | ||
if (EncryptionSwitch.IsOn) | ||
PasswordBox.Focus(FocusState.Programmatic); | ||
else | ||
Password = string.Empty; | ||
} | ||
private void PasswordBox_PasswordChanging(PasswordBox _, PasswordBoxPasswordChangingEventArgs e) | ||
{ | ||
if (PasswordBox.Password.Length > 0) | ||
EncryptionSwitch.IsOn = true; | ||
} | ||
|
||
private record FileFormatItem(ArchiveFormats Key, string Label, string Description); | ||
private record SplittingSizeItem(ArchiveSplittingSizes Key, string Label); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.