Skip to content

Commit 5ab100d

Browse files
committed
Almost finished testing.
1 parent cf44102 commit 5ab100d

File tree

5 files changed

+162
-225
lines changed

5 files changed

+162
-225
lines changed

Virtual_EDW/CustomTabPage.cs

Lines changed: 108 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class CustomTabPage : TabPage
7171
internal bool StartUpIndicator = true;
7272

7373

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+
7482
public void setDisplayJsonFlag(bool value)
7583
{
7684
DisplayJsonFlag = value;
@@ -202,12 +210,14 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
202210
localTabControl.Size = new Size(896, 573);
203211
localTabControl.Name = $"tabControl{classification}";
204212
localTabControl.BackColor = Color.White;
205-
localTabControl.SelectedIndexChanged += new EventHandler(SyntaxHighlightsHandlebars);
213+
//localTabControl.SelectedIndexChanged += new EventHandler(SyntaxHighlightsHandlebars);
214+
localTabControl.SelectedIndexChanged += new EventHandler(SubTabClick);
206215

207216
// Add 'Generation Output' Tab Page on Sub Tab
208217
tabPageGenerationOutput = new TabPage($"{_inputNiceName} Generation Output");
209218
localTabControl.TabPages.Add(tabPageGenerationOutput);
210219
tabPageGenerationOutput.BackColor = Color.Transparent;
220+
tabPageGenerationOutput.Name = $"{_inputNiceName} Generation Output";
211221
tabPageGenerationOutput.BorderStyle = BorderStyle.None;
212222
tabPageGenerationOutput.UseVisualStyleBackColor = true;
213223

@@ -219,11 +229,12 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
219229
localRichTextBoxGenerationOutput.Location = new Point(3, 6);
220230
localRichTextBoxGenerationOutput.Size = new Size(882, 535);
221231
localRichTextBoxGenerationOutput.BorderStyle = BorderStyle.None;
222-
232+
223233
// Add 'Pattern' Tab Page to on Sub Tab
224234
tabPageGenerationPattern = new TabPage($"{_inputNiceName} Pattern");
225235
localTabControl.TabPages.Add(tabPageGenerationPattern);
226236
tabPageGenerationPattern.BackColor = Color.Transparent;
237+
tabPageGenerationPattern.Name = $"{_inputNiceName} Pattern";
227238
tabPageGenerationPattern.BorderStyle = BorderStyle.None;
228239
tabPageGenerationPattern.UseVisualStyleBackColor = true;
229240

@@ -281,8 +292,6 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
281292
localLabelActiveConnectionKeyValue.Name = $"label{classification}ConnectionKeyValue";
282293
localLabelActiveConnectionKeyValue.Text = @"<connection key>";
283294

284-
285-
286295
// Add 'Save Pattern' Button
287296
localSavePattern = new Button();
288297
tabPageGenerationPattern.Controls.Add(localSavePattern);
@@ -300,6 +309,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
300309
localRichTextBoxGenerationPattern.Location = new Point(3, 82);
301310
localRichTextBoxGenerationPattern.Size = new Size(195, 30);
302311
localRichTextBoxGenerationPattern.BorderStyle = BorderStyle.None;
312+
localRichTextBoxGenerationPattern.TextChanged += new EventHandler(CommitPatternToMemory);
303313
#endregion
304314

305315
#region Constructor Methods
@@ -323,14 +333,83 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
323333
_localRichTextBox.AppendText(notes);
324334
}
325335

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+
326362
// Prevention of double hitting of some event handlers
327363
StartUpIndicator = false;
328364

329365
#endregion
330366
}
331367

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+
332411
/// <summary>
333-
/// Automatically scroll to the end of the text
412+
/// Automatically scroll to the end of the text.
334413
/// </summary>
335414
/// <param name="sender"></param>
336415
/// <param name="e"></param>
@@ -340,11 +419,6 @@ public void ScrollToCaret(object sender, EventArgs e)
340419
_localRichTextBox.ScrollToCaret();
341420
}
342421

343-
public void SyntaxHighlightsHandlebars(object sender, EventArgs e)
344-
{
345-
TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text.TrimEnd());
346-
}
347-
348422
public void FilterItemList(object o, EventArgs e)
349423
{
350424
SetItemList(ItemList);
@@ -392,36 +466,43 @@ private void CheckAllCheckBoxes()
392466
}
393467
}
394468

395-
396469
private void DisplayPattern(object o, EventArgs e)
397470
{
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).
399472
var loadPattern = FormBase.VdwConfigurationSettings.patternList.FirstOrDefault(x => x.LoadPatternName == localComboBoxGenerationPattern.Text);
400473

401474
// 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);
403478

404-
localLabelFullFilePath.Text = localFullPath;
405-
localLabelActiveConnectionKeyValue.Text = loadPattern.LoadPatternConnectionKey;
479+
localLabelFullFilePath.Text = localFullPath;
480+
localLabelActiveConnectionKeyValue.Text = loadPattern.LoadPatternConnectionKey;
406481

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\nDoes '{loadPattern.LoadPatternFilePath}' exist and is the path correct?\r\n\r\nIf 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;
412495
}
413-
catch
496+
else
414497
{
415-
loadPatternTemplate = $"There was an error loading the pattern specified in the load pattern collection file.\r\n\r\nDoes '{loadPattern.LoadPatternFilePath}' exist and is the path correct?\r\n\r\nIf 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."));
416499
}
417500

418-
// Display the pattern in the text box on the screen
419-
localRichTextBoxGenerationPattern.Text = loadPatternTemplate;
420-
421501
// Syntax highlight for Handlebars
422502
if (StartUpIndicator == false)
423503
{
424-
TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text);
504+
ApplySyntaxHighlightingForHandlebars();
505+
//TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text);
425506
}
426507
}
427508

@@ -471,8 +552,6 @@ void Generate(object o, EventArgs e)
471552

472553
void DoWork()
473554
{
474-
//VdwUtility.CreateSchema(FormBase.TeamConfigurationSettings.ConnectionStringStg);
475-
// TO DO: retrieve correct schema
476555
_localRichTextBox.Clear();
477556
GenerateFromPattern();
478557
}
@@ -576,13 +655,8 @@ private void GenerateFromPattern()
576655
RaiseOnChangeMainText($"\r\nAssociated scripts have been saved in {FormBase.VdwConfigurationSettings.VdwOutputPath}.\r\n");
577656

578657
// Apply syntax highlighting
579-
SyntaxHighlight();
580-
}
581-
582-
public void SyntaxHighlight()
583-
{
584658
TextHandling.SyntaxHighlightSql(localRichTextBoxGenerationOutput, localRichTextBoxGenerationOutput.Text);
585-
}
659+
}
586660

587661
/// <summary>
588662
/// Populate the combobox containing the pattern names associated with the classification.

Virtual_EDW/Form_Base.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ internal static class VdwConfigurationSettings
8989

9090
// TEAM active working environment
9191
public static TeamWorkingEnvironment ActiveEnvironment { get; set; } = new TeamWorkingEnvironment();
92+
93+
// In memory settings for reloading
94+
public static string SelectedSubTab { get; set; }
95+
public static string SelectedMainTab { get; set; }
96+
public static string SelectedPatternText { get; set; }
9297
}
9398

9499

Virtual_EDW/Form_Main.Designer.cs

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)