Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public virtual string? SourcePath
if (SetProperty(ref _SourcePath, value))
{
OnPropertyChanged(nameof(SourceDirectoryDisplayName));
DisplayName = Path.GetFileName(value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ public string DestinationDirectoryDisplayName
get => Path.GetFileName(Path.GetDirectoryName(DestinationPath));
}

private bool _IsActionTaken;
public bool IsActionTaken
public bool IsDefault
{
get => _IsActionTaken;
set => SetProperty(ref _IsActionTaken, value);
get => ConflictResolveOption == FileNameConflictResolveOptionType.GenerateNewName; // Default value
}

public FileNameConflictResolveOptionType ConflictResolveOption { get; set; }
private FileNameConflictResolveOptionType _ConflictResolveOption;
public FileNameConflictResolveOptionType ConflictResolveOption
{
get => _ConflictResolveOption;
set => SetProperty(ref _ConflictResolveOption, value);
}

public ICommand GenerateNewNameCommand { get; }

Expand All @@ -56,7 +59,6 @@ public FileSystemDialogConflictItemViewModel()

public void TakeAction(FileNameConflictResolveOptionType conflictResolveOption)
{
IsActionTaken = true;
ConflictResolveOption = conflictResolveOption;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
using System.IO;

namespace Files.Backend.ViewModels.Dialogs.FileSystemDialog
namespace Files.Backend.ViewModels.Dialogs.FileSystemDialog
{
public sealed class FileSystemDialogDefaultItemViewModel : BaseFileSystemDialogItemViewModel
{
public override string? SourcePath
{
get => base.SourcePath;
set
{
if (base.SourcePath != value)
{
base.SourcePath = value;

DisplayName = Path.GetFileName(value);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ internal FileSystemDialogViewModel(FileSystemDialogMode fileSystemDialogMode, IE
_dialogClosingCts = new();
Items = new(items);

PrimaryButtonClickCommand = new RelayCommand(PrimaryButtonClick);
SecondaryButtonClickCommand = new RelayCommand(SecondaryButtonClick);
}

Expand All @@ -58,7 +57,7 @@ public void ApplyConflictOptionToAll(FileNameConflictResolveOptionType e)
{
foreach (var item in Items)
{
if (item is FileSystemDialogConflictItemViewModel conflictItem && !conflictItem.IsActionTaken)
if (item is FileSystemDialogConflictItemViewModel conflictItem)
{
conflictItem.TakeAction(e);
}
Expand All @@ -79,14 +78,6 @@ public void CancelCts()
_dialogClosingCts.Dispose();
}

private void PrimaryButtonClick()
{
if (!FileSystemDialogMode.IsInDeleteMode)
{
ApplyConflictOptionToAll(FileNameConflictResolveOptionType.GenerateNewName);
}
}

private void SecondaryButtonClick()
{
if (FileSystemDialogMode.ConflictsExist)
Expand Down Expand Up @@ -198,7 +189,7 @@ private static async Task LoadItemsIcon(IEnumerable<BaseFileSystemDialogItemView
var imagingService = Ioc.Default.GetRequiredService<IImagingService>();
var threadingService = Ioc.Default.GetRequiredService<IThreadingService>();

await items.ParallelForEach(async (item) =>
await items.ParallelForEachAsync(async (item) =>
{
try
{
Expand All @@ -209,7 +200,7 @@ await threadingService.ExecuteOnUiThreadAsync(async () =>
item.ItemIcon = await imagingService.GetImageModelFromPathAsync(item.SourcePath!, 64u);
});
}
catch (Exception ex) { }
catch { }
}, 10, token);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Files.Shared/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static IDictionary<TKey, TValue> AddIfNotPresent<TKey, TValue>(this IDict
/// <param name="cts">Cancellation token, stops all remaining operations</param>
/// <param name="scheduler">Task scheduler on which to execute `body`</param>
/// <returns></returns>
public static async Task ParallelForEach<T>(this IEnumerable<T> source, Func<T, Task> body, int maxDegreeOfParallelism = DataflowBlockOptions.Unbounded, CancellationToken cts = default, TaskScheduler? scheduler = null)
public static async Task ParallelForEachAsync<T>(this IEnumerable<T> source, Func<T, Task> body, int maxDegreeOfParallelism = DataflowBlockOptions.Unbounded, CancellationToken cts = default, TaskScheduler? scheduler = null)
{
var options = new ExecutionDataflowBlockOptions
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.Uwp/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ protected async void FileList_DragItemsStarting(object sender, DragItemsStarting

try
{
await e.Items.OfType<ListedItem>().ParallelForEach(async item =>
await e.Items.OfType<ListedItem>().ParallelForEachAsync(async item =>
{
if (banner != null)
{
Expand Down
54 changes: 50 additions & 4 deletions src/Files.Uwp/Dialogs/FilesystemOperationDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
CornerRadius="{StaticResource OverlayCornerRadius}"
DefaultButton="Primary"
IsPrimaryButtonEnabled="{x:Bind ViewModel.PrimaryButtonEnabled, Mode=OneWay}"
PrimaryButtonCommand="{x:Bind ViewModel.PrimaryButtonClickCommand, Mode=OneWay}"
PrimaryButtonText="{x:Bind ViewModel.PrimaryButtonText, Mode=OneWay}"
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}"
SecondaryButtonCommand="{x:Bind ViewModel.SecondaryButtonClickCommand, Mode=OneWay}"
Expand Down Expand Up @@ -52,19 +51,63 @@
</MenuFlyout>

<vc:ImageModelToImageConverter x:Key="ImageModelToImageConverter" />
<vc:GenericEnumConverter x:Key="GenericEnumConverter" />

<DataTemplate x:Key="ConflictItemDataTemplate" x:DataType="vm:FileSystemDialogConflictItemViewModel">
<Grid ColumnSpacing="12">
<Grid.ColumnDefinitions>
<!-- Icon -->
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<!-- Content -->
<ColumnDefinition />
<!-- Options -->
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!-- Icon -->
<Image
Grid.Column="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Source="{x:Bind ItemIcon, Mode=OneWay, Converter={StaticResource ImageModelToImageConverter}}" />

<!-- Content -->
<StackPanel
Grid.Column="1"
VerticalAlignment="Center"
Spacing="4">
<StackPanel Orientation="Horizontal" Spacing="16">
<TextBlock Text="{x:Bind DisplayName, Mode=OneWay}" />
<FontIcon FontSize="14" Glyph="&#xE72A;" />
<TextBlock Text="{x:Bind DestinationDisplayName, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="16">
<TextBlock
Foreground="{ThemeResource SystemAccentColor}"
Text="{x:Bind SourceDirectoryDisplayName}"
ToolTipService.ToolTip="{x:Bind SourcePath}" />
<FontIcon
FontSize="14"
Foreground="{ThemeResource SystemAccentColor}"
Glyph="&#xE72A;" />
<TextBlock
Foreground="{ThemeResource SystemAccentColor}"
Text="{x:Bind DestinationDirectoryDisplayName}"
ToolTipService.ToolTip="{x:Bind DestinationPath, Mode=OneWay}" />
</StackPanel>
</StackPanel>

<!-- Options -->
<ComboBox
Grid.Column="2"
VerticalAlignment="Center"
SelectedIndex="{x:Bind ConflictResolveOption, Mode=TwoWay, Converter={StaticResource GenericEnumConverter}}">
<ComboBox.Items>
<ComboBoxItem Content="{helpers:ResourceString Name=GenerateNewName}" />
<ComboBoxItem Content="{helpers:ResourceString Name=ConflictingItemsDialogItemOptionReplaceExisting/Text}" />
<ComboBoxItem Content="{helpers:ResourceString Name=Skip}" />
</ComboBox.Items>
</ComboBox>
</Grid>
</DataTemplate>

Expand All @@ -85,7 +128,10 @@
Source="{x:Bind ItemIcon, Mode=OneWay, Converter={StaticResource ImageModelToImageConverter}}" />

<!-- Content -->
<StackPanel Grid.Column="1" Spacing="4">
<StackPanel
Grid.Column="1"
VerticalAlignment="Center"
Spacing="4">
<TextBlock Text="{x:Bind DisplayName}" />
<TextBlock
Opacity="0.8"
Expand Down
2 changes: 1 addition & 1 deletion src/Files.Uwp/Dialogs/FilesystemOperationDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void MenuFlyout_Opening(object sender, object e)
}
}

if (DetailsGrid.Items.Count > 1 && DetailsGrid.SelectedItems.Count == 1 && DetailsGrid.SelectedItems.Any(x => (x as FileSystemDialogConflictItemViewModel).IsActionTaken))
if (DetailsGrid.Items.Count > 1 && DetailsGrid.SelectedItems.Count == 1 && !DetailsGrid.SelectedItems.Any(x => (x as FileSystemDialogConflictItemViewModel).IsDefault))
{
ApplyToAllOption.Visibility = Visibility.Visible;
ApplyToAllSeparator.Visibility = Visibility.Visible;
Expand Down
1 change: 1 addition & 0 deletions src/Files.Uwp/Files.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@
<DependentUpon>WidgetsListControl.xaml</DependentUpon>
</Compile>
<Compile Include="ValueConverters\ColorModelToColorConverter.cs" />
<Compile Include="ValueConverters\GenericEnumConverter.cs" />
<Compile Include="ValueConverters\ImageModelToImageConverter.cs" />
<Compile Include="ViewModels\Dialogs\DecompressArchiveDialogViewModel.cs" />
<Compile Include="ViewModels\NavToolbarViewModel.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packag
foreach (var item in source.Zip(destination, (src, dest, index) => new { src, dest, index }))
{
var itemPathOrName = string.IsNullOrEmpty(item.src.Path) ? item.src.Item.Name : item.src.Path;
incomingItems.Add(new FileSystemDialogConflictItemViewModel() { SourcePath = itemPathOrName, DestinationPath = item.dest });
incomingItems.Add(new FileSystemDialogConflictItemViewModel() { SourcePath = itemPathOrName, DestinationPath = item.dest, DestinationDisplayName = Path.GetFileName(item.dest) });
if (collisions.ContainsKey(incomingItems.ElementAt(item.index).SourcePath))
{
// Something strange happened, log
Expand Down
4 changes: 2 additions & 2 deletions src/Files.Uwp/Helpers/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static async void CutItem(IShellPage associatedInstance)

try
{
await associatedInstance.SlimContentPage.SelectedItems.ToList().ParallelForEach(async listedItem =>
await associatedInstance.SlimContentPage.SelectedItems.ToList().ParallelForEachAsync(async listedItem =>
{
if (banner != null)
{
Expand Down Expand Up @@ -166,7 +166,7 @@ public static async Task CopyItem(IShellPage associatedInstance)

try
{
await associatedInstance.SlimContentPage.SelectedItems.ToList().ParallelForEach(async listedItem =>
await associatedInstance.SlimContentPage.SelectedItems.ToList().ParallelForEachAsync(async listedItem =>
{
if (banner != null)
{
Expand Down
42 changes: 42 additions & 0 deletions src/Files.Uwp/ValueConverters/GenericEnumConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Linq;
using Windows.UI.Xaml.Data;

namespace Files.Uwp.ValueConverters
{
internal sealed class GenericEnumConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
int enumValue = System.Convert.ToInt32(value);

if (parameter is string strParam)
{
// enumValue-convertedValue: 0-1,1-2
var enumConversionValues = strParam.Split(',').ToDictionary(k => System.Convert.ToInt32(k.Split('-')[0]), v => System.Convert.ToInt32(v.Split('-')[1]));

if (enumConversionValues.TryGetValue((int)value, out var convertedValue))
{
enumValue = convertedValue;
}
// else.. use value from the cast above
}

try
{
if (Enum.GetName(targetType, enumValue) is string enumName)
{
return Enum.Parse(targetType, enumName);
}
}
catch { }

return enumValue;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return Convert(value, targetType, parameter, language);
}
}
}