22using Avalonia . Interactivity ;
33using Avalonia . Markup . Xaml ;
44using System ;
5+ using System . Globalization ;
56using System . Text . Json ;
67
78namespace SubtitleEdit . Plugins . TypewriterEffect ;
89
910public partial class MainWindow : Window
1011{
1112 private readonly PluginRequest _request ;
13+ private TextBlock _infoLabel = null ! ;
14+ private NumericUpDown _endDelayInput = null ! ;
1215
1316 // Parameterless constructor only exists for the XAML designer.
1417 public MainWindow ( ) : this ( new PluginRequest ( ) ) { }
1518
1619 public MainWindow ( PluginRequest request )
1720 {
18- InitializeComponent ( ) ;
1921 _request = request ;
22+ InitializeComponent ( ) ;
2023
2124 var selectedCount = request . SelectedIndices . Count ;
22- InfoLabel . Text = selectedCount > 0
25+ _infoLabel . Text = selectedCount > 0
2326 ? $ "Each of the { selectedCount } selected line(s) will be split into several short lines that progressively reveal the text."
2427 : "Every line will be split into several short lines that progressively reveal the text." ;
2528
26- EndDelayInput . Value = ( decimal ) LoadEndDelaySetting ( request . Settings , defaultValue : 0.5 ) ;
29+ _endDelayInput . Value = ( decimal ) LoadEndDelaySetting ( request . Settings , defaultValue : 0.5 ) ;
2730 }
2831
29- private void InitializeComponent ( ) => AvaloniaXamlLoader . Load ( this ) ;
32+ private void InitializeComponent ( )
33+ {
34+ AvaloniaXamlLoader . Load ( this ) ;
35+ _infoLabel = this . FindControl < TextBlock > ( "InfoLabel" ) ! ;
36+ _endDelayInput = this . FindControl < NumericUpDown > ( "EndDelayInput" ) ! ;
37+ }
3038
3139 private void OnCancel ( object ? sender , RoutedEventArgs e )
3240 {
@@ -36,7 +44,7 @@ private void OnCancel(object? sender, RoutedEventArgs e)
3644
3745 private void OnOk ( object ? sender , RoutedEventArgs e )
3846 {
39- var endDelaySec = ( double ) ( EndDelayInput . Value ?? 0m ) ;
47+ var endDelaySec = ( double ) ( _endDelayInput . Value ?? 0m ) ;
4048
4149 try
4250 {
@@ -84,7 +92,8 @@ private static double LoadEndDelaySetting(JsonElement? settings, double defaultV
8492
8593 private static JsonElement BuildSettings ( double endDelay )
8694 {
87- using var doc = JsonDocument . Parse ( $ "{{\" endDelay\" :{ endDelay . ToString ( "0.###" , System . Globalization . CultureInfo . InvariantCulture ) } }}") ;
95+ var json = $ "{{\" endDelay\" :{ endDelay . ToString ( "0.###" , CultureInfo . InvariantCulture ) } }}";
96+ using var doc = JsonDocument . Parse ( json ) ;
8897 return doc . RootElement . Clone ( ) ;
8998 }
9099}
0 commit comments