Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed Aug 26, 2024
1 parent b964919 commit f0e9fd2
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 144 deletions.
56 changes: 56 additions & 0 deletions src/Files.App/Actions/FileSystem/FlattenAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml.Controls;
using Windows.Foundation.Metadata;
using Windows.Storage;

namespace Files.App.Actions
{
internal sealed class FlattenAction : ObservableObject, IAction
{
private readonly IContentPageContext context;
private readonly IGeneralSettingsService GeneralSettingsService = Ioc.Default.GetRequiredService<IGeneralSettingsService>();

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

public string Description
=> "FlattenDescription".GetLocalizedResource();

public bool IsExecutable =>
GeneralSettingsService.ShowFlattenOptions &&
context.ShellPage is not null &&
context.HasSelection &&
context.SelectedItem?.PrimaryItemAttribute is StorageItemTypes.Folder;

public FlattenAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();

context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync(object? parameter = null)
{
var optionsDialog = new ContentDialog()
{
Title = "FlattenFolderDialogTitle".GetLocalizedResource(),
Content = "FlattenFolderDialogContent".GetLocalizedResource(),
PrimaryButtonText = "OK".GetLocalizedResource(),
DefaultButton = ContentDialogButton.Primary
};

if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
optionsDialog.XamlRoot = MainWindow.Instance.Content.XamlRoot;

return optionsDialog.TryShowAsync();
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
107 changes: 0 additions & 107 deletions src/Files.App/Actions/FileSystem/FlattenSingleAction.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.Extensions.Logging;
using System.IO;
using Windows.Storage;
using Microsoft.Extensions.Logging;

namespace Files.App.Actions
{
internal sealed class FlattenRecursiveAction : ObservableObject, IAction
internal sealed class FlattenToRootAction : ObservableObject, IAction
{
private readonly IContentPageContext context;
private readonly IGeneralSettingsService GeneralSettingsService = Ioc.Default.GetRequiredService<IGeneralSettingsService>();

public string Label
=> "FlattenRecursive".GetLocalizedResource();
=> "FlattenToRoot".GetLocalizedResource();

public string Description
=> "FlattenDescription".GetLocalizedResource();
=> "FlattenToRootDescription".GetLocalizedResource();

public bool IsExecutable =>
GeneralSettingsService.ShowFlattenOptions &&
context.ShellPage is not null &&
context.HasSelection &&
context.SelectedItem?.PrimaryItemAttribute is StorageItemTypes.Folder;

public FlattenRecursiveAction()
public FlattenToRootAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();

Expand Down Expand Up @@ -57,7 +59,7 @@ private Task FlattenFolderAsync(string folderPath)
FlattenFolderAsync(containedFolder);

var folderName = Path.GetFileName(containedFolder);
var destinationPath = Path.Combine(context.ShellPage?.ShellViewModel?.CurrentFolder?.ItemPath ?? string.Empty, folderName);
var destinationPath = Path.Combine(context?.SelectedItem?.ItemPath ?? string.Empty, folderName);

if (Directory.Exists(destinationPath))
continue;
Expand All @@ -75,7 +77,7 @@ private Task FlattenFolderAsync(string folderPath)
foreach (var containedFile in containedFiles)
{
var fileName = Path.GetFileName(containedFile);
var destinationPath = Path.Combine(context.ShellPage?.ShellViewModel?.CurrentFolder?.ItemPath ?? string.Empty, fileName);
var destinationPath = Path.Combine(context?.SelectedItem?.ItemPath ?? string.Empty, fileName);

if (File.Exists(destinationPath))
continue;
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Data/Commands/Manager/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public enum CommandCodes
DecompressArchiveHereSmart,
DecompressArchiveToChildFolder,

// Folder
FlattenSingle,
FlattenRecursive,
// Folder
FlattenToRoot,
Flatten,

// Image Manipulation
RotateLeft,
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand DecompressArchiveHere => commands[CommandCodes.DecompressArchiveHere];
public IRichCommand DecompressArchiveHereSmart => commands[CommandCodes.DecompressArchiveHereSmart];
public IRichCommand DecompressArchiveToChildFolder => commands[CommandCodes.DecompressArchiveToChildFolder];
public IRichCommand FlattenSingle => commands[CommandCodes.FlattenSingle];
public IRichCommand FlattenRecursive => commands[CommandCodes.FlattenRecursive];
public IRichCommand FlattenToRoot => commands[CommandCodes.FlattenToRoot];
public IRichCommand Flatten => commands[CommandCodes.Flatten];
public IRichCommand RotateLeft => commands[CommandCodes.RotateLeft];
public IRichCommand RotateRight => commands[CommandCodes.RotateRight];
public IRichCommand OpenItem => commands[CommandCodes.OpenItem];
Expand Down Expand Up @@ -293,8 +293,8 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
[CommandCodes.DecompressArchiveHere] = new DecompressArchiveHere(),
[CommandCodes.DecompressArchiveHereSmart] = new DecompressArchiveHereSmart(),
[CommandCodes.DecompressArchiveToChildFolder] = new DecompressArchiveToChildFolderAction(),
[CommandCodes.FlattenSingle] = new FlattenSingleAction(),
[CommandCodes.FlattenRecursive] = new FlattenRecursiveAction(),
[CommandCodes.FlattenToRoot] = new FlattenToRootAction(),
[CommandCodes.Flatten = new FlattenAction(),
[CommandCodes.RotateLeft] = new RotateLeftAction(),
[CommandCodes.RotateRight] = new RotateRightAction(),
[CommandCodes.OpenItem] = new OpenItemAction(),
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand DecompressArchiveHereSmart { get; }
IRichCommand DecompressArchiveToChildFolder { get; }

IRichCommand FlattenSingle { get; }
IRichCommand FlattenRecursive { get; }
IRichCommand FlattenToRoot { get; }
IRichCommand Flatten { get; }

IRichCommand RotateLeft { get; }
IRichCommand RotateRight { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
ThemedIconModel = new() { ThemedIconStyle = "App.ThemedIcons.Folder" },
Items =
[
new ContextMenuFlyoutItemViewModelBuilder(Commands.FlattenSingle).Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.FlattenRecursive).Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.FlattenToRoot).Build(),
new ContextMenuFlyoutItemViewModelBuilder(Commands.Flatten).Build(),
],
IsHidden = selectedItems.Count != 1 || !selectedItems.Any(item => item?.PrimaryItemAttribute is StorageItemTypes.Folder) || !itemsSelected,
ShowItem = UserSettingsService.GeneralSettingsService.ShowFlattenOptions
Expand Down
19 changes: 14 additions & 5 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,9 @@
<data name="SettingsSetAsDefaultFileManagerDescription" xml:space="preserve">
<value>This option modifies the system registry and can have unexpected side effects on your device. Continue at your own risk.</value>
</data>
<data name="ShowFlattenOptionsDescription" xml:space="preserve">
<value>The flatten operations are permanent and not recommended. Continue at your own risk.</value>
</data>
<data name="FolderWidgetCreateNewLibraryDialogTitleText" xml:space="preserve">
<value>Create Library</value>
</data>
Expand Down Expand Up @@ -2031,13 +2034,19 @@
<value>Flatten</value>
</data>
<data name="FlattenDescription" xml:space="preserve">
<value>Flatten a folder contents into the current path.</value>
<value>Combine all files and sub files into a single folder</value>
</data>
<data name="FlattenToRoot" xml:space="preserve">
<value>Flatten to root</value>
</data>
<data name="FlattenToRootDescription" xml:space="preserve">
<value>Move all files and sub files into the selected folder</value>
</data>
<data name="FlattenSingle" xml:space="preserve">
<value>Flatten Single</value>
<data name="FlattenFolderDialogTitle" xml:space="preserve">
<value>Flatten folder</value>
</data>
<data name="FlattenRecursive" xml:space="preserve">
<value>Flatten Recursive</value>
<data name="FlattenFolderDialogContent" xml:space="preserve">
<value>No additional options are available yet. We're still working on this feature, so please check back later!.</value>
</data>
<data name="ShowFlattenOptions" xml:space="preserve">
<value>Show flatten options</value>
Expand Down
14 changes: 14 additions & 0 deletions src/Files.App/ViewModels/Settings/AdvancedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,20 @@ public bool ShowSystemTrayIcon
}
}

// TODO remove when feature is marked as stable
public bool ShowFlattenOptions
{
get => UserSettingsService.GeneralSettingsService.ShowFlattenOptions;
set
{
if (value == UserSettingsService.GeneralSettingsService.ShowFlattenOptions)
return;

UserSettingsService.GeneralSettingsService.ShowFlattenOptions = value;
OnPropertyChanged();
}
}

public async Task OpenFilesOnWindowsStartupAsync()
{
var stateMode = await ReadState();
Expand Down
25 changes: 13 additions & 12 deletions src/Files.App/ViewModels/Settings/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,18 +454,19 @@ public bool ShowCompressionOptions
}
}

public bool ShowFlattenOptions
{
get => UserSettingsService.GeneralSettingsService.ShowFlattenOptions;
set
{
if (value == UserSettingsService.GeneralSettingsService.ShowFlattenOptions)
return;

UserSettingsService.GeneralSettingsService.ShowFlattenOptions = value;
OnPropertyChanged();
}
}
// TODO uncomment code when feature is marked as stable
//public bool ShowFlattenOptions
//{
// get => UserSettingsService.GeneralSettingsService.ShowFlattenOptions;
// set
// {
// if (value == UserSettingsService.GeneralSettingsService.ShowFlattenOptions)
// return;

// UserSettingsService.GeneralSettingsService.ShowFlattenOptions = value;
// OnPropertyChanged();
// }
//}

public bool ShowSendToMenu
{
Expand Down
14 changes: 14 additions & 0 deletions src/Files.App/Views/Settings/AdvancedPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@
</i:Interaction.Behaviors>
</ToggleSwitch>
</local:SettingsBlockControl>

<!-- Flatten options -->
<local:SettingsBlockControl
Title="{helpers:ResourceString Name=ShowFlattenOptions}"
HorizontalAlignment="Stretch"
Description="{helpers:ResourceString Name=ShowFlattenOptionsDescription}">
<local:SettingsBlockControl.Icon>
<FontIcon Glyph="&#xE8B7;" />
</local:SettingsBlockControl.Icon>
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=ShowFlattenOptions}"
IsOn="{x:Bind ViewModel.ShowFlattenOptions, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>
</StackPanel>
</Grid>
</Page>
Loading

0 comments on commit f0e9fd2

Please sign in to comment.