Skip to content

Commit

Permalink
Merge branch 'main' into ya/wasdk
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Oct 16, 2024
2 parents ed66d02 + db34916 commit a6c179d
Show file tree
Hide file tree
Showing 75 changed files with 1,384 additions and 920 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Bug Report
description: Create a bug report to help improve Files.
labels: [bug]
type: 'Bug'
title: 'Bug: '
body:

# Description
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/code_quality_issue.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Code Quality Issue
description: Create a code quality issue to help Files keep a clean codebase
labels: [codebase quality]
type: 'Code quality'
title: 'Code Quality: '
body:
- type: textarea
attributes:
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Feature Request
description: This project thrives from differentiation from competing apps. Suggest an idea for Files.
labels: [feature request]
type: 'Feature request'
title: 'Feature: '
body:

# Description
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,17 @@ jobs:
shell: pwsh
run: Start-Process -FilePath "$env:WINAPPDRIVER_EXE86_PATH"

# Retry integration tests if first attempt fails
- name: Run interaction tests
run: |
dotnet test `
$env:AUTOMATED_TESTS_ASSEMBLY_DIR\**\Files.InteractionTests.dll `
--logger "trx;LogFileName=$env:AUTOMATED_TESTS_ASSEMBLY_DIR\testResults.trx"
uses: nick-fields/retry@v3
with:
timeout_minutes: 15
max_attempts: 2
shell: pwsh
command: |
dotnet test `
$env:AUTOMATED_TESTS_ASSEMBLY_DIR\**\Files.InteractionTests.dll `
--logger "trx;LogFileName=$env:AUTOMATED_TESTS_ASSEMBLY_DIR\testResults.trx"
# - name: Generate markdown from the tests result
# shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Identity
Name="FilesDev"
Publisher="CN=Files"
Version="3.7.9.0" />
Version="3.7.11.0" />

<Properties>
<DisplayName>Files - Dev</DisplayName>
Expand Down
1 change: 1 addition & 0 deletions src/Files.App.CsWin32/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,5 @@ IFileOperation
IShellItem2
PSGetPropertyKeyFromName
ShellExecuteEx
CoTaskMemFree
QueryDosDevice
49 changes: 49 additions & 0 deletions src/Files.App.CsWin32/Windows.Win32.ComHeapPtr.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using System;
using System.Runtime.CompilerServices;
using Windows.Win32;
using Windows.Win32.System.Com;

