Skip to content

Commit a686d11

Browse files
committed
Prefill new item dialog with default name
Updated the create item dialog to prefill the input box with a default name for files and folders. Added a new resource string for file creation and modified dialog factory and UI helpers to support passing the item name.
1 parent 24ec2f9 commit a686d11

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static DynamicDialog GetFor_ShortcutNotFound(string targetPath)
5555
return dialog;
5656
}
5757

58-
public static DynamicDialog GetFor_CreateItemDialog(string itemType)
58+
public static DynamicDialog GetFor_CreateItemDialog(string itemType, string? itemName)
5959
{
6060
DynamicDialog? dialog = null;
6161
TextBox inputText = new()
@@ -95,13 +95,14 @@ public static DynamicDialog GetFor_CreateItemDialog(string itemType)
9595

9696
inputText.Loaded += (s, e) =>
9797
{
98-
// dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
99-
_ = inputText.DispatcherQueue.EnqueueOrInvokeAsync(() =>
98+
// Dispatching to the UI thread fixes an issue where the primary dialog button would steal focus
99+
_ = inputText.DispatcherQueue.EnqueueOrInvokeAsync(() =>
100100
{
101-
if(itemType.Equals("Folder", StringComparison.OrdinalIgnoreCase))
102-
{
101+
// Prefill text box with default name #17942
102+
if (itemType.Equals("Folder", StringComparison.OrdinalIgnoreCase))
103103
inputText.Text = Strings.NewFolder.GetLocalizedResource();
104-
}
104+
else if (itemName is not null)
105+
inputText.Text = string.Format(Strings.CreateNewFile.GetLocalizedResource(), itemName);
105106

106107
inputText.Focus(FocusState.Programmatic);
107108
inputText.SelectAll();

src/Files.App/Helpers/UI/UIFilesystemHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static async Task CreateFileFromDialogResultTypeAsync(AddItemDialogItemTy
107107
string? userInput = null;
108108
if (itemType != AddItemDialogItemType.File || itemInfo?.Command is null)
109109
{
110-
DynamicDialog dialog = DynamicDialogFactory.GetFor_CreateItemDialog(itemType.ToString().GetLocalizedResource().ToLower());
110+
DynamicDialog dialog = DynamicDialogFactory.GetFor_CreateItemDialog(itemType.ToString().GetLocalizedResource().ToLower(), itemInfo?.Name);
111111
await dialog.TryShowAsync(); // Show rename dialog
112112

113113
if (dialog.DynamicResult != DynamicDialogResult.Primary)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4347,4 +4347,7 @@
43474347
<data name="OnlyInColumnsView" xml:space="preserve">
43484348
<value>Only in Columns View</value>
43494349
</data>
4350+
<data name="CreateNewFile" xml:space="preserve">
4351+
<value>New {0}</value>
4352+
</data>
43504353
</root>

0 commit comments

Comments
 (0)