Skip to content

Commit

Permalink
Feature: Improved UX for the "Create new item" dialog (files-communit…
Browse files Browse the repository at this point in the history
…y#16317)

Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
  • Loading branch information
yaira2 and hishitetsu authored Oct 9, 2024
1 parent e7f8c33 commit 1781b7f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
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

0 comments on commit 1781b7f

Please sign in to comment.