Skip to content

Commit d1953b5

Browse files
committed
Merge branch 'main' into pr/12005
2 parents c29edaf + 204b7f3 commit d1953b5

File tree

66 files changed

+974
-716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+974
-716
lines changed

src/Files.App/Actions/FileSystem/FormatDriveAction.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
22
using CommunityToolkit.Mvvm.DependencyInjection;
33
using Files.App.Contexts;
4+
using Files.App.DataModels.NavigationControlItems;
45
using Files.App.Extensions;
56
using Files.App.Shell;
67
using Files.App.ViewModels;
@@ -13,11 +14,11 @@ namespace Files.App.Actions
1314
internal class FormatDriveAction : ObservableObject, IAction
1415
{
1516
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
16-
17+
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>();
1718
public string Label { get; } = "FormatDriveText".GetLocalizedResource();
1819

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

2223
public FormatDriveAction()
2324
{

src/Files.App/Actions/Navigation/DuplicateCurrentTabAction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using CommunityToolkit.Mvvm.DependencyInjection;
22
using Files.App.Contexts;
33
using Files.App.Extensions;
4+
using Files.App.ViewModels;
45
using Files.App.Views;
56
using System.Threading.Tasks;
6-
using static Files.App.ViewModels.MainPageViewModel;
77

88
namespace Files.App.Actions
99
{
1010
internal class DuplicateCurrentTabAction : IAction
1111
{
1212
private readonly IMultitaskingContext context = Ioc.Default.GetRequiredService<IMultitaskingContext>();
13+
private readonly MainPageViewModel mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
1314

1415
public string Label { get; } = "DuplicateTab".GetLocalizedResource();
1516
public string Description => "DuplicateCurrentTabDescription".GetLocalizedResource();
@@ -19,11 +20,11 @@ public async Task ExecuteAsync()
1920
var arguments = context.CurrentTabItem.TabItemArguments;
2021
if (arguments is null)
2122
{
22-
await AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
23+
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
2324
}
2425
else
2526
{
26-
await AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.CurrentTabIndex + 1);
27+
await mainPageViewModel.AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.CurrentTabIndex + 1);
2728
}
2829
}
2930
}

src/Files.App/Actions/Navigation/DuplicateSelectedTabAction.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Files.App.Commands;
33
using Files.App.Contexts;
44
using Files.App.Extensions;
5+
using Files.App.ViewModels;
56
using Files.App.Views;
67
using System.Threading.Tasks;
78
using static Files.App.ViewModels.MainPageViewModel;
@@ -11,6 +12,7 @@ namespace Files.App.Actions
1112
internal class DuplicateSelectedTabAction : IAction
1213
{
1314
private readonly IMultitaskingContext context = Ioc.Default.GetRequiredService<IMultitaskingContext>();
15+
private readonly MainPageViewModel mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
1416

1517
public string Label { get; } = "DuplicateTab".GetLocalizedResource();
1618
public string Description => "DuplicateSelectedTabDescription".GetLocalizedResource();
@@ -22,11 +24,11 @@ public async Task ExecuteAsync()
2224
var arguments = context.SelectedTabItem.TabItemArguments;
2325
if (arguments is null)
2426
{
25-
await AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
27+
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
2628
}
2729
else
2830
{
29-
await AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.SelectedTabIndex + 1);
31+
await mainPageViewModel.AddNewTabByParam(arguments.InitialPageType, arguments.NavigationArg, context.SelectedTabIndex + 1);
3032
}
3133
}
3234
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Files.App.Commands;
1+
using CommunityToolkit.Mvvm.DependencyInjection;
2+
using Files.App.Commands;
23
using Files.App.Extensions;
34
using Files.App.ViewModels;
45
using System.Threading.Tasks;
@@ -7,12 +8,14 @@ namespace Files.App.Actions
78
{
89
internal class NewTabAction : IAction
910
{
11+
private readonly MainPageViewModel mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
12+
1013
public string Label { get; } = "NewTab".GetLocalizedResource();
1114

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

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

16-
public Task ExecuteAsync() => MainPageViewModel.AddNewTabAsync();
19+
public Task ExecuteAsync() => mainPageViewModel.AddNewTabAsync();
1720
}
1821
}

