Skip to content

Commit

Permalink
Merge branch 'main' into pr/12005
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed Apr 16, 2023
2 parents c29edaf + 204b7f3 commit d1953b5
Show file tree
Hide file tree
Showing 66 changed files with 974 additions and 716 deletions.
5 changes: 3 additions & 2 deletions src/Files.App/Actions/FileSystem/FormatDriveAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Contexts;
using Files.App.DataModels.NavigationControlItems;
using Files.App.Extensions;
using Files.App.Shell;
using Files.App.ViewModels;
Expand All @@ -13,11 +14,11 @@ namespace Files.App.Actions
internal class FormatDriveAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>();
public string Label { get; } = "FormatDriveText".GetLocalizedResource();

public string Description { get; } = "FormatDriveDescription".GetLocalizedResource();
public bool IsExecutable => context.HasItem && (App.DrivesManager.Drives.FirstOrDefault(x => string.Equals(x.Path, context.Folder?.ItemPath))?.MenuOptions.ShowFormatDrive ?? false);
public bool IsExecutable => context.HasItem && (drivesViewModel.Drives.Cast<DriveItem>().FirstOrDefault(x => string.Equals(x.Path, context.Folder?.ItemPath))?.MenuOptions.ShowFormatDrive ?? false);

public FormatDriveAction()
{
Expand Down
7 changes: 4 additions & 3 deletions src/Files.App/Actions/Navigation/DuplicateCurrentTabAction.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.ViewModels;
using Files.App.Views;
using System.Threading.Tasks;
using static Files.App.ViewModels.MainPageViewModel;

namespace Files.App.Actions
{
internal class DuplicateCurrentTabAction : IAction
{
private readonly IMultitaskingContext context = Ioc.Default.GetRequiredService<IMultitaskingContext>();
private readonly MainPageViewModel mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();

public string Label { get; } = "DuplicateTab".GetLocalizedResource();
public string Description => "DuplicateCurrentTabDescription".GetLocalizedResource();
Expand All @@ -19,11 +20,11 @@ public async Task ExecuteAsync()
var arguments = context.CurrentTabItem.TabItemArguments;
if (arguments is null)
{
await AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
}
else
{
await AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.CurrentTabIndex + 1);
await mainPageViewModel.AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.CurrentTabIndex + 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.ViewModels;
using Files.App.Views;
using System.Threading.Tasks;
using static Files.App.ViewModels.MainPageViewModel;
Expand All @@ -11,6 +12,7 @@ namespace Files.App.Actions
internal class DuplicateSelectedTabAction : IAction
{
private readonly IMultitaskingContext context = Ioc.Default.GetRequiredService<IMultitaskingContext>();
private readonly MainPageViewModel mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();

public string Label { get; } = "DuplicateTab".GetLocalizedResource();
public string Description => "DuplicateSelectedTabDescription".GetLocalizedResource();
Expand All @@ -22,11 +24,11 @@ public async Task ExecuteAsync()
var arguments = context.SelectedTabItem.TabItemArguments;
if (arguments is null)
{
await AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
}
else
{
await AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.SelectedTabIndex + 1);
await mainPageViewModel.AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.SelectedTabIndex + 1);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Files.App/Actions/Navigation/NewTabAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Files.App.Commands;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Extensions;
using Files.App.ViewModels;
using System.Threading.Tasks;
Expand All @@ -7,12 +8,14 @@ namespace Files.App.Actions
{
internal class NewTabAction : IAction
{
private readonly MainPageViewModel mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();

public string Label { get; } = "NewTab".GetLocalizedResource();

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

public HotKey HotKey { get; } = new(Keys.T, KeyModifiers.Ctrl);

public Task ExecuteAsync() => MainPageViewModel.AddNewTabAsync();
public Task ExecuteAsync() => mainPageViewModel.AddNewTabAsync();
}
}
21 changes: 9 additions & 12 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public partial class App : Application
public static QuickAccessManager QuickAccessManager { get; private set; }
public static CloudDrivesManager CloudDrivesManager { get; private set; }
public static NetworkDrivesManager NetworkDrivesManager { get; private set; }
public static DrivesManager DrivesManager { get; private set; }
public static WSLDistroManager WSLDistroManager { get; private set; }
public static LibraryManager LibraryManager { get; private set; }
public static FileTagsManager FileTagsManager { get; private set; }
Expand Down Expand Up @@ -95,7 +94,6 @@ private static void EnsureSettingsAndConfigurationAreBootstrapped()
RecentItemsManager ??= new RecentItems();
AppModel ??= new AppModel();
LibraryManager ??= new LibraryManager();
DrivesManager ??= new DrivesManager();
NetworkDrivesManager ??= new NetworkDrivesManager();
CloudDrivesManager ??= new CloudDrivesManager();
WSLDistroManager ??= new WSLDistroManager();
Expand Down Expand Up @@ -123,19 +121,18 @@ private static async Task InitializeAppComponentsAsync()
{
var userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
var addItemService = Ioc.Default.GetRequiredService<IAddItemService>();
var preferencesSettingsService = userSettingsService.PreferencesSettingsService;
var generalSettingsService = userSettingsService.GeneralSettingsService;

// Start off a list of tasks we need to run before we can continue startup
await Task.Run(async () =>
{
await Task.WhenAll(
StartAppCenter(),
DrivesManager.UpdateDrivesAsync(),
OptionalTask(CloudDrivesManager.UpdateDrivesAsync(), preferencesSettingsService.ShowCloudDrivesSection),
OptionalTask(CloudDrivesManager.UpdateDrivesAsync(), generalSettingsService.ShowCloudDrivesSection),
LibraryManager.UpdateLibrariesAsync(),
OptionalTask(NetworkDrivesManager.UpdateDrivesAsync(), preferencesSettingsService.ShowNetworkDrivesSection),
OptionalTask(WSLDistroManager.UpdateDrivesAsync(), preferencesSettingsService.ShowWslSection),
OptionalTask(FileTagsManager.UpdateFileTagsAsync(), preferencesSettingsService.ShowFileTagsSection),
OptionalTask(NetworkDrivesManager.UpdateDrivesAsync(), generalSettingsService.ShowNetworkDrivesSection),
OptionalTask(WSLDistroManager.UpdateDrivesAsync(), generalSettingsService.ShowWslSection),
OptionalTask(FileTagsManager.UpdateFileTagsAsync(), generalSettingsService.ShowFileTagsSection),
QuickAccessManager.InitializeAsync()
);

Expand Down Expand Up @@ -188,7 +185,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
services
.AddSingleton<IUserSettingsService, UserSettingsService>()
.AddSingleton<IAppearanceSettingsService, AppearanceSettingsService>((sp) => new AppearanceSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
.AddSingleton<IPreferencesSettingsService, PreferencesSettingsService>((sp) => new PreferencesSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
.AddSingleton<IGeneralSettingsService, GeneralSettingsService>((sp) => new GeneralSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
.AddSingleton<IFoldersSettingsService, FoldersSettingsService>((sp) => new FoldersSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
.AddSingleton<IApplicationSettingsService, ApplicationSettingsService>((sp) => new ApplicationSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
.AddSingleton<IPreviewPaneSettingsService, PreviewPaneSettingsService>((sp) => new PreviewPaneSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
Expand Down Expand Up @@ -226,10 +223,12 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
.AddSingleton<IQuickAccessService, QuickAccessService>()
.AddSingleton<IResourcesService, ResourcesService>()
.AddSingleton<IJumpListService, JumpListService>()
.AddSingleton<IRemovableDrivesService, RemovableDrivesService>()
.AddSingleton<MainPageViewModel>()
.AddSingleton<PreviewPaneViewModel>()
.AddSingleton<SidebarViewModel>()
.AddSingleton<SettingsViewModel>()
.AddSingleton<DrivesViewModel>()
.AddSingleton<OngoingTasksViewModel>()
.AddSingleton<AppearanceViewModel>()
)
Expand Down Expand Up @@ -314,8 +313,6 @@ await SafetyExtensions.IgnoreExceptions(async () =>
Logger);
}

DrivesManager?.Dispose();

// Try to maintain clipboard data after app close
SafetyExtensions.IgnoreExceptions(() =>
{
Expand All @@ -342,7 +339,7 @@ public static void SaveSessionTabs()

bundlesSettingsService.FlushSettings();

userSettingsService.PreferencesSettingsService.LastSessionTabList = MainPageViewModel.AppInstances.DefaultIfEmpty().Select(tab =>
userSettingsService.GeneralSettingsService.LastSessionTabList = MainPageViewModel.AppInstances.DefaultIfEmpty().Select(tab =>
{
if (tab is not null && tab.TabItemArguments is not null)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ private void AddNewFileTagsToMenu(CommandBarFlyout contextMenu)
index = index >= 0 ? index : contextMenu.SecondaryCommands.Count;

// Only show the edit tags flyout if settings is enabled
if (!UserSettingsService.PreferencesSettingsService.ShowEditTagsMenu)
if (!UserSettingsService.GeneralSettingsService.ShowEditTagsMenu)
return;

contextMenu.SecondaryCommands.Insert(index, new AppBarSeparator());
Expand All @@ -725,7 +725,7 @@ private async Task AddShellMenuItemsAsync(List<ContextMenuFlyoutItemViewModel> s
var openWithMenuItem = shellMenuItems.FirstOrDefault(x => x.Tag is Win32ContextMenuItem { CommandString: "openas" });
var sendToMenuItem = shellMenuItems.FirstOrDefault(x => x.Tag is Win32ContextMenuItem { CommandString: "sendto" });
var shellMenuItemsFiltered = shellMenuItems.Where(x => x != openWithMenuItem && x != sendToMenuItem).ToList();
var mainShellMenuItems = shellMenuItemsFiltered.RemoveFrom(!UserSettingsService.PreferencesSettingsService.MoveShellExtensionsToSubMenu ? int.MaxValue : shiftPressed ? 6 : 0);
var mainShellMenuItems = shellMenuItemsFiltered.RemoveFrom(!UserSettingsService.GeneralSettingsService.MoveShellExtensionsToSubMenu ? int.MaxValue : shiftPressed ? 6 : 0);
var overflowShellMenuItemsUnfiltered = shellMenuItemsFiltered.Except(mainShellMenuItems).ToList();
var overflowShellMenuItems = overflowShellMenuItemsUnfiltered.Where(
(x, i) => (x.ItemType == ItemType.Separator &&
Expand Down Expand Up @@ -780,12 +780,12 @@ private async Task AddShellMenuItemsAsync(List<ContextMenuFlyoutItemViewModel> s
index++;
}

if (overflowItemFlyout.Items.Count > 0 && UserSettingsService.PreferencesSettingsService.MoveShellExtensionsToSubMenu)
if (overflowItemFlyout.Items.Count > 0 && UserSettingsService.GeneralSettingsService.MoveShellExtensionsToSubMenu)
{
overflowItem.Label = "ShowMoreOptions".GetLocalizedResource();
overflowItem.IsEnabled = true;
}
else if (!UserSettingsService.PreferencesSettingsService.MoveShellExtensionsToSubMenu)
else if (!UserSettingsService.GeneralSettingsService.MoveShellExtensionsToSubMenu)
overflowItem.Visibility = Visibility.Collapsed;
}
}
Expand Down
51 changes: 44 additions & 7 deletions src/Files.App/DataModels/NavigationControlItems/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Helpers;
using Files.App.Storage.WindowsStorage;
using Files.Sdk.Storage;
using Files.Sdk.Storage.Enums;
using Files.Sdk.Storage.LocatableStorage;
using Files.Shared.Extensions;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media.Imaging;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;

namespace Files.App.DataModels.NavigationControlItems
{
public class DriveItem : ObservableObject, INavigationControlItem
public class DriveItem : ObservableObject, INavigationControlItem, ILocatableFolder
{
private BitmapImage icon;
public BitmapImage Icon
Expand All @@ -23,8 +29,6 @@ public BitmapImage Icon
set => SetProperty(ref icon, value);
}

//public Uri IconSource { get; set; }

public byte[] IconData { get; set; }

private string path;
Expand Down Expand Up @@ -150,6 +154,10 @@ public bool ShowStorageSense
set => SetProperty(ref showStorageSense, value);
}

public string Id => DeviceID;

public string Name => Root.DisplayName;

public DriveItem()
{
ItemType = NavigationControlItemType.CloudDrive;
Expand Down Expand Up @@ -235,17 +243,22 @@ public int CompareTo(INavigationControlItem other)
return result == 0 ? Text.CompareTo(other.Text) : result;
}

public async Task LoadDriveIcon()
public async Task LoadThumbnailAsync(bool isSidebar = false)
{
if (IconData is null)
if (!isSidebar)
{
using var thumbnail = await DriveHelpers.GetThumbnailAsync(Root);
IconData ??= await thumbnail.ToByteArrayAsync();
}
else
{
if (!string.IsNullOrEmpty(DeviceID) && !string.Equals(DeviceID, "network-folder"))
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, 24);
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, 24);

IconData ??= UIHelpers.GetSidebarIconResourceInfo(Constants.ImageRes.Folder).IconData;
}

Icon = await IconData.ToBitmapAsync();
Icon ??= await IconData.ToBitmapAsync();
}

private string GetSizeString()
Expand All @@ -255,6 +268,30 @@ private string GetSizeString()
FreeSpace.ToSizeString(),
MaxSpace.ToSizeString());
}

public Task<IFile> GetFileAsync(string fileName, CancellationToken cancellationToken = default)
{
var folder = new WindowsStorageFolder(Root);
return folder.GetFileAsync(fileName, cancellationToken);
}

public Task<IFolder> GetFolderAsync(string folderName, CancellationToken cancellationToken = default)
{
var folder = new WindowsStorageFolder(Root);
return folder.GetFolderAsync(folderName, cancellationToken);
}

public IAsyncEnumerable<IStorable> GetItemsAsync(StorableKind kind = StorableKind.All, CancellationToken cancellationToken = default)
{
var folder = new WindowsStorageFolder(Root);
return folder.GetItemsAsync(kind, cancellationToken);
}

public Task<ILocatableFolder?> GetParentAsync(CancellationToken cancellationToken = default)
{
var folder = new WindowsStorageFolder(Root);
return folder.GetParentAsync(cancellationToken);
}
}

public enum DriveType
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/DataModels/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public int IndexOfItem(INavigationControlItem locationItem)

public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
{
var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));
var item = await FilesystemTasks.Wrap(() => DriveHelpers.GetRootFromPathAsync(path));
var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item));
LocationItem locationItem;

Expand Down Expand Up @@ -173,7 +173,7 @@ private void AddLocationItemToSidebar(LocationItem locationItem)
/// </summary>
public async Task AddAllItemsToSidebar()
{
if (userSettingsService.PreferencesSettingsService.ShowFavoritesSection)
if (userSettingsService.GeneralSettingsService.ShowFavoritesSection)
foreach (string path in FavoriteItems)
await AddItemToSidebarAsync(path);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Files.App/Dialogs/SettingsDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@
<!-- Menu Items -->
<NavigationView.MenuItems>
<NavigationViewItem
AccessKey="A"
AutomationProperties.AutomationId="SettingsItemAppearance"
Content="{helpers:ResourceString Name=Appearance}"
AccessKey="P"
AutomationProperties.AutomationId="SettingsItemGeneral"
Content="{helpers:ResourceString Name=General}"
IsSelected="True"
Tag="0">
<NavigationViewItem.Icon>
<FontIcon HorizontalAlignment="Left" Glyph="&#xE790;" />
<FontIcon Glyph="&#xE9E9;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem
AccessKey="P"
AutomationProperties.AutomationId="SettingsItemPreferences"
Content="{helpers:ResourceString Name=SettingsNavPreferences/Content}"
AccessKey="A"
AutomationProperties.AutomationId="SettingsItemAppearance"
Content="{helpers:ResourceString Name=Appearance}"
Tag="1">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE9E9;" />
<FontIcon HorizontalAlignment="Left" Glyph="&#xE790;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Dialogs/SettingsDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private void MainSettingsNavigationView_SelectionChanged(NavigationView sender,

_ = selectedItemTag switch
{
0 => SettingsContentFrame.Navigate(typeof(AppearancePage)),
1 => SettingsContentFrame.Navigate(typeof(PreferencesPage)),
0 => SettingsContentFrame.Navigate(typeof(GeneralPage)),
1 => SettingsContentFrame.Navigate(typeof(AppearancePage)),
2 => SettingsContentFrame.Navigate(typeof(FoldersPage)),
3 => SettingsContentFrame.Navigate(typeof(TagsPage)),
4 => SettingsContentFrame.Navigate(typeof(AdvancedPage)),
Expand Down
Loading

0 comments on commit d1953b5

Please sign in to comment.