Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Improved UX for the "Create new item" dialog #16317

Merged
merged 4 commits into from
Oct 9, 2024
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
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());
await dialog.TryShowAsync(); // Show rename dialog

if (dialog.DynamicResult != DynamicDialogResult.Primary)
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Strings/en-US/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>Enter an item name</value>
</data>
<data name="RenameDialog.PrimaryButtonText" xml:space="preserve">
<value>Set name</value>
<data name="CreateNewItemTitle" xml:space="preserve">
<value>Create new {0}</value>
</data>
<data name="LightTheme" xml:space="preserve">
<value>Light</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Files.App.ViewModels.Dialogs
{
class RenameDialogViewModel : ObservableObject
class CreateItemDialogViewModel : ObservableObject
{
private bool isNameInvalid;
public bool IsNameInvalid
Expand Down
Loading