Skip to content

Commit ad153fa

Browse files
authored
Merge branch 'main' into 5bfa/CQ-Win32PInvokeVanara
2 parents 03e5dfa + 239f4bc commit ad153fa

27 files changed

+577
-214
lines changed

src/Files.App (Package)/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<Identity
1717
Name="FilesDev"
1818
Publisher="CN=Files"
19-
Version="3.7.7.0" />
19+
Version="3.7.9.0" />
2020

2121
<Properties>
2222
<DisplayName>Files - Dev</DisplayName>

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,5 @@ CreateFile
139139
GetFileSizeEx
140140
WIN32_FIND_DATAW
141141
FILE_ACCESS_RIGHTS
142+
CoTaskMemFree
143+
QueryDosDevice
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using System;
5+
using System.Runtime.CompilerServices;
6+
using Windows.Win32;
7+
using Windows.Win32.System.Com;
8+
9+
namespace Windows.Win32
10+
{
11+
/// <summary>
12+
/// Contains a heap pointer allocated via CoTaskMemAlloc and a set of methods to work with the pointer safely.
13+
/// </summary>
14+
public unsafe struct ComHeapPtr<T> : IDisposable where T : unmanaged
15+
{
16+
private T* _ptr;
17+
18+
public bool IsNull
19+
=> _ptr == default;
20+
21+
public ComHeapPtr(T* ptr)
22+
{
23+
_ptr = ptr;
24+
}
25+
26+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
27+
public readonly T* Get()
28+
{
29+
return _ptr;
30+
}
31+
32+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
33+
public readonly T** GetAddressOf()
34+
{
35+
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
36+
}
37+
38+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
39+
public void Dispose()
40+
{
41+
T* ptr = _ptr;
42+
if (ptr is not null)
43+
{
44+
_ptr = null;
45+
PInvoke.CoTaskMemFree((void*)ptr);
46+
}
47+
}
48+
}
49+
}

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public RichGlyph Glyph
2323
context.ShellPage is not null &&
2424
IsPageTypeValid() &&
2525
context.ShellPage.SlimContentPage is not null &&
26-
IsSelectionValid();
26+
context.HasSelection;
2727

2828
public RenameAction()
2929
{
@@ -32,16 +32,18 @@ public RenameAction()
3232
context.PropertyChanged += Context_PropertyChanged;
3333
}
3434

35-
public Task ExecuteAsync(object? parameter = null)
35+
public async Task ExecuteAsync(object? parameter = null)
3636
{
37-
context.ShellPage?.SlimContentPage?.ItemManipulationModel.StartRenameItem();
38-
39-
return Task.CompletedTask;
40-
}
41-
42-
private bool IsSelectionValid()
43-
{
44-
return context.HasSelection && context.SelectedItems.Count == 1;
37+
if (context.SelectedItems.Count > 1)
38+
{
39+
var viewModel = new BulkRenameDialogViewModel();
40+
var dialogService = Ioc.Default.GetRequiredService<IDialogService>();
41+
var result = await dialogService.ShowDialogAsync(viewModel);
42+
}
43+
else
44+
{
45+
context.ShellPage?.SlimContentPage?.ItemManipulationModel.StartRenameItem();
46+
}
4547
}
4648

4749
private bool IsPageTypeValid()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task ExecuteAsync(object? parameter = null)
4141
if (await confirmationDialog.TryShowAsync() is not ContentDialogResult.Primary)
4242
return;
4343

44-
bool result = await Task.Run(StorageTrashBinService.RestoreAllTrashes);
44+
bool result = await StorageTrashBinService.RestoreAllTrashesAsync();
4545

4646
// Show error dialog when failed
4747
if (!result)

src/Files.App/Data/Contracts/IStorageTrashBinService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ public interface IStorageTrashBinService
6262
/// Restores files and folders in Recycle Bin to original paths.
6363
/// </summary>
6464
/// <returns>True if succeeded; otherwise, false</returns>
65-
bool RestoreAllTrashes();
65+
Task<bool> RestoreAllTrashesAsync();
6666
}
6767
}

src/Files.App/Data/Models/PinnedFoldersManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ public async Task UpdateItemsWithExplorerAsync()
3939

