Skip to content
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

Feature: Added a prompt when failing to rename items requiring additional permissions #14669

Merged
22 changes: 22 additions & 0 deletions src/Files.App/Helpers/Dialog/DynamicDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,27 @@ public static DynamicDialog GetFor_DeleteGitBranchConfirmation(string branchName

return dialog;
}

public static DynamicDialog GetFor_RenameRequiresHigherPermissions(string path)
{
DynamicDialog dialog = null!;
dialog = new DynamicDialog(new DynamicDialogViewModel()
{
TitleText = "ItemRenameFailed".GetLocalizedResource(),
SubtitleText = string.Format("HigherPermissionsRequired".GetLocalizedResource(), path),
PrimaryButtonText = "OK".GetLocalizedResource(),
SecondaryButtonText = "EditPermissions".GetLocalizedResource(),
SecondaryButtonAction = (vm, e) =>
{
var context = Ioc.Default.GetRequiredService<IContentPageContext>();
var item = context.ShellPage?.FilesystemViewModel.FilesAndFolders.FirstOrDefault(li => li.ItemPath.Equals(path));

if (context.ShellPage is not null && item is not null)
FilePropertiesHelpers.OpenPropertiesWindow(item, context.ShellPage, PropertiesNavigationViewItemType.Security);
}
});

return dialog;
}
}
}
9 changes: 9 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3685,6 +3685,15 @@
<data name="ChangeAlbumCover" xml:space="preserve">
<value>Change album cover</value>
</data>
<data name="ItemRenameFailed" xml:space="preserve">
<value>Failed to rename item</value>
</data>
<data name="HigherPermissionsRequired" xml:space="preserve">
<value>Editing "{0}" requires additional permissions</value>
</data>
<data name="EditPermissions" xml:space="preserve">
<value>Edit permissions</value>
</data>
<data name="BackgroundRunningNotificationBody" xml:space="preserve">
<value>Files is still running in the background to improve startup performance.</value>
</data>
Expand Down
6 changes: 5 additions & 1 deletion src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Views.Properties;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -87,7 +88,8 @@ public static void OpenPropertiesWindow(IShellPage associatedInstance)
/// </summary>
/// <param name="item">An item to view properties</param>
/// <param name="associatedInstance">Associated main window instance</param>
public static void OpenPropertiesWindow(object item, IShellPage associatedInstance)
/// <param name="defaultPage">The page to show when opening the window</param>
public static void OpenPropertiesWindow(object item, IShellPage associatedInstance, PropertiesNavigationViewItemType defaultPage = PropertiesNavigationViewItemType.General)
{
if (item is null)
return;
Expand Down Expand Up @@ -147,6 +149,8 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan

appWindow.Move(appWindowPos);
appWindow.Show();

(frame.Content as MainPropertiesPage)?.TryNavigateToPage(defaultPage);
}

// Destruction of Window objects seems to cause access violation. (#12057)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,17 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source, stri
if (renameResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.Unauthorized))
{
if (!asAdmin && await RequestAdminOperation())
return await RenameAsync(source, newName, collision, progress, cancellationToken, true);
{
var res = await RenameAsync(source, newName, collision, progress, cancellationToken, true);
if (res is null)
{
await DynamicDialogFactory
.GetFor_RenameRequiresHigherPermissions(source.Path)
.TryShowAsync();
}

return res;
}
}
else if (renameResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.InUse))
{
Expand Down
12 changes: 12 additions & 0 deletions src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public MainPropertiesPage()
FlowDirection = FlowDirection.RightToLeft;
}


// Navigates to specified properties page
public bool TryNavigateToPage(PropertiesNavigationViewItemType pageType)
ferrariofilippo marked this conversation as resolved.
Show resolved Hide resolved
{
var page = MainPropertiesViewModel.NavigationViewItems.FirstOrDefault(item => item.ItemType == pageType);
if (page is null)
return false;

MainPropertiesViewModel.SelectedNavigationViewItem = page;
return true;
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
var parameter = (PropertiesPageNavigationParameter)e.Parameter;
Expand Down
Loading