@@ -57,50 +57,28 @@ public static DynamicDialog GetFor_ShortcutNotFound(string targetPath)
57
57
58
58
public static DynamicDialog GetFor_RenameDialog ( )
59
59
{
60
- DynamicDialog dialog = null ;
61
- TextBox inputText = new TextBox ( )
60
+ DynamicDialog ? dialog = null ;
61
+ TextBox inputText = new ( )
62
62
{
63
63
Height = 35d ,
64
64
PlaceholderText = "RenameDialogInputText/PlaceholderText" . GetLocalizedResource ( )
65
65
} ;
66
66
67
- TextBlock tipText = new TextBlock ( )
67
+ TextBlock tipText = new ( )
68
68
{
69
- Text = "RenameDialogSymbolsTip /Text" . GetLocalizedResource ( ) ,
69
+ Text = "InvalidFilename /Text" . GetLocalizedResource ( ) ,
70
70
Margin = new Microsoft . UI . Xaml . Thickness ( 0 , 0 , 4 , 0 ) ,
71
71
TextWrapping = Microsoft . UI . Xaml . TextWrapping . Wrap ,
72
72
Opacity = 0.0d
73
73
} ;
74
74
75
- inputText . BeforeTextChanging += async ( textBox , args ) =>
75
+ inputText . TextChanged += ( textBox , args ) =>
76
76
{
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 ;
104
82
} ;
105
83
106
84
inputText . Loaded += ( s , e ) =>
0 commit comments