Skip to content

Feature: Moved "format drive" to main context menu #11364

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
merged 12 commits into from
Feb 21, 2023
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
2 changes: 2 additions & 0 deletions src/Files.App/DataModels/NavigationControlItems/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
IsLocationItem = true,
ShowEjectDevice = item.IsRemovable,
ShowShellItems = true,
ShowFormatDrive = !(item.Type == DriveType.Network || string.Equals(root.Path, "C:\\", StringComparison.OrdinalIgnoreCase)),
ShowProperties = true
};
item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path;
App.Logger.Warn(item.Path);
item.DeviceID = deviceId;
item.Root = root;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class ContextMenuOptions

public bool ShowEjectDevice { get; set; }

public bool ShowFormatDrive { get; set; }

public bool ShowShellItems { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Files.App/Filesystem/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ public override string ToString()
public bool IsAlternateStream => this is AlternateStreamItem;
public virtual bool IsExecutable => FileExtensionHelpers.IsExecutableFile(ItemPath);
public bool IsPinned => App.QuickAccessManager.Model.FavoriteItems.Contains(itemPath);
public bool IsDriveRoot => ItemPath == PathNormalization.GetPathRoot(ItemPath);

private BaseStorageFile itemFile;
public BaseStorageFile ItemFile
Expand Down
7 changes: 7 additions & 0 deletions src/Files.App/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,13 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
ShowItem = !itemsSelected
},
new ContextMenuFlyoutItemViewModel()
{
Text = "FormatDriveText".GetLocalizedResource(),
Command = commandsViewModel.FormatDriveCommand,
CommandParameter = itemViewModel?.CurrentFolder,
ShowItem = itemViewModel.CurrentFolder is not null && (App.DrivesManager.Drives.Where(x => string.Equals(x.Path, itemViewModel?.CurrentFolder.ItemPath)).FirstOrDefault()?.MenuOptions.ShowFormatDrive ?? false),
},
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutContextFlyoutEmptyRecycleBin/Text".GetLocalizedResource(),
Glyph = "\uEF88",
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/ShellContextMenuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Func<string, bool> FilterMenuItems(bool showOpenMenu)
"cut", "copy", "paste", "delete", "properties", "link",
"Windows.ModernShare", "Windows.Share", "setdesktopwallpaper",
"eject", "rename", "explore", "openinfiles", "extract",
"copyaspath", "undelete", "empty", "rotate90", "rotate270",
"copyaspath", "undelete", "empty", "format", "rotate90", "rotate270",
Win32API.ExtractStringFromDLL("shell32.dll", 34593), // Add to collection
Win32API.ExtractStringFromDLL("shell32.dll", 5384), // Pin to Start
Win32API.ExtractStringFromDLL("shell32.dll", 5385), // Unpin from Start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,11 @@ public async Task PlayAll()
await NavigationHelpers.OpenSelectedItems(associatedInstance);
}

public void FormatDrive(ListedItem? e)
{
Win32API.OpenFormatDriveDialog(e?.ItemPath ?? string.Empty);
}

#endregion Command Implementation
}
}
3 changes: 3 additions & 0 deletions src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.Input;
using Files.App.Filesystem;
using Files.Shared;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
Expand Down Expand Up @@ -82,6 +83,7 @@ private void InitializeCommands()
RotateImageRightCommand = new AsyncRelayCommand(CommandsModel.RotateImageRight);
InstallFontCommand = new AsyncRelayCommand(CommandsModel.InstallFont);
PlayAllCommand = new AsyncRelayCommand(CommandsModel.PlayAll);
FormatDriveCommand = new RelayCommand<ListedItem>(CommandsModel.FormatDrive);
}

#endregion Command Initialization
Expand Down Expand Up @@ -199,6 +201,7 @@ private void InitializeCommands()
public ICommand InstallFontCommand { get; private set; }

public ICommand PlayAllCommand { get; private set; }
public ICommand FormatDriveCommand { get; private set; }

#endregion Commands

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Files.App.Filesystem;
using Files.Shared;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
Expand Down Expand Up @@ -119,5 +120,7 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable
Task InstallFont();

Task PlayAll();

void FormatDrive(ListedItem? obj);
}
}
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,9 @@
<data name="ShowHiddenItems" xml:space="preserve">
<value>Show hidden items</value>
</data>
<data name="FormatDriveText" xml:space="preserve">
<value>Format...</value>
</data>
<data name="Help" xml:space="preserve">
<value>Help</value>
</data>
Expand Down
17 changes: 17 additions & 0 deletions src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Files.App.Helpers;
using Files.App.Helpers.ContextFlyouts;
using Files.App.ServicesImplementation;
using Files.App.Shell;
using Files.App.ViewModels;
using Files.Backend.Services.Settings;
using Files.Shared.Extensions;
Expand All @@ -29,6 +30,7 @@
using Windows.ApplicationModel.DataTransfer.DragDrop;
using Windows.System;
using Windows.UI.Core;
using static System.Net.Mime.MediaTypeNames;
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;

