Skip to content

Commit e56fb6a

Browse files
committed
Added comment header to code block
1 parent 9f71115 commit e56fb6a

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

CS/Ribbon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Or use the following tag to remove all other ribbons when this loads
418418
id="separator12"
419419
/>
420420
<button
421-
id="btnScriptTypeGithubTable"
421+
id="btnScriptTypeMarkdownTable"
422422
getImage="GetButtonImage"
423423
getLabel="GetLabelText"
424424
onAction="OnAction"

CS/Scripts/Formula.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ public static void DqlUpdateLocked()
901901
/// Add a formula at the end of the table to use as a script
902902
/// </summary>
903903
/// <remarks></remarks>
904-
public static void GithubTable()
904+
public static void MarkdownTable()
905905
{
906906
Excel.ListObject tbl = null;
907907
Excel.ListColumn sqlCol = null;
@@ -952,10 +952,10 @@ public static void GithubTable()
952952
sqlCol.Range.HorizontalAlignment = Excel.Constants.xlLeft;
953953
sqlCol.DataBodyRange.Copy();
954954
Ribbon.AppVariables.FileType = "TXT";
955-
string headerColumn = Ribbon.ConcatenateColumnNames(tbl.Range, string.Empty, "|", "") + "|" + Environment.NewLine;
955+
string headerColumn = Ribbon.ConcatenateColumnNames(tbl.Range, string.Empty, "|", string.Empty, string.Empty) + "|" + Environment.NewLine;
956956
string headerSeparator = "|:" + new String('-', 10);
957957
string headerLine = new System.Text.StringBuilder(headerSeparator.Length * lastColumnIndex).Insert(0, headerSeparator, lastColumnIndex).ToString().Substring(0, ((headerSeparator.Length * lastColumnIndex) - (headerSeparator.Length - 1))) + Environment.NewLine;
958-
Ribbon.AppVariables.ScriptRange = headerColumn + headerLine + (string)Clipboard.GetData(DataFormats.Text);
958+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("Markdown table", "<!---" , "--->") + headerColumn + headerLine + (string)Clipboard.GetData(DataFormats.Text);
959959
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
960960
}
961961
catch (System.Runtime.InteropServices.COMException)
@@ -1075,7 +1075,7 @@ public static void HtmlTable()
10751075
Ribbon.AppVariables.FileType = "XML";
10761076
Ribbon.AppVariables.ScriptRange = (string)Clipboard.GetData(DataFormats.Text);
10771077
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
1078-
Ribbon.AppVariables.ScriptRange = "<table>" + Environment.NewLine + "<tr>" + Environment.NewLine + Ribbon.ConcatenateColumnNames(tbl.Range, "", "<th>", "</th>", Environment.NewLine) + Environment.NewLine + "</tr>" + Environment.NewLine + Ribbon.AppVariables.ScriptRange + "</table>";
1078+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("HTML table", "<!---", "--->") + "<table>" + Environment.NewLine + "<tr>" + Environment.NewLine + Ribbon.ConcatenateColumnNames(tbl.Range, "", "<th>", "</th>", Environment.NewLine) + Environment.NewLine + "</tr>" + Environment.NewLine + Ribbon.AppVariables.ScriptRange + "</table>";
10791079
}
10801080
catch (System.Runtime.InteropServices.COMException)
10811081
{
@@ -1856,7 +1856,7 @@ public static void TSqlCreateTable()
18561856
sqlCol.DataBodyRange.Copy();
18571857
Ribbon.AppVariables.FileType = "SQL";
18581858
Ribbon.AppVariables.ScriptRange = createTable + (string)Clipboard.GetData(DataFormats.Text);
1859-
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
1859+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("To create and insert records") + Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
18601860
}
18611861
catch (System.Runtime.InteropServices.COMException)
18621862
{
@@ -1958,7 +1958,7 @@ public static void TSqlInsertValues()
19581958
sqlCol.DataBodyRange.Copy();
19591959
Ribbon.AppVariables.FileType = "SQL";
19601960
Ribbon.AppVariables.ScriptRange = (string)Clipboard.GetData(DataFormats.Text);
1961-
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
1961+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("To insert records") + Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
19621962
}
19631963
catch (System.Runtime.InteropServices.COMException)
19641964
{
@@ -2066,10 +2066,10 @@ public static void TSqlMergeValues()
20662066
sqlCol.Range.Columns.AutoFit();
20672067
sqlCol.Range.HorizontalAlignment = Excel.Constants.xlLeft;
20682068
sqlCol.Range.Copy();
2069-
Ribbon.AppVariables.FileType = "SQL";
2069+
Ribbon.AppVariables.FileType = "SQL";
20702070
Ribbon.AppVariables.ScriptRange = (string)Clipboard.GetData(DataFormats.Text);
20712071
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
2072-
Ribbon.AppVariables.ScriptRange = "SET XACT_ABORT ON" + Environment.NewLine + "BEGIN TRANSACTION;" + Environment.NewLine + Environment.NewLine + ";WITH " + Environment.NewLine + tableAliasTemp + Environment.NewLine + "AS " + Environment.NewLine + "(" + Environment.NewLine + Ribbon.AppVariables.ScriptRange + ") " + Environment.NewLine + "MERGE " + tableAlias + " AS T" + Environment.NewLine + "USING " + tableAliasTemp + " AS S" + Environment.NewLine + "ON " + Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S") + "WHEN NOT MATCHED BY TARGET" + Environment.NewLine + "THEN INSERT" + Environment.NewLine + "(" + Environment.NewLine + Ribbon.ConcatenateColumnNames(tbl.Range, "", "[", "]") + Environment.NewLine + ")" + Environment.NewLine + "VALUES" + Environment.NewLine + "(" + Environment.NewLine + Ribbon.ConcatenateColumnNames(tbl.Range, "S", "[", "]") + Environment.NewLine + ")" + Environment.NewLine + "WHEN MATCHED" + Environment.NewLine + "THEN UPDATE SET" + Environment.NewLine + Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S") + "--WHEN NOT MATCHED BY SOURCE AND 'ADD WHERE CLAUSE HERE'" + Environment.NewLine + "--THEN DELETE" + Environment.NewLine + "OUTPUT $action, inserted.*, deleted.*;" + Environment.NewLine + Environment.NewLine + "ROLLBACK TRANSACTION;" + Environment.NewLine + "--COMMIT TRANSACTION;" + Environment.NewLine + "GO";
2072+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("To update, insert & delete rows") + "SET XACT_ABORT ON" + Environment.NewLine + "BEGIN TRANSACTION;" + Environment.NewLine + Environment.NewLine + ";WITH " + Environment.NewLine + tableAliasTemp + Environment.NewLine + "AS " + Environment.NewLine + "(" + Environment.NewLine + Ribbon.AppVariables.ScriptRange + ") " + Environment.NewLine + "MERGE " + tableAlias + " AS T" + Environment.NewLine + "USING " + tableAliasTemp + " AS S" + Environment.NewLine + "ON " + Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S") + "WHEN NOT MATCHED BY TARGET" + Environment.NewLine + "THEN INSERT" + Environment.NewLine + "(" + Environment.NewLine + Ribbon.ConcatenateColumnNames(tbl.Range, "", "[", "]") + Environment.NewLine + ")" + Environment.NewLine + "VALUES" + Environment.NewLine + "(" + Environment.NewLine + Ribbon.ConcatenateColumnNames(tbl.Range, "S", "[", "]") + Environment.NewLine + ")" + Environment.NewLine + "WHEN MATCHED" + Environment.NewLine + "THEN UPDATE SET" + Environment.NewLine + Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S") + "--WHEN NOT MATCHED BY SOURCE AND 'ADD WHERE CLAUSE HERE'" + Environment.NewLine + "--THEN DELETE" + Environment.NewLine + "OUTPUT $action, inserted.*, deleted.*;" + Environment.NewLine + Environment.NewLine + "ROLLBACK TRANSACTION;" + Environment.NewLine + "--COMMIT TRANSACTION;" + Environment.NewLine + "GO";
20732073
}
20742074
catch (System.Runtime.InteropServices.COMException)
20752075
{
@@ -2173,7 +2173,7 @@ public static void TSqlSelectUnion()
21732173
sqlCol.DataBodyRange.Copy();
21742174
Ribbon.AppVariables.FileType = "SQL";
21752175
Ribbon.AppVariables.ScriptRange = (string)Clipboard.GetData(DataFormats.Text);
2176-
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
2176+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("To select values with a union operator") + Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
21772177
}
21782178
catch (System.Runtime.InteropServices.COMException)
21792179
{
@@ -2282,7 +2282,7 @@ public static void TSqlSelectValues()
22822282
sqlCol.Range.Copy();
22832283
Ribbon.AppVariables.FileType = "SQL";
22842284
Ribbon.AppVariables.ScriptRange = (string)Clipboard.GetData(DataFormats.Text);
2285-
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
2285+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("To select values") + Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
22862286
}
22872287
catch (System.Runtime.InteropServices.COMException)
22882288
{
@@ -2432,7 +2432,7 @@ public static void TSqlUpdateValues()
24322432
sqlCol.DataBodyRange.Copy();
24332433
Ribbon.AppVariables.FileType = "SQL";
24342434
Ribbon.AppVariables.ScriptRange = (string)Clipboard.GetData(DataFormats.Text);
2435-
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
2435+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("To update records") + Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
24362436
}
24372437
catch (System.Runtime.InteropServices.COMException)
24382438
{
@@ -2549,7 +2549,7 @@ public static void XmlValues()
25492549
sqlCol.DataBodyRange.Copy();
25502550
Ribbon.AppVariables.FileType = "XML";
25512551
Ribbon.AppVariables.ScriptRange = (string)Clipboard.GetData(DataFormats.Text);
2552-
Ribbon.AppVariables.ScriptRange = Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
2552+
Ribbon.AppVariables.ScriptRange = Ribbon.GetCommentHeader("XML table", "<!---", "--->") + Ribbon.AppVariables.ScriptRange.Replace(@"""", String.Empty);
25532553
}
25542554
catch (System.Runtime.InteropServices.COMException)
25552555
{

CS/Scripts/Ribbon.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public System.Drawing.Bitmap GetButtonImage(Office.IRibbonControl control)
218218
case "btnScriptTypePlSqlSelectUnion":
219219
case "btnScriptTypePlSqlUpdateValues":
220220
return Properties.Resources.ScriptTypePlSql;
221-
case "btnScriptTypeGithubTable":
221+
case "btnScriptTypeMarkdownTable":
222222
return Properties.Resources.ScriptTypeMarkdown;
223223
case "btnScriptTypeHtmlTable":
224224
case "btnScriptTypeXmlValues":
@@ -307,7 +307,7 @@ public string GetLabelText(Office.IRibbonControl control)
307307
return "DQL Update";
308308
case "btnScriptTypeDqlUpdateLocked":
309309
return "DQL Update/Locked";
310-
case "btnScriptTypeGithubTable":
310+
case "btnScriptTypeMarkdownTable":
311311
return "Markdown Table";
312312
case "btnScriptTypeHtmlTable":
313313
return "HTML Table";
@@ -504,7 +504,7 @@ public bool GetVisible(Office.IRibbonControl control)
504504
case "btnScriptTypeDqlUpdate":
505505
case "btnScriptTypeDqlUpdateLocked":
506506
return Properties.Settings.Default.Visible_mnuScriptType_DQL;
507-
case "btnScriptTypeGithubTable":
507+
case "btnScriptTypeMarkdownTable":
508508
return Properties.Settings.Default.Visible_mnuScriptType_Markdown;
509509
case "btnScriptTypeHtmlTable":
510510
case "btnScriptTypeXmlValues":
@@ -583,8 +583,8 @@ public void OnAction(Office.IRibbonControl control)
583583
case "btnScriptTypeDqlUpdateLocked":
584584
Formula.DqlUpdateLocked();
585585
break;
586-
case "btnScriptTypeGithubTable":
587-
Formula.GithubTable();
586+
case "btnScriptTypeMarkdownTable":
587+
Formula.MarkdownTable();
588588
break;
589589
case "btnScriptTypeHtmlTable":
590590
Formula.HtmlTable();
@@ -1677,6 +1677,23 @@ public string UpdateTableAliasComboBoxSource(int itemIndex)
16771677

16781678
}
16791679

1680+
/// <summary>
1681+
/// To create a header comment for the code block
1682+
/// </summary>
1683+
/// <returns></returns>
1684+
public static string GetCommentHeader(string purposeLine = "", string prefix = "/*", string suffix = "*/")
1685+
{
1686+
string noteLine = string.Concat("Generated from ", AssemblyInfo.Title);
1687+
string dividerLine = string.Concat(System.Linq.Enumerable.Repeat("=", 75));
1688+
string headerComment = prefix + Environment.NewLine;
1689+
headerComment += "|" + dividerLine + Environment.NewLine;
1690+
headerComment += "| Purpose: " + purposeLine + Environment.NewLine;
1691+
headerComment += "| Note: " + noteLine + Environment.NewLine;
1692+
headerComment += "|" + dividerLine + Environment.NewLine;
1693+
headerComment += suffix + Environment.NewLine + Environment.NewLine;
1694+
return headerComment;
1695+
}
1696+
16801697
#endregion
16811698

16821699
}

0 commit comments

Comments
 (0)