Skip to content

Commit 1d66171

Browse files
Feature: Added default name when creating new files (#17942)
Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com>
1 parent 014d34d commit 1d66171

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

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

Lines changed: 14 additions & 4 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,14 +95,24 @@ 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(() => inputText.Focus(FocusState.Programmatic));
98+
// Dispatching to the UI thread fixes an issue where the primary dialog button would steal focus
99+
_ = inputText.DispatcherQueue.EnqueueOrInvokeAsync(() =>
100+
{
101+
// Prefill text box with default name #17845
102+
if (itemType.Equals("Folder", StringComparison.OrdinalIgnoreCase))
103+
inputText.Text = Strings.NewFolder.GetLocalizedResource();
104+
else if (itemName is not null)
105+
inputText.Text = string.Format(Strings.CreateNewFile.GetLocalizedResource(), itemName);
106+
107+
inputText.Focus(FocusState.Programmatic);
108+
inputText.SelectAll();
109+
});
100110
};
101111

102112
dialog = new DynamicDialog(new DynamicDialogViewModel()
103113
{
104114
TitleText = string.Format(Strings.CreateNewItemTitle.GetLocalizedResource(), itemType),
105-
SubtitleText = null,
115+
SubtitleText = Strings.EnterAnItemName.GetLocalizedResource(),
106116
DisplayControl = new Grid()
107117
{
108118
MinWidth = 300d,

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)