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

Fix: Fixed create file button when entering text with Chinese input flyout #11040

Merged
merged 32 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6046833
Initial fix
hecksmosis Jan 9, 2023
889818e
Fix formatting
hecksmosis Jan 9, 2023
9d862bd
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 10, 2023
a96f055
Add dialog
hecksmosis Jan 10, 2023
e7207f6
Update strings
hecksmosis Jan 10, 2023
3723ed3
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 10, 2023
e533da3
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 12, 2023
06b30f7
Add check for rename
hecksmosis Jan 12, 2023
31996ad
Merge branch 'fix_forbidden_filenames' of https://github.com/hecksmos…
hecksmosis Jan 12, 2023
d266fcc
Update FilesystemOperations.cs
hecksmosis Jan 12, 2023
b1d6934
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 15, 2023
d08a57b
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 15, 2023
98c24e7
Update FilesystemOperations.cs
hecksmosis Jan 15, 2023
86999b1
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 15, 2023
94c0c61
Merge branch 'main' into fix_forbidden_filenames
yaira2 Jan 19, 2023
2cf88e9
Fix chinese input flyout not enabling button
hecksmosis Jan 19, 2023
9c74cf7
Merge branch 'main' into fix_chinese_input_flyout
hecksmosis Jan 19, 2023
45fc470
Update src/Files.App/Strings/en-US/Resources.resw
hecksmosis Jan 19, 2023
c4adf1f
Merge branch 'main' into fix_forbidden_filenames
hecksmosis Jan 19, 2023
70da83c
Add name checker method
hecksmosis Jan 20, 2023
02d3730
Merge branch 'main' of https://github.com/files-community/Files into …
hecksmosis Jan 20, 2023
0fa289e
Merge branch 'fix_forbidden_filenames' of https://github.com/hecksmos…
hecksmosis Jan 20, 2023
4ac7a49
Remove TextChanging and add restricted name check
hecksmosis Jan 20, 2023
20a58bc
Merge branch 'fix_forbidden_filenames' of https://github.com/hecksmos…
hecksmosis Jan 20, 2023
b42f600
Merge branch 'fix_chinese_input_flyout' of https://github.com/hecksmo…
hecksmosis Jan 20, 2023
b8a2dae
Refactor
hecksmosis Jan 20, 2023
36bd09b
Remove resources.resw changes
hecksmosis Jan 20, 2023
b070862
Update src/Files.App/Helpers/DynamicDialogFactory.cs
hecksmosis Jan 20, 2023
4e5e574
Merge branch 'main' into fix_chinese_input_flyout
yaira2 Jan 20, 2023
9789452
Merge branch 'main' into fix_chinese_input_flyout
yaira2 Jan 22, 2023
b0e7693
Use IsValidForFilename method
hecksmosis Jan 22, 2023
06c7204
Update src/Files.App/Helpers/DynamicDialogFactory.cs
hecksmosis Jan 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packag

#endregion IFilesystemHelpers

private static bool IsValidForFilename(string name)
public static bool IsValidForFilename(string name)
=> !string.IsNullOrWhiteSpace(name) && !ContainsRestrictedCharacters(name) && !ContainsRestrictedFileName(name);

private static async Task<(List<FileNameConflictResolveOptionType> collisions, bool cancelOperation, IEnumerable<IFileSystemDialogConflictItemViewModel>)> GetCollision(FilesystemOperationType operationType, IEnumerable<IStorageItemWithPath> source, IEnumerable<string> destination, bool forceDialog)
Expand Down
42 changes: 10 additions & 32 deletions src/Files.App/Helpers/DynamicDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,50 +57,28 @@ public static DynamicDialog GetFor_ShortcutNotFound(string targetPath)

public static DynamicDialog GetFor_RenameDialog()
{
DynamicDialog dialog = null;
TextBox inputText = new TextBox()
DynamicDialog? dialog = null;
TextBox inputText = new()
{
Height = 35d,
PlaceholderText = "RenameDialogInputText/PlaceholderText".GetLocalizedResource()
};

TextBlock tipText = new TextBlock()
TextBlock tipText = new()
{
Text = "RenameDialogSymbolsTip/Text".GetLocalizedResource(),
Text = "InvalidFilename/Text".GetLocalizedResource(),
Margin = new Microsoft.UI.Xaml.Thickness(0, 0, 4, 0),
TextWrapping = Microsoft.UI.Xaml.TextWrapping.Wrap,
Opacity = 0.0d
};

inputText.BeforeTextChanging += async (textBox, args) =>
inputText.TextChanged += (textBox, args) =>
{
if (FilesystemHelpers.ContainsRestrictedCharacters(args.NewText))
{
args.Cancel = true;
await inputText.DispatcherQueue.EnqueueAsync(() =>
{
var oldSelection = textBox.SelectionStart + textBox.SelectionLength;
var oldText = textBox.Text;
textBox.Text = FilesystemHelpers.FilterRestrictedCharacters(args.NewText);
textBox.SelectionStart = oldSelection + textBox.Text.Length - oldText.Length;
tipText.Opacity = 1.0d;
});
}
else
{
dialog.ViewModel.AdditionalData = args.NewText;

if (!string.IsNullOrWhiteSpace(args.NewText))
{
dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel;
}
else
{
dialog.ViewModel.DynamicButtonsEnabled = DynamicDialogButtons.Cancel;
}

tipText.Opacity = 0.0d;
}
var isInputValid = FilesystemHelpers.IsValidForFilename(inputText.Text);
tipText.Opacity = isInputValid ? 0.0d : 1.0d;
dialog!.ViewModel.DynamicButtonsEnabled = isInputValid
? DynamicDialogButtons.Primary | DynamicDialogButtons.Cancel
: DynamicDialogButtons.Cancel;
};

inputText.Loaded += (s, e) =>
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 @@ -513,8 +513,8 @@
<data name="FileNameTeachingTip.CloseButtonContent" xml:space="preserve">
<value>OK</value>
</data>
<data name="RenameDialogSymbolsTip.Text" xml:space="preserve">
<value>The item name must not contain the following characters: \ / : * ? " &lt; &gt; |</value>
<data name="InvalidFilename.Text" xml:space="preserve">
<value>The item name specified is invalid</value>
</data>
<data name="ItemSelected.Text" xml:space="preserve">
<value>item selected</value>
Expand Down