@@ -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 ) =>
0 commit comments