namespace Files.App.UserControls
Expand Down Expand Up @@ -121,6 +123,8 @@ public ICommand EmptyRecycleBinCommand

private ICommand EjectDeviceCommand { get; }

private ICommand FormatDriveCommand { get; }

private ICommand OpenPropertiesCommand { get; }

private bool IsInPointerPressed = false;
Expand All @@ -141,6 +145,7 @@ public SidebarControl()
OpenInNewWindowCommand = new RelayCommand(OpenInNewWindow);
OpenInNewPaneCommand = new RelayCommand(OpenInNewPane);
EjectDeviceCommand = new RelayCommand(EjectDevice);
FormatDriveCommand = new RelayCommand(FormatDrive);
OpenPropertiesCommand = new RelayCommand<CommandBarFlyout>(OpenProperties);
}

Expand Down Expand Up @@ -271,6 +276,13 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
ShowItem = options.ShowEjectDevice
},
new ContextMenuFlyoutItemViewModel()
{
Text = "FormatDriveText".GetLocalizedResource(),
Command = FormatDriveCommand,
CommandParameter = item,
ShowItem = options.ShowFormatDrive
},
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutContextFlyoutPropertiesFolder/Text".GetLocalizedResource(),
Glyph = "\uE946",
Expand Down Expand Up @@ -377,6 +389,11 @@ private async void EjectDevice()
await UIHelpers.ShowDeviceEjectResultAsync(result);
}

private void FormatDrive()
{
Win32API.OpenFormatDriveDialog(rightClickedItem.Path);
}

private async void Sidebar_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
if (IsInPointerPressed || args.InvokedItem is null || args.InvokedItemContainer is null)
Expand Down
20 changes: 18 additions & 2 deletions src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Helpers;
using Files.App.Shell;
using Files.App.ViewModels;
using Files.App.ViewModels.Widgets;
using Files.Backend.Services.Settings;
Expand All @@ -18,6 +19,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Expand Down Expand Up @@ -81,6 +83,7 @@ public sealed partial class DrivesWidget : HomePageWidget, IWidgetItemModel, INo

private IShellPage associatedInstance;

public ICommand FormatDriveCommand;
public ICommand EjectDeviceCommand;
public ICommand DisconnectNetworkDriveCommand;
public ICommand GoToStorageSenseCommand;
Expand Down Expand Up @@ -126,6 +129,7 @@ public DrivesWidget()

App.DrivesManager.DataChanged += Manager_DataChanged;

FormatDriveCommand = new RelayCommand<DriveCardItem>(FormatDrive);
EjectDeviceCommand = new AsyncRelayCommand<DriveCardItem>(EjectDevice);
OpenInNewTabCommand = new RelayCommand<WidgetCardItem>(OpenInNewTab);
OpenInNewWindowCommand = new RelayCommand<WidgetCardItem>(OpenInNewWindow);
Expand All @@ -139,7 +143,8 @@ public DrivesWidget()

public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCardItem item, bool isPinned)
{
var options = (item.Item as DriveItem)?.MenuOptions;
var drive = ItemsAdded.Where(x => string.Equals(PathNormalization.NormalizePath(x.Path), PathNormalization.NormalizePath(item.Path), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
var options = drive?.Item.MenuOptions;

return new List<ContextMenuFlyoutItemViewModel>()
{
Expand Down Expand Up @@ -199,6 +204,13 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
ShowItem = options?.ShowEjectDevice ?? false
},
new ContextMenuFlyoutItemViewModel()
{
Text = "FormatDriveText".GetLocalizedResource(),
Command = FormatDriveCommand,
CommandParameter = item,
ShowItem = options?.ShowFormatDrive ?? false
},
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutContextFlyoutPropertiesFolder/Text".GetLocalizedResource(),
Glyph = "\uE946",
Expand Down Expand Up @@ -233,7 +245,7 @@ await DispatcherQueue.EnqueueAsync(async () =>
{
foreach (DriveItem drive in App.DrivesManager.Drives)
{
if (!ItemsAdded.Any(x => x.Item == drive) && drive.Type != DriveType.VirtualDrive)
if (!ItemsAdded.Any(x => x.Item == drive) && drive.Type != DataModels.NavigationControlItems.DriveType.VirtualDrive)
{
var cardItem = new DriveCardItem(drive);
ItemsAdded.AddSorted(cardItem);
Expand All @@ -260,6 +272,10 @@ private async Task EjectDevice(DriveCardItem item)
await UIHelpers.ShowDeviceEjectResultAsync(result);
}

private void FormatDrive(DriveCardItem? item)
{
Win32API.OpenFormatDriveDialog(item?.Path ?? string.Empty);
}

private async Task OpenProperties(DriveCardItem item)
{
Expand Down