namespace Windows.Win32
{
/// <summary>
/// Contains a heap pointer allocated via CoTaskMemAlloc and a set of methods to work with the pointer safely.
/// </summary>
public unsafe struct ComHeapPtr<T> : IDisposable where T : unmanaged
{
private T* _ptr;

public bool IsNull
=> _ptr == default;

public ComHeapPtr(T* ptr)
{
_ptr = ptr;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly T* Get()
{
return _ptr;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly T** GetAddressOf()
{
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
T* ptr = _ptr;
if (ptr is not null)
{
_ptr = null;
PInvoke.CoTaskMemFree((void*)ptr);
}
}
}
}
22 changes: 12 additions & 10 deletions src/Files.App/Actions/FileSystem/RenameAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RichGlyph Glyph
context.ShellPage is not null &&
IsPageTypeValid() &&
context.ShellPage.SlimContentPage is not null &&
IsSelectionValid();
context.HasSelection;

public RenameAction()
{
Expand All @@ -32,16 +32,18 @@ public RenameAction()
context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync(object? parameter = null)
public async Task ExecuteAsync(object? parameter = null)
{
context.ShellPage?.SlimContentPage?.ItemManipulationModel.StartRenameItem();

return Task.CompletedTask;
}

private bool IsSelectionValid()
{
return context.HasSelection && context.SelectedItems.Count == 1;
if (context.SelectedItems.Count > 1)
{
var viewModel = new BulkRenameDialogViewModel();
var dialogService = Ioc.Default.GetRequiredService<IDialogService>();
var result = await dialogService.ShowDialogAsync(viewModel);
}
else
{
context.ShellPage?.SlimContentPage?.ItemManipulationModel.StartRenameItem();
}
}

private bool IsPageTypeValid()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public BaseTransferItemAction()

public async Task ExecuteTransferAsync(DataPackageOperation type = DataPackageOperation.Copy)
{
if (ContentPageContext.ShellPage is null ||
if (ContentPageContext.ShellPage?.SlimContentPage is null ||
ContentPageContext.ShellPage.SlimContentPage.IsItemSelected is false)
return;

Expand Down
11 changes: 5 additions & 6 deletions src/Files.App/Actions/Open/OpenClassicPropertiesAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ private unsafe void ExecuteShellCommand(string itemPath)
SHELLEXECUTEINFOW info = default;
info.cbSize = (uint)Marshal.SizeOf(info);
info.nShow = 5; // SW_SHOW
info.fMask = 0x0000000C;
info.fMask = 0x0000000C; // SEE_MASK_INVOKEIDLIST

var verb = "properties";
fixed (char* cVerb = verb)
fixed (char* cVerb = "properties", lpFile = itemPath)
{
info.lpVerb = cVerb;

fixed (char* lpFile = itemPath)
info.lpFile = lpFile;

PInvoke.ShellExecuteEx(ref info);
PInvoke.ShellExecuteEx(ref info);
}
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
59 changes: 59 additions & 0 deletions src/Files.App/Dialogs/BulkRenameDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!-- Copyright (c) 2024 Files Community. Licensed under the MIT License. See the LICENSE. -->
<ContentDialog
x:Class="Files.App.Dialogs.BulkRenameDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{helpers:ResourceString Name=BulkRename}"
DefaultButton="Primary"
HighContrastAdjustment="None"
IsPrimaryButtonEnabled="{x:Bind ViewModel.IsNameValid, Mode=OneWay}"
PrimaryButtonCommand="{x:Bind ViewModel.CommitRenameCommand, Mode=OneWay}"
PrimaryButtonText="{helpers:ResourceString Name=Rename}"
RequestedTheme="{x:Bind RootAppElement.RequestedTheme, Mode=OneWay}"
SecondaryButtonText="{helpers:ResourceString Name=Cancel}"
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">

<StackPanel Width="440" Spacing="4">

<!-- Name -->
<Grid
Padding="12"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="1"
ColumnSpacing="8"
CornerRadius="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBlock
Grid.Column="0"
VerticalAlignment="Center"
Text="{helpers:ResourceString Name=Name}" />

<TextBox
x:Name="FileNameBox"
Grid.Column="1"
Width="260"
PlaceholderText="{helpers:ResourceString Name=EnterName}"
Text="{x:Bind ViewModel.FileName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<TextBox.Resources>
<TeachingTip
x:Name="InvalidNameWarning"
Title="{helpers:ResourceString Name=InvalidFilename/Text}"
IsOpen="{x:Bind ViewModel.ShowNameWarning, Mode=OneWay}"
PreferredPlacement="Bottom"
Target="{x:Bind FileNameBox}" />
</TextBox.Resources>
</TextBox>

</Grid>

</StackPanel>
</ContentDialog>
29 changes: 29 additions & 0 deletions src/Files.App/Dialogs/BulkRenameDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.Dialogs
{
public sealed partial class BulkRenameDialog : ContentDialog, IDialog<BulkRenameDialogViewModel>
{
private FrameworkElement RootAppElement
=> (FrameworkElement)MainWindow.Instance.Content;

public BulkRenameDialogViewModel ViewModel
{
get => (BulkRenameDialogViewModel)DataContext;
set => DataContext = value;
}

public BulkRenameDialog()
{
InitializeComponent();
}

public new async Task<DialogResult> ShowAsync()
{
return (DialogResult)await base.ShowAsync();
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Files.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<PublishReadyToRunComposite Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRunComposite>
<ApplicationIcon>..\Files.App (Package)\Assets\AppTiles\Dev\Logo.ico</ApplicationIcon>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
Expand Down
10 changes: 5 additions & 5 deletions src/Files.App/Helpers/Dialog/DynamicDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static DynamicDialog GetFor_ShortcutNotFound(string targetPath)
return dialog;
}

public static DynamicDialog GetFor_RenameDialog()
public static DynamicDialog GetFor_CreateItemDialog(string itemType)
{
DynamicDialog? dialog = null;
TextBox inputText = new()
Expand All @@ -70,7 +70,7 @@ public static DynamicDialog GetFor_RenameDialog()
{
Title = "InvalidFilename/Text".GetLocalizedResource(),
PreferredPlacement = TeachingTipPlacementMode.Bottom,
DataContext = new RenameDialogViewModel(),
DataContext = new CreateItemDialogViewModel(),
};

warning.SetBinding(TeachingTip.TargetProperty, new Binding()
Expand All @@ -88,7 +88,7 @@ public static DynamicDialog GetFor_RenameDialog()
inputText.TextChanged += (textBox, args) =>
{
var isInputValid = FilesystemHelpers.IsValidForFilename(inputText.Text);
((RenameDialogViewModel)warning.DataContext).IsNameInvalid = !string.IsNullOrEmpty(inputText.Text) && !isInputValid;
((CreateItemDialogViewModel)warning.DataContext).IsNameInvalid = !string.IsNullOrEmpty(inputText.Text) && !isInputValid;
dialog!.ViewModel.DynamicButtonsEnabled = isInputValid
? DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
: DynamicDialogButtons.Cancel;
Expand All @@ -104,7 +104,7 @@ public static DynamicDialog GetFor_RenameDialog()

dialog = new DynamicDialog(new DynamicDialogViewModel()
{
TitleText = "EnterAnItemName".GetLocalizedResource(),
TitleText = string.Format("CreateNewItemTitle".GetLocalizedResource(), itemType),
SubtitleText = null,
DisplayControl = new Grid()
{
Expand All @@ -118,7 +118,7 @@ public static DynamicDialog GetFor_RenameDialog()
{
vm.HideDialog(); // Rename successful
},
PrimaryButtonText = "RenameDialog/PrimaryButtonText".GetLocalizedResource(),
PrimaryButtonText = "Create".GetLocalizedResource(),
CloseButtonText = "Cancel".GetLocalizedResource(),
DynamicButtonsEnabled = DynamicDialogButtons.Cancel,
DynamicButtons = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/UI/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static async Task CreateFileFromDialogResultTypeAsync(AddItemDialogItemTy
string? userInput = null;
if (itemType != AddItemDialogItemType.File || itemInfo?.Command is null)
{
DynamicDialog dialog = DynamicDialogFactory.GetFor_RenameDialog();
DynamicDialog dialog = DynamicDialogFactory.GetFor_CreateItemDialog(itemType.ToString().GetLocalizedResource().ToLower());
await dialog.TryShowAsync(); // Show rename dialog

if (dialog.DynamicResult != DynamicDialogResult.Primary)
Expand Down
5 changes: 3 additions & 2 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public MainWindow()
InitializeComponent();

WindowHandle = WinUIEx.WindowExtensions.GetWindowHandle(this);
MinHeight = 416;
MinWidth = 516;
MinHeight = 316;
MinWidth = 416;
ExtendsContentIntoTitleBar = true;
Title = "Files";
PersistenceId = "FilesMainWindow";
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonPressedBackgroundColor = Colors.Transparent;
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Services/App/AppDialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public DialogService()
{ typeof(GitHubLoginDialogViewModel), () => new GitHubLoginDialog() },
{ typeof(FileTooLargeDialogViewModel), () => new FileTooLargeDialog() },
{ typeof(ReleaseNotesDialogViewModel), () => new ReleaseNotesDialog() },
{ typeof(BulkRenameDialogViewModel), () => new BulkRenameDialog() },
}.ToFrozenDictionary();
}

Expand Down
10 changes: 8 additions & 2 deletions src/Files.App/Strings/af/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@
<data name="EnterAnItemName" xml:space="preserve">
<value>Voer 'n itemnaam in</value>
</data>
<data name="RenameDialog.PrimaryButtonText" xml:space="preserve">
<value>Stel naam op</value>
<data name="CreateNewItemTitle" xml:space="preserve">
<value>Create new {0}</value>
</data>
<data name="LightTheme" xml:space="preserve">
<value>Lig</value>
Expand Down Expand Up @@ -3945,4 +3945,10 @@
<data name="Toolbars" xml:space="preserve">
<value>Toolbars</value>
</data>
<data name="UserID" xml:space="preserve">
<value>User ID</value>
</data>
<data name="BulkRename" xml:space="preserve">
<value>Bulk rename</value>
</data>
</root>
Loading

0 comments on commit a6c179d

Please sign in to comment.