Skip to content

Commit 6b8bfd9

Browse files
Feature: Added a prompt when failing to rename items requiring additional permissions (#14669)
1 parent eb94a77 commit 6b8bfd9

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

src/Files.App/Helpers/Dialog/DynamicDialogFactory.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,27 @@ public static DynamicDialog GetFor_DeleteGitBranchConfirmation(string branchName
311311

312312
return dialog;
313313
}
314+
315+
public static DynamicDialog GetFor_RenameRequiresHigherPermissions(string path)
316+
{
317+
DynamicDialog dialog = null!;
318+
dialog = new DynamicDialog(new DynamicDialogViewModel()
319+
{
320+
TitleText = "ItemRenameFailed".GetLocalizedResource(),
321+
SubtitleText = string.Format("HigherPermissionsRequired".GetLocalizedResource(), path),
322+
PrimaryButtonText = "OK".GetLocalizedResource(),
323+
SecondaryButtonText = "EditPermissions".GetLocalizedResource(),
324+
SecondaryButtonAction = (vm, e) =>
325+
{
326+
var context = Ioc.Default.GetRequiredService<IContentPageContext>();
327+
var item = context.ShellPage?.FilesystemViewModel.FilesAndFolders.FirstOrDefault(li => li.ItemPath.Equals(path));
328+
329+
if (context.ShellPage is not null && item is not null)
330+
FilePropertiesHelpers.OpenPropertiesWindow(item, context.ShellPage, PropertiesNavigationViewItemType.Security);
331+
}
332+
});
333+
334+
return dialog;
335+
}
314336
}
315337
}

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,6 +3685,15 @@
36853685
<data name="ChangeAlbumCover" xml:space="preserve">
36863686
<value>Change album cover</value>
36873687
</data>
3688+
<data name="ItemRenameFailed" xml:space="preserve">
3689+
<value>Failed to rename item</value>
3690+
</data>
3691+
<data name="HigherPermissionsRequired" xml:space="preserve">
3692+
<value>Editing "{0}" requires additional permissions</value>
3693+
</data>
3694+
<data name="EditPermissions" xml:space="preserve">
3695+
<value>Edit permissions</value>
3696+
</data>
36883697
<data name="BackgroundRunningNotificationBody" xml:space="preserve">
36893698
<value>Files is still running in the background to improve startup performance.</value>
36903699
</data>

src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Files.App.Views.Properties;
45
using Microsoft.UI;
56
using Microsoft.UI.Windowing;
67
using Microsoft.UI.Xaml;
@@ -87,7 +88,8 @@ public static void OpenPropertiesWindow(IShellPage associatedInstance)
8788
/// </summary>
8889
/// <param name="item">An item to view properties</param>
8990
/// <param name="associatedInstance">Associated main window instance</param>
90-
public static void OpenPropertiesWindow(object item, IShellPage associatedInstance)
91+
/// <param name="defaultPage">The page to show when opening the window</param>
92+
public static void OpenPropertiesWindow(object item, IShellPage associatedInstance, PropertiesNavigationViewItemType defaultPage = PropertiesNavigationViewItemType.General)
9193
{
9294
if (item is null)
9395
return;
@@ -147,6 +149,8 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
147149

148150
appWindow.Move(appWindowPos);
149151
appWindow.Show();
152+
153+
(frame.Content as MainPropertiesPage)?.TryNavigateToPage(defaultPage);
150154
}
151155

152156
// Destruction of Window objects seems to cause access violation. (#12057)

src/Files.App/Utils/Storage/Operations/ShellFilesystemOperations.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,17 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source, stri
657657
if (renameResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.Unauthorized))
658658
{
659659
if (!asAdmin && await RequestAdminOperation())
660-
return await RenameAsync(source, newName, collision, progress, cancellationToken, true);
660+
{
661+
var res = await RenameAsync(source, newName, collision, progress, cancellationToken, true);
662+
if (res is null)
663+
{
664+
await DynamicDialogFactory
665+
.GetFor_RenameRequiresHigherPermissions(source.Path)
666+
.TryShowAsync();
667+
}
668+
669+
return res;
670+
}
661671
}
662672
else if (renameResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.InUse))
663673
{

src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ public MainPropertiesPage()
3333
FlowDirection = FlowDirection.RightToLeft;
3434
}
3535

36+
37+
// Navigates to specified properties page
38+
public bool TryNavigateToPage(PropertiesNavigationViewItemType pageType)
39+
{
40+
var page = MainPropertiesViewModel.NavigationViewItems.FirstOrDefault(item => item.ItemType == pageType);
41+
if (page is null)
42+
return false;
43+
44+
MainPropertiesViewModel.SelectedNavigationViewItem = page;
45+
return true;
46+
}
47+
3648
protected override void OnNavigatedTo(NavigationEventArgs e)
3749
{
3850
var parameter = (PropertiesPageNavigationParameter)e.Parameter;

0 commit comments

Comments
 (0)