4040
try
4141
{
42+
var formerPinnedFolders = PinnedFolders.ToList();
43+
4244
PinnedFolders = (await QuickAccessService.GetPinnedFoldersAsync())
4345
.Where(link => (bool?)link.Properties["System.Home.IsPinned"] ?? false)
4446
.Select(link => link.FilePath).ToList();
47+
48+
if (formerPinnedFolders.SequenceEqual(PinnedFolders))
49+
return;
50+
4551
RemoveStaleSidebarItems();
4652
await AddAllItemsToSidebarAsync();
4753
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!-- Copyright (c) 2024 Files Community. Licensed under the MIT License. See the LICENSE. -->
2+
<ContentDialog
3+
x:Class="Files.App.Dialogs.BulkRenameDialog"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:helpers="using:Files.App.Helpers"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
Title="{helpers:ResourceString Name=BulkRename}"
10+
DefaultButton="Primary"
11+
HighContrastAdjustment="None"
12+
IsPrimaryButtonEnabled="{x:Bind ViewModel.IsNameValid, Mode=OneWay}"
13+
PrimaryButtonCommand="{x:Bind ViewModel.CommitRenameCommand, Mode=OneWay}"
14+
PrimaryButtonText="{helpers:ResourceString Name=Rename}"
15+
RequestedTheme="{x:Bind RootAppElement.RequestedTheme, Mode=OneWay}"
16+
SecondaryButtonText="{helpers:ResourceString Name=Cancel}"
17+
Style="{StaticResource DefaultContentDialogStyle}"
18+
mc:Ignorable="d">
19+
20+
<StackPanel Width="440" Spacing="4">
21+
22+
<!-- Name -->
23+
<Grid
24+
Padding="12"
25+
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
26+
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
27+
BorderThickness="1"
28+
ColumnSpacing="8"
29+
CornerRadius="4">
30+
<Grid.ColumnDefinitions>
31+
<ColumnDefinition Width="*" />
32+
<ColumnDefinition Width="Auto" />
33+
</Grid.ColumnDefinitions>
34+
35+
<TextBlock
36+
Grid.Column="0"
37+
VerticalAlignment="Center"
38+
Text="{helpers:ResourceString Name=Name}" />
39+
40+
<TextBox
41+
x:Name="FileNameBox"
42+
Grid.Column="1"
43+
Width="260"
44+
PlaceholderText="{helpers:ResourceString Name=EnterName}"
45+
Text="{x:Bind ViewModel.FileName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
46+
<TextBox.Resources>
47+
<TeachingTip
48+
x:Name="InvalidNameWarning"
49+
Title="{helpers:ResourceString Name=InvalidFilename/Text}"
50+
IsOpen="{x:Bind ViewModel.ShowNameWarning, Mode=OneWay}"
51+
PreferredPlacement="Bottom"
52+
Target="{x:Bind FileNameBox}" />
53+
</TextBox.Resources>
54+
</TextBox>
55+
56+
</Grid>
57+
58+
</StackPanel>
59+
</ContentDialog>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
using Microsoft.UI.Xaml;
4+
using Microsoft.UI.Xaml.Controls;
5+
6+
namespace Files.App.Dialogs
7+
{
8+
public sealed partial class BulkRenameDialog : ContentDialog, IDialog<BulkRenameDialogViewModel>
9+
{
10+
private FrameworkElement RootAppElement
11+
=> (FrameworkElement)MainWindow.Instance.Content;
12+
13+
public BulkRenameDialogViewModel ViewModel
14+
{
15+
get => (BulkRenameDialogViewModel)DataContext;
16+
set => DataContext = value;
17+
}
18+
19+
public BulkRenameDialog()
20+
{
21+
InitializeComponent();
22+
}
23+
24+
public new async Task<DialogResult> ShowAsync()
25+
{
26+
return (DialogResult)await base.ShowAsync();
27+
}
28+
}
29+
}

src/Files.App/Files.App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
8686
<PackageReference Include="TagLibSharp" Version="2.3.0" />
8787
<PackageReference Include="Tulpep.ActiveDirectoryObjectPicker" Version="3.0.11" />
88+
<PackageReference Include="WinUIEx" Version="2.3.4" />
8889
<PackageReference Include="Vanara.Windows.Extensions" Version="4.0.1" />
8990
<PackageReference Include="Vanara.Windows.Shell" Version="4.0.1" />
9091
<PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />

0 commit comments

Comments
 (0)