11using Daisy . SaveAsDAISY . Conversion . Pipeline . Pipeline2 ;
22using System ;
3+ using System . Text . RegularExpressions ;
34using System . Threading ;
45using System . Windows ;
56using System . Windows . Automation ;
@@ -14,7 +15,7 @@ public partial class ConversionProgress : Window
1415 {
1516 public string CurrentProgressMessage { get ; set ; } = "" ;
1617
17-
18+
1819
1920 private int StepIncrement = 1 ;
2021 public ConversionProgress ( )
@@ -23,7 +24,7 @@ public ConversionProgress()
2324 DataContext = this ;
2425 }
2526
26-
27+ private static readonly Regex EndsWithProgress = new Regex ( @"(\d+)\s*\/\s*(\d+)\s*$" ) ;
2728
2829 // For external thread calls
2930 public delegate void DelegatedAddMessage ( string message , bool isProgress = true ) ;
@@ -34,21 +35,40 @@ public void AddMessage(string message, bool isProgress = true)
3435 this . Dispatcher . Invoke ( new DelegatedAddMessage ( AddMessage ) , message , isProgress ) ;
3536 return ;
3637 }
38+ CurrentAction . Focus ( ) ;
39+ // unpractical
40+ //if (isProgress) {
41+ // this.Activate();
42+ //}
3743 string [ ] lines = message . Split ( new char [ ] { '\r ' , '\n ' } , StringSplitOptions . RemoveEmptyEntries ) ;
3844 foreach ( string line in lines ) {
3945 if ( isProgress ) {
4046 CurrentProgressMessage = line ;
47+ //CurrentAction.Text = CurrentProgressMessage;
4148 CurrentAction . Text = CurrentProgressMessage ;
42- ProgressionTracker . Value += StepIncrement ;
49+ AutomationProperties . SetHelpText ( CurrentAction , CurrentProgressMessage ) ;
4350
51+ if ( EndsWithProgress . IsMatch ( line ) ) {
52+ Match match = EndsWithProgress . Match ( line ) ;
53+ if ( match . Groups . Count == 3 ) {
54+ if ( int . TryParse ( match . Groups [ 2 ] . Value , out int maximum ) ) {
55+ ProgressionTracker . Maximum = maximum ;
56+ }
57+ if ( int . TryParse ( match . Groups [ 1 ] . Value , out int value ) ) {
58+ ProgressionTracker . Value = value ;
59+ }
60+ }
61+ } else {
62+ ProgressionTracker . Value += StepIncrement ;
63+ }
4464 } else {
4565 CurrentAction . Text = CurrentProgressMessage + " - " + line ;
66+ AutomationProperties . SetHelpText ( CurrentAction , CurrentProgressMessage ) ;
4667 }
4768 MessageTextArea . AppendText ( line + "\r \n " ) ;
4869 }
49- CurrentAction . Focus ( ) ;
50- AutomationProperties . SetHelpText ( CurrentAction , CurrentProgressMessage ) ;
51- var peer = UIElementAutomationPeer . CreatePeerForElement ( CurrentAction ) ;
70+
71+ var peer = UIElementAutomationPeer . FromElement ( CurrentAction ) as TextElementAutomationPeer ;
5272 if ( peer != null ) {
5373 peer . RaiseAutomationEvent ( AutomationEvents . LiveRegionChanged ) ;
5474 }
@@ -71,14 +91,15 @@ public void InitializeProgress(string message = "", int maximum = 1, int step =
7191 this . Dispatcher . Invoke ( new DelegatedInitializeProgress ( InitializeProgress ) , message , maximum , step ) ;
7292 return ;
7393 }
94+ this . Activate ( ) ;
95+ CurrentAction . Focus ( ) ;
7496 CurrentProgressMessage = message ;
7597 CurrentAction . Text = CurrentProgressMessage ;
76-
98+ //Title = "Progress - " + message;
7799 this . MessageTextArea . AppendText ( ( message . EndsWith ( "\n " ) ? message : message + "\r \n " ) ) ;
78100 ProgressionTracker . Maximum = maximum ;
79101 StepIncrement = step ;
80102 ProgressionTracker . Value = 0 ;
81- CurrentAction . Focus ( ) ;
82103 AutomationProperties . SetHelpText ( CurrentAction , CurrentProgressMessage ) ;
83104 var peer = UIElementAutomationPeer . CreatePeerForElement ( CurrentAction ) ;
84105 if ( peer != null ) {
@@ -120,10 +141,17 @@ public void setCancelClickListener(CancelClickListener cancelAction)
120141 cancelButtonClicked = cancelAction ;
121142 }
122143
144+ public void Resume ( )
145+ {
146+ CancelButton . IsEnabled = true ;
147+ }
148+
123149 private void CancelButton_Click ( object sender , RoutedEventArgs e )
124150 {
151+
125152 if ( cancelButtonClicked != null ) cancelButtonClicked ( ) ;
126- this . Close ( ) ;
153+ CancelButton . IsEnabled = false ;
154+ //this.Close();
127155 }
128156
129157 private void Window_Closing ( object sender , System . ComponentModel . CancelEventArgs e )
0 commit comments