src/Files.App/App.xaml.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public partial class App : Application
6464
public static QuickAccessManager QuickAccessManager { get; private set; }
6565
public static CloudDrivesManager CloudDrivesManager { get; private set; }
6666
public static NetworkDrivesManager NetworkDrivesManager { get; private set; }
67-
public static DrivesManager DrivesManager { get; private set; }
6867
public static WSLDistroManager WSLDistroManager { get; private set; }
6968
public static LibraryManager LibraryManager { get; private set; }
7069
public static FileTagsManager FileTagsManager { get; private set; }
@@ -95,7 +94,6 @@ private static void EnsureSettingsAndConfigurationAreBootstrapped()
9594
RecentItemsManager ??= new RecentItems();
9695
AppModel ??= new AppModel();
9796
LibraryManager ??= new LibraryManager();
98-
DrivesManager ??= new DrivesManager();
9997
NetworkDrivesManager ??= new NetworkDrivesManager();
10098
CloudDrivesManager ??= new CloudDrivesManager();
10199
WSLDistroManager ??= new WSLDistroManager();
@@ -123,19 +121,18 @@ private static async Task InitializeAppComponentsAsync()
123121
{
124122
var userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
125123
var addItemService = Ioc.Default.GetRequiredService<IAddItemService>();
126-
var preferencesSettingsService = userSettingsService.PreferencesSettingsService;
124+
var generalSettingsService = userSettingsService.GeneralSettingsService;
127125

128126
// Start off a list of tasks we need to run before we can continue startup
129127
await Task.Run(async () =>
130128
{
131129
await Task.WhenAll(
132130
StartAppCenter(),
133-
DrivesManager.UpdateDrivesAsync(),
134-
OptionalTask(CloudDrivesManager.UpdateDrivesAsync(), preferencesSettingsService.ShowCloudDrivesSection),
131+
OptionalTask(CloudDrivesManager.UpdateDrivesAsync(), generalSettingsService.ShowCloudDrivesSection),
135132
LibraryManager.UpdateLibrariesAsync(),
136-
OptionalTask(NetworkDrivesManager.UpdateDrivesAsync(), preferencesSettingsService.ShowNetworkDrivesSection),
137-
OptionalTask(WSLDistroManager.UpdateDrivesAsync(), preferencesSettingsService.ShowWslSection),
138-
OptionalTask(FileTagsManager.UpdateFileTagsAsync(), preferencesSettingsService.ShowFileTagsSection),
133+
OptionalTask(NetworkDrivesManager.UpdateDrivesAsync(), generalSettingsService.ShowNetworkDrivesSection),
134+
OptionalTask(WSLDistroManager.UpdateDrivesAsync(), generalSettingsService.ShowWslSection),
135+
OptionalTask(FileTagsManager.UpdateFileTagsAsync(), generalSettingsService.ShowFileTagsSection),
139136
QuickAccessManager.InitializeAsync()
140137
);
141138

@@ -188,7 +185,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
188185
services
189186
.AddSingleton<IUserSettingsService, UserSettingsService>()
190187
.AddSingleton<IAppearanceSettingsService, AppearanceSettingsService>((sp) => new AppearanceSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
191-
.AddSingleton<IPreferencesSettingsService, PreferencesSettingsService>((sp) => new PreferencesSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
188+
.AddSingleton<IGeneralSettingsService, GeneralSettingsService>((sp) => new GeneralSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
192189
.AddSingleton<IFoldersSettingsService, FoldersSettingsService>((sp) => new FoldersSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
193190
.AddSingleton<IApplicationSettingsService, ApplicationSettingsService>((sp) => new ApplicationSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
194191
.AddSingleton<IPreviewPaneSettingsService, PreviewPaneSettingsService>((sp) => new PreviewPaneSettingsService((sp.GetService<IUserSettingsService>() as UserSettingsService).GetSharingContext()))
@@ -226,10 +223,12 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
226223
.AddSingleton<IQuickAccessService, QuickAccessService>()
227224
.AddSingleton<IResourcesService, ResourcesService>()
228225
.AddSingleton<IJumpListService, JumpListService>()
226+
.AddSingleton<IRemovableDrivesService, RemovableDrivesService>()
229227
.AddSingleton<MainPageViewModel>()
230228
.AddSingleton<PreviewPaneViewModel>()
231229
.AddSingleton<SidebarViewModel>()
232230
.AddSingleton<SettingsViewModel>()
231+
.AddSingleton<DrivesViewModel>()
233232
.AddSingleton<OngoingTasksViewModel>()
234233
.AddSingleton<AppearanceViewModel>()
235234
)
@@ -314,8 +313,6 @@ await SafetyExtensions.IgnoreExceptions(async () =>
314313
Logger);
315314
}
316315

317-
DrivesManager?.Dispose();
318-
319316
// Try to maintain clipboard data after app close
320317
SafetyExtensions.IgnoreExceptions(() =>
321318
{
@@ -342,7 +339,7 @@ public static void SaveSessionTabs()
342339

343340
bundlesSettingsService.FlushSettings();
344341

345-
userSettingsService.PreferencesSettingsService.LastSessionTabList = MainPageViewModel.AppInstances.DefaultIfEmpty().Select(tab =>
342+
userSettingsService.GeneralSettingsService.LastSessionTabList = MainPageViewModel.AppInstances.DefaultIfEmpty().Select(tab =>
346343
{
347344
if (tab is not null && tab.TabItemArguments is not null)
348345
{

src/Files.App/BaseLayout.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ private void AddNewFileTagsToMenu(CommandBarFlyout contextMenu)
705705
index = index >= 0 ? index : contextMenu.SecondaryCommands.Count;
706706

707707
// Only show the edit tags flyout if settings is enabled
708-
if (!UserSettingsService.PreferencesSettingsService.ShowEditTagsMenu)
708+
if (!UserSettingsService.GeneralSettingsService.ShowEditTagsMenu)
709709
return;
710710

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

783-
if (overflowItemFlyout.Items.Count > 0 && UserSettingsService.PreferencesSettingsService.MoveShellExtensionsToSubMenu)
783+
if (overflowItemFlyout.Items.Count > 0 && UserSettingsService.GeneralSettingsService.MoveShellExtensionsToSubMenu)
784784
{
785785
overflowItem.Label = "ShowMoreOptions".GetLocalizedResource();
786786
overflowItem.IsEnabled = true;
787787
}
788-
else if (!UserSettingsService.PreferencesSettingsService.MoveShellExtensionsToSubMenu)
788+
else if (!UserSettingsService.GeneralSettingsService.MoveShellExtensionsToSubMenu)
789789
overflowItem.Visibility = Visibility.Collapsed;
790790
}
791791
}

src/Files.App/DataModels/NavigationControlItems/DriveItem.cs

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44
using Files.App.Extensions;
55
using Files.App.Filesystem;
66
using Files.App.Helpers;
7+
using Files.App.Storage.WindowsStorage;
8+
using Files.Sdk.Storage;
9+
using Files.Sdk.Storage.Enums;
10+
using Files.Sdk.Storage.LocatableStorage;
711
using Files.Shared.Extensions;
812
using Microsoft.UI.Xaml;
913
using Microsoft.UI.Xaml.Media.Imaging;
1014
using System;
15+
using System.Collections.Generic;
16+
using System.Threading;
1117
using System.Threading.Tasks;
1218
using Windows.Storage;
1319
using Windows.Storage.Streams;
1420

1521
namespace Files.App.DataModels.NavigationControlItems
1622
{
17-
public class DriveItem : ObservableObject, INavigationControlItem
23+
public class DriveItem : ObservableObject, INavigationControlItem, ILocatableFolder
1824
{
1925
private BitmapImage icon;
2026
public BitmapImage Icon
@@ -23,8 +29,6 @@ public BitmapImage Icon
2329
set => SetProperty(ref icon, value);
2430
}
2531

26-
//public Uri IconSource { get; set; }
27-
2832
public byte[] IconData { get; set; }
2933

3034
private string path;
@@ -150,6 +154,10 @@ public bool ShowStorageSense
150154
set => SetProperty(ref showStorageSense, value);
151155
}
152156

157+
public string Id => DeviceID;
158+
159+
public string Name => Root.DisplayName;
160+
153161
public DriveItem()
154162
{
155163
ItemType = NavigationControlItemType.CloudDrive;
@@ -235,17 +243,22 @@ public int CompareTo(INavigationControlItem other)
235243
return result == 0 ? Text.CompareTo(other.Text) : result;
236244
}
237245

238-
public async Task LoadDriveIcon()
246+
public async Task LoadThumbnailAsync(bool isSidebar = false)
239247
{
240-
if (IconData is null)
248+
if (!isSidebar)
249+
{
250+
using var thumbnail = await DriveHelpers.GetThumbnailAsync(Root);
251+
IconData ??= await thumbnail.ToByteArrayAsync();
252+
}
253+
else
241254
{
242255
if (!string.IsNullOrEmpty(DeviceID) && !string.Equals(DeviceID, "network-folder"))
243-
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, 24);
256+
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, 24);
244257

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

248-
Icon = await IconData.ToBitmapAsync();
261+
Icon ??= await IconData.ToBitmapAsync();
249262
}
250263

251264
private string GetSizeString()
@@ -255,6 +268,30 @@ private string GetSizeString()
255268
FreeSpace.ToSizeString(),
256269
MaxSpace.ToSizeString());
257270
}
271+
272+
public Task<IFile> GetFileAsync(string fileName, CancellationToken cancellationToken = default)
273+
{
274+
var folder = new WindowsStorageFolder(Root);
275+
return folder.GetFileAsync(fileName, cancellationToken);
276+
}
277+
278+
public Task<IFolder> GetFolderAsync(string folderName, CancellationToken cancellationToken = default)
279+
{
280+
var folder = new WindowsStorageFolder(Root);
281+
return folder.GetFolderAsync(folderName, cancellationToken);
282+
}
283+
284+
public IAsyncEnumerable<IStorable> GetItemsAsync(StorableKind kind = StorableKind.All, CancellationToken cancellationToken = default)
285+
{
286+
var folder = new WindowsStorageFolder(Root);
287+
return folder.GetItemsAsync(kind, cancellationToken);
288+
}
289+
290+
public Task<ILocatableFolder?> GetParentAsync(CancellationToken cancellationToken = default)
291+
{
292+
var folder = new WindowsStorageFolder(Root);
293+
return folder.GetParentAsync(cancellationToken);
294+
}
258295
}
259296

260297
public enum DriveType

src/Files.App/DataModels/SidebarPinnedModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public int IndexOfItem(INavigationControlItem locationItem)
7979

8080
public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
8181
{
82-
var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));
82+
var item = await FilesystemTasks.Wrap(() => DriveHelpers.GetRootFromPathAsync(path));
8383
var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item));
8484
LocationItem locationItem;
8585

@@ -173,7 +173,7 @@ private void AddLocationItemToSidebar(LocationItem locationItem)
173173
/// </summary>
174174
public async Task AddAllItemsToSidebar()
175175
{
176-
if (userSettingsService.PreferencesSettingsService.ShowFavoritesSection)
176+
if (userSettingsService.GeneralSettingsService.ShowFavoritesSection)
177177
foreach (string path in FavoriteItems)
178178
await AddItemToSidebarAsync(path);
179179
}

src/Files.App/Dialogs/SettingsDialog.xaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,22 @@
7272
<!-- Menu Items -->
7373
<NavigationView.MenuItems>
7474
<NavigationViewItem
75-
AccessKey="A"
76-
AutomationProperties.AutomationId="SettingsItemAppearance"
77-
Content="{helpers:ResourceString Name=Appearance}"
75+
AccessKey="P"
76+
AutomationProperties.AutomationId="SettingsItemGeneral"
77+
Content="{helpers:ResourceString Name=General}"
7878
IsSelected="True"
7979
Tag="0">
8080
<NavigationViewItem.Icon>
81-
<FontIcon HorizontalAlignment="Left" Glyph="&#xE790;" />
81+
<FontIcon Glyph="&#xE9E9;" />
8282
</NavigationViewItem.Icon>
8383
</NavigationViewItem>
8484
<NavigationViewItem
85-
AccessKey="P"
86-
AutomationProperties.AutomationId="SettingsItemPreferences"
87-
Content="{helpers:ResourceString Name=SettingsNavPreferences/Content}"
85+
AccessKey="A"
86+
AutomationProperties.AutomationId="SettingsItemAppearance"
87+
Content="{helpers:ResourceString Name=Appearance}"
8888
Tag="1">
8989
<NavigationViewItem.Icon>
90-
<FontIcon Glyph="&#xE9E9;" />
90+
<FontIcon HorizontalAlignment="Left" Glyph="&#xE790;" />
9191
</NavigationViewItem.Icon>
9292
</NavigationViewItem>
9393
<NavigationViewItem

src/Files.App/Dialogs/SettingsDialog.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ private void MainSettingsNavigationView_SelectionChanged(NavigationView sender,
4545

4646
_ = selectedItemTag switch
4747
{
48-
0 => SettingsContentFrame.Navigate(typeof(AppearancePage)),
49-
1 => SettingsContentFrame.Navigate(typeof(PreferencesPage)),
48+
0 => SettingsContentFrame.Navigate(typeof(GeneralPage)),
49+
1 => SettingsContentFrame.Navigate(typeof(AppearancePage)),
5050
2 => SettingsContentFrame.Navigate(typeof(FoldersPage)),
5151
3 => SettingsContentFrame.Navigate(typeof(TagsPage)),
5252
4 => SettingsContentFrame.Navigate(typeof(AdvancedPage)),

0 commit comments

Comments
 (0)