Skip to content
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
18 changes: 14 additions & 4 deletions src/Files.App/Helpers/Dialog/DynamicDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static DynamicDialog GetFor_ShortcutNotFound(string targetPath)
return dialog;
}

public static DynamicDialog GetFor_CreateItemDialog(string itemType)
public static DynamicDialog GetFor_CreateItemDialog(string itemType, string? itemName)
{
DynamicDialog? dialog = null;
TextBox inputText = new()
Expand Down Expand Up @@ -95,14 +95,24 @@ public static DynamicDialog GetFor_CreateItemDialog(string itemType)

inputText.Loaded += (s, e) =>
{
// dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
_ = inputText.DispatcherQueue.EnqueueOrInvokeAsync(() => inputText.Focus(FocusState.Programmatic));
// Dispatching to the UI thread fixes an issue where the primary dialog button would steal focus
_ = inputText.DispatcherQueue.EnqueueOrInvokeAsync(() =>
{
// Prefill text box with default name #17845
if (itemType.Equals("Folder", StringComparison.OrdinalIgnoreCase))
inputText.Text = Strings.NewFolder.GetLocalizedResource();
else if (itemName is not null)
inputText.Text = string.Format(Strings.CreateNewFile.GetLocalizedResource(), itemName);

inputText.Focus(FocusState.Programmatic);
inputText.SelectAll();
});
};

dialog = new DynamicDialog(new DynamicDialogViewModel()
{
TitleText = string.Format(Strings.CreateNewItemTitle.GetLocalizedResource(), itemType),
SubtitleText = null,
SubtitleText = Strings.EnterAnItemName.GetLocalizedResource(),
DisplayControl = new Grid()
{
MinWidth = 300d,
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 @@ -107,7 +107,7 @@ public static async Task CreateFileFromDialogResultTypeAsync(AddItemDialogItemTy
string? userInput = null;
if (itemType != AddItemDialogItemType.File || itemInfo?.Command is null)
{
DynamicDialog dialog = DynamicDialogFactory.GetFor_CreateItemDialog(itemType.ToString().GetLocalizedResource().ToLower());
DynamicDialog dialog = DynamicDialogFactory.GetFor_CreateItemDialog(itemType.ToString().GetLocalizedResource().ToLower(), itemInfo?.Name);
await dialog.TryShowAsync(); // Show rename dialog

if (dialog.DynamicResult != DynamicDialogResult.Primary)
Expand Down
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 @@ -4347,4 +4347,7 @@
<data name="OnlyInColumnsView" xml:space="preserve">
<value>Only in Columns View</value>
</data>
<data name="CreateNewFile" xml:space="preserve">
<value>New {0}</value>
</data>
</root>
Loading