@@ -71,6 +71,14 @@ class CustomTabPage : TabPage
71
71
internal bool StartUpIndicator = true ;
72
72
73
73
74
+ /// <summary>
75
+ /// Function can be called from the main form as well this wya.
76
+ /// </summary>
77
+ public void ApplySyntaxHighlightingForHandlebars ( )
78
+ {
79
+ TextHandling . SyntaxHighlightHandlebars ( localRichTextBoxGenerationPattern , localRichTextBoxGenerationPattern . Text . TrimEnd ( ) ) ;
80
+ }
81
+
74
82
public void setDisplayJsonFlag ( bool value )
75
83
{
76
84
DisplayJsonFlag = value ;
@@ -202,12 +210,14 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
202
210
localTabControl . Size = new Size ( 896 , 573 ) ;
203
211
localTabControl . Name = $ "tabControl{ classification } ";
204
212
localTabControl . BackColor = Color . White ;
205
- localTabControl . SelectedIndexChanged += new EventHandler ( SyntaxHighlightsHandlebars ) ;
213
+ //localTabControl.SelectedIndexChanged += new EventHandler(SyntaxHighlightsHandlebars);
214
+ localTabControl . SelectedIndexChanged += new EventHandler ( SubTabClick ) ;
206
215
207
216
// Add 'Generation Output' Tab Page on Sub Tab
208
217
tabPageGenerationOutput = new TabPage ( $ "{ _inputNiceName } Generation Output") ;
209
218
localTabControl . TabPages . Add ( tabPageGenerationOutput ) ;
210
219
tabPageGenerationOutput . BackColor = Color . Transparent ;
220
+ tabPageGenerationOutput . Name = $ "{ _inputNiceName } Generation Output";
211
221
tabPageGenerationOutput . BorderStyle = BorderStyle . None ;
212
222
tabPageGenerationOutput . UseVisualStyleBackColor = true ;
213
223
@@ -219,11 +229,12 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
219
229
localRichTextBoxGenerationOutput . Location = new Point ( 3 , 6 ) ;
220
230
localRichTextBoxGenerationOutput . Size = new Size ( 882 , 535 ) ;
221
231
localRichTextBoxGenerationOutput . BorderStyle = BorderStyle . None ;
222
-
232
+
223
233
// Add 'Pattern' Tab Page to on Sub Tab
224
234
tabPageGenerationPattern = new TabPage ( $ "{ _inputNiceName } Pattern") ;
225
235
localTabControl . TabPages . Add ( tabPageGenerationPattern ) ;
226
236
tabPageGenerationPattern . BackColor = Color . Transparent ;
237
+ tabPageGenerationPattern . Name = $ "{ _inputNiceName } Pattern";
227
238
tabPageGenerationPattern . BorderStyle = BorderStyle . None ;
228
239
tabPageGenerationPattern . UseVisualStyleBackColor = true ;
229
240
@@ -281,8 +292,6 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
281
292
localLabelActiveConnectionKeyValue . Name = $ "label{ classification } ConnectionKeyValue";
282
293
localLabelActiveConnectionKeyValue . Text = @"<connection key>" ;
283
294
284
-
285
-
286
295
// Add 'Save Pattern' Button
287
296
localSavePattern = new Button ( ) ;
288
297
tabPageGenerationPattern . Controls . Add ( localSavePattern ) ;
@@ -300,6 +309,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
300
309
localRichTextBoxGenerationPattern . Location = new Point ( 3 , 82 ) ;
301
310
localRichTextBoxGenerationPattern . Size = new Size ( 195 , 30 ) ;
302
311
localRichTextBoxGenerationPattern . BorderStyle = BorderStyle . None ;
312
+ localRichTextBoxGenerationPattern . TextChanged += new EventHandler ( CommitPatternToMemory ) ;
303
313
#endregion
304
314
305
315
#region Constructor Methods
@@ -323,14 +333,83 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
323
333
_localRichTextBox . AppendText ( notes ) ;
324
334
}
325
335
336
+ // Set the tab pages back to what they were before reload
337
+ var currentSubTab = FormBase . VdwConfigurationSettings . SelectedSubTab ;
338
+ if ( currentSubTab != null )
339
+ {
340
+ var localTabPage = localTabControl . TabPages [ currentSubTab ] ;
341
+
342
+ if ( localTabPage != null ) // The control we're looking for has to exist, otherwise no need to continue
343
+ {
344
+ if ( localTabControl . TabPages . Contains ( localTabControl . TabPages [ currentSubTab ] ) )
345
+ {
346
+ localTabControl . SelectTab ( localTabControl . TabPages [ currentSubTab ] ) ;
347
+ try
348
+ {
349
+ localTabControl . SelectedTab . Controls [ 7 ] . Text =
350
+ FormBase . VdwConfigurationSettings . SelectedPatternText ;
351
+ }
352
+ catch
353
+ {
354
+ // Do nothing
355
+ }
356
+
357
+ ApplySyntaxHighlightingForHandlebars ( ) ;
358
+ }
359
+ }
360
+ }
361
+
326
362
// Prevention of double hitting of some event handlers
327
363
StartUpIndicator = false ;
328
364
329
365
#endregion
330
366
}
331
367
368
+ private void CommitPatternToMemory ( object sender , EventArgs args )
369
+ {
370
+ if ( StartUpIndicator == false )
371
+ {
372
+ if ( localTabControl . SelectedTab != null )
373
+ {
374
+ try
375
+ {
376
+ FormBase . VdwConfigurationSettings . SelectedPatternText =
377
+ localTabControl . SelectedTab . Controls [ 7 ] . Text ;
378
+ }
379
+ catch
380
+ {
381
+ // Do nothing
382
+ }
383
+ }
384
+ }
385
+ }
386
+
387
+ /// <summary>
388
+ /// Called by the OnSelectedIndexChanged event on the local tab control, this method saves on-screen information to memory in case the UI is rebuilt.
389
+ /// </summary>
390
+ /// <param name="sender"></param>
391
+ /// <param name="args"></param>
392
+ private void SubTabClick ( object sender , EventArgs args )
393
+ {
394
+ try
395
+ {
396
+ if ( ! localTabControl . SelectedTab . Name . EndsWith ( "Output" ) )
397
+ {
398
+ //SyntaxHighlightsHandlebars(sender, args); // Needed as part of index change event
399
+ //TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text.TrimEnd());
400
+ FormBase . VdwConfigurationSettings . SelectedSubTab = localTabControl . SelectedTab . Name ;
401
+ FormBase . VdwConfigurationSettings . SelectedPatternText = localTabControl . SelectedTab . Controls [ 7 ] . Text ;
402
+ ApplySyntaxHighlightingForHandlebars ( ) ;
403
+ }
404
+ }
405
+ catch
406
+ {
407
+ // Do nothing
408
+ }
409
+ }
410
+
332
411
/// <summary>
333
- /// Automatically scroll to the end of the text
412
+ /// Automatically scroll to the end of the text.
334
413
/// </summary>
335
414
/// <param name="sender"></param>
336
415
/// <param name="e"></param>
@@ -340,11 +419,6 @@ public void ScrollToCaret(object sender, EventArgs e)
340
419
_localRichTextBox . ScrollToCaret ( ) ;
341
420
}
342
421
343
- public void SyntaxHighlightsHandlebars ( object sender , EventArgs e )
344
- {
345
- TextHandling . SyntaxHighlightHandlebars ( localRichTextBoxGenerationPattern , localRichTextBoxGenerationPattern . Text . TrimEnd ( ) ) ;
346
- }
347
-
348
422
public void FilterItemList ( object o , EventArgs e )
349
423
{
350
424
SetItemList ( ItemList ) ;
@@ -392,36 +466,43 @@ private void CheckAllCheckBoxes()
392
466
}
393
467
}
394
468
395
-
396
469
private void DisplayPattern ( object o , EventArgs e )
397
470
{
398
- // Retrieve all the info for the pattern name from memory (from the list of patterns)
471
+ // Retrieve all the info for the pattern name from memory based on the combobox value (from the list of patterns).
399
472
var loadPattern = FormBase . VdwConfigurationSettings . patternList . FirstOrDefault ( x => x . LoadPatternName == localComboBoxGenerationPattern . Text ) ;
400
473
401
474
// Set the label with the path so it's visible to the user where the file is located
402
- string localFullPath = Path . Combine ( FormBase . VdwConfigurationSettings . LoadPatternPath , loadPattern . LoadPatternFilePath ) ;
475
+ if ( loadPattern != null )
476
+ {
477
+ string localFullPath = Path . Combine ( FormBase . VdwConfigurationSettings . LoadPatternPath , loadPattern . LoadPatternFilePath ) ;
403
478
404
- localLabelFullFilePath . Text = localFullPath ;
405
- localLabelActiveConnectionKeyValue . Text = loadPattern . LoadPatternConnectionKey ;
479
+ localLabelFullFilePath . Text = localFullPath ;
480
+ localLabelActiveConnectionKeyValue . Text = loadPattern . LoadPatternConnectionKey ;
406
481
407
- // Read the file from the path
408
- string loadPatternTemplate = "" ;
409
- try
410
- {
411
- loadPatternTemplate = File . ReadAllText ( localFullPath ) ;
482
+ // Read the file from the path
483
+ string loadPatternTemplate = "" ;
484
+ try
485
+ {
486
+ loadPatternTemplate = File . ReadAllText ( localFullPath ) ;
487
+ }
488
+ catch
489
+ {
490
+ loadPatternTemplate = $ "There was an error loading the pattern specified in the load pattern collection file.\r \n \r \n Does '{ loadPattern . LoadPatternFilePath } ' exist and is the path correct?\r \n \r \n If this is not the case please update the load pattern collection information in the 'settings' tab.";
491
+ }
492
+
493
+ // Display the pattern in the text box on the screen
494
+ localRichTextBoxGenerationPattern . Text = loadPatternTemplate ;
412
495
}
413
- catch
496
+ else
414
497
{
415
- loadPatternTemplate = $ "There was an error loading the pattern specified in the load pattern collection file. \r \n \r \n Does ' { loadPattern . LoadPatternFilePath } ' exist and is the path correct? \r \n \r \n If this is not the case please update the load pattern collection information in the 'settings' tab." ;
498
+ FormBase . VdwConfigurationSettings . VdwEventLog . Add ( Event . CreateNewEvent ( EventTypes . Warning , $ "There was no pattern available." ) ) ;
416
499
}
417
500
418
- // Display the pattern in the text box on the screen
419
- localRichTextBoxGenerationPattern . Text = loadPatternTemplate ;
420
-
421
501
// Syntax highlight for Handlebars
422
502
if ( StartUpIndicator == false )
423
503
{
424
- TextHandling . SyntaxHighlightHandlebars ( localRichTextBoxGenerationPattern , localRichTextBoxGenerationPattern . Text ) ;
504
+ ApplySyntaxHighlightingForHandlebars ( ) ;
505
+ //TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text);
425
506
}
426
507
}
427
508
@@ -471,8 +552,6 @@ void Generate(object o, EventArgs e)
471
552
472
553
void DoWork ( )
473
554
{
474
- //VdwUtility.CreateSchema(FormBase.TeamConfigurationSettings.ConnectionStringStg);
475
- // TO DO: retrieve correct schema
476
555
_localRichTextBox . Clear ( ) ;
477
556
GenerateFromPattern ( ) ;
478
557
}
@@ -576,13 +655,8 @@ private void GenerateFromPattern()
576
655
RaiseOnChangeMainText ( $ "\r \n Associated scripts have been saved in { FormBase . VdwConfigurationSettings . VdwOutputPath } .\r \n ") ;
577
656
578
657
// Apply syntax highlighting
579
- SyntaxHighlight ( ) ;
580
- }
581
-
582
- public void SyntaxHighlight ( )
583
- {
584
658
TextHandling . SyntaxHighlightSql ( localRichTextBoxGenerationOutput , localRichTextBoxGenerationOutput . Text ) ;
585
- }
659
+ }
586
660
587
661
/// <summary>
588
662
/// Populate the combobox containing the pattern names associated with the classification.
0 commit comments