Skip to content

Commit 030cd41

Browse files
authored
Fix: Fixed create file button when entering text with Chinese input flyout (#11040)
1 parent 8a54137 commit 030cd41

File tree

3 files changed

+13
-35
lines changed

3 files changed

+13
-35
lines changed

src/Files.App/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packag
648648

649649
#endregion IFilesystemHelpers
650650

651-
private static bool IsValidForFilename(string name)
651+
public static bool IsValidForFilename(string name)
652652
=> !string.IsNullOrWhiteSpace(name) && !ContainsRestrictedCharacters(name) && !ContainsRestrictedFileName(name);
653653

654654
private static async Task<(List<FileNameConflictResolveOptionType> collisions, bool cancelOperation, IEnumerable<IFileSystemDialogConflictItemViewModel>)> GetCollision(FilesystemOperationType operationType, IEnumerable<IStorageItemWithPath> source, IEnumerable<string> destination, bool forceDialog)

src/Files.App/Helpers/DynamicDialogFactory.cs

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,50 +57,28 @@ public static DynamicDialog GetFor_ShortcutNotFound(string targetPath)
5757

5858
public static DynamicDialog GetFor_RenameDialog()
5959
{
60-
DynamicDialog dialog = null;
61-
TextBox inputText = new TextBox()
60+
DynamicDialog? dialog = null;
61+
TextBox inputText = new()
6262
{
6363
Height = 35d,
6464
PlaceholderText = "RenameDialogInputText/PlaceholderText".GetLocalizedResource()
6565
};
6666

67-
TextBlock tipText = new TextBlock()
67+
TextBlock tipText = new()
6868
{
69-
Text = "RenameDialogSymbolsTip/Text".GetLocalizedResource(),
69+
Text = "InvalidFilename/Text".GetLocalizedResource(),
7070
Margin = new Microsoft.UI.Xaml.Thickness(0, 0, 4, 0),
7171
TextWrapping = Microsoft.UI.Xaml.TextWrapping.Wrap,
7272
Opacity = 0.0d
7373
};
7474

75-
inputText.BeforeTextChanging += async (textBox, args) =>
75+
inputText.TextChanged += (textBox, args) =>
7676
{
77-
if (FilesystemHelpers.ContainsRestrictedCharacters(args.NewText))
78-
{
79-
args.Cancel = true;
80-
await inputText.DispatcherQueue.EnqueueAsync(() =>
81-
{
82-
var oldSelection = textBox.SelectionStart + textBox.SelectionLength;
83-
var oldText = textBox.Text;
84-
textBox.Text = FilesystemHelpers.FilterRestrictedCharacters(args.NewText);
85-
textBox.SelectionStart = oldSelection + textBox.Text.Length - oldText.Length;
86-
tipText.Opacity = 1.0d;
87-
});
88-
}
89-
else
90-
{
91-
dialog.ViewModel.AdditionalData = args.NewText;
92-
93-
if (!string.IsNullOrWhiteSpace(args.NewText))
94-
{
95-
dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel;
96-
}
97-
else
98-
{
99-
dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Cancel;
100-
}
101-
102-
tipText.Opacity = 0.0d;
103-
}
77+
var isInputValid = FilesystemHelpers.IsValidForFilename(inputText.Text);
78+
tipText.Opacity = isInputValid ? 0.0d : 1.0d;
79+
dialog!.ViewModel.DynamicButtonsEnabled = isInputValid
80+
? DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
81+
: DynamicDialogButtons.Cancel;
10482
};
10583

10684
inputText.Loaded += (s, e) =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@
513513
<data name="FileNameTeachingTip.CloseButtonContent" xml:space="preserve">
514514
<value>OK</value>
515515
</data>
516-
<data name="RenameDialogSymbolsTip.Text" xml:space="preserve">
517-
<value>The item name must not contain the following characters: \ / : * ? " &lt; &gt; |</value>
516+
<data name="InvalidFilename.Text" xml:space="preserve">
517+
<value>The item name specified is invalid</value>
518518
</data>
519519
<data name="ItemSelected.Text" xml:space="preserve">
520520
<value>item selected</value>

0 commit comments

Comments
 (0)