Skip to content

Commit ca07ff7

Browse files
tduguidtduguid
authored andcommitted
Added context menu items and updated error class
1 parent 3dfd174 commit ca07ff7

File tree

10 files changed

+231
-60
lines changed

10 files changed

+231
-60
lines changed

CS/Properties/Resources.Designer.cs

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

CS/Properties/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,13 @@
157157
<data name="ScriptTypeMarkup" type="System.Resources.ResXFileRef, System.Windows.Forms">
158158
<value>..\Resources\ScriptTypeMarkup.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
159159
</data>
160+
<data name="SaveCode" type="System.Resources.ResXFileRef, System.Windows.Forms">
161+
<value>..\Resources\SaveCode.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
162+
</data>
163+
<data name="SaveVersion" type="System.Resources.ResXFileRef, System.Windows.Forms">
164+
<value>..\Resources\SaveVersion.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
165+
</data>
166+
<data name="camera" type="System.Resources.ResXFileRef, System.Windows.Forms">
167+
<value>..\Resources\camera.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
168+
</data>
160169
</root>

CS/Resources/SaveCode.png

804 Bytes
Loading

CS/Resources/SaveVersion.png

755 Bytes
Loading

CS/Resources/camera.png

665 Bytes
Loading

CS/Ribbon.xml

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,80 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
33

4-
<!--
5-
Use the following tags to remove indivdual ribbons when this loads
6-
<tab idMso="TabHome" getVisible="GetVisible"/>
7-
<tab idMso="TabInsert" getVisible="GetVisible"/>
8-
<tab idMso="TabReview" getVisible="GetVisible"/>
9-
<tab idMso="TabData" getVisible="GetVisible"/>
10-
<tab idMso="TabView" getVisible="GetVisible"/>
11-
<tab idMso="TabFormulas" getVisible="GetVisible"/>
12-
<tab idMso="TabPageLayoutExcel" getVisible="GetVisible"/>
13-
<tab idMso="TabDeveloper" getVisible="GetVisible"/>
14-
<tab idMso="TabPrintPreview" getVisible="GetVisible"/>
15-
<tab idMso="TabAddIns" getVisible="GetVisible"/>
16-
<tab idMso="TabSetTableToolsExcel" getVisible="GetVisible"/>
17-
Or use the following tag to remove all other ribbons when this loads
184
<ribbon startFromScratch="true">
19-
-->
20-
<ribbon startFromScratch="false">
215
<qat>
226
<sharedControls >
7+
<control
8+
idMso ="Undo"
9+
/>
10+
<control
11+
idMso ="Redo"
12+
/>
13+
<button
14+
idMso ="FileSendAsAttachment"
15+
label="Email"
16+
screentip="Email File As Attachment"
17+
supertip="This will email the current file as an attachment. "
18+
/>
19+
<separator id="sepSc1"/>
20+
<button
21+
id="btnSaveVersion"
22+
label="Save Version"
23+
onAction="OnAction"
24+
getImage="GetButtonImage"
25+
screentip="Save File As Version"
26+
supertip="This will save the current file as a version in the same directory."
27+
/>
28+
<button
29+
id="btnSaveCode"
30+
label="Save Code"
31+
onAction="OnAction"
32+
getImage="GetButtonImage"
33+
screentip="Save VBA/XML Code"
34+
supertip="This will save the VBA and XML for the current file in the same directory. (Coming Soon!)"
35+
enabled="false"
36+
/>
37+
<separator id="sepSc2"/>
2338
<button
2439
idMso ="Camera"
2540
label="Excel Camera"
41+
getImage="GetButtonImage"
2642
screentip="Microsoft Excel Camera"
2743
supertip="This tool allows you to take a snapshot of a selected datasheet portion, it also syncs the data with the image; whenever you make changes to the original data set, live image gets updated, showing you the latest cells values. "
2844
/>
45+
<button
46+
id="btnSnippingTool1"
47+
label="Snipping Tool"
48+
onAction="OnAction"
49+
getImage="GetButtonImage"
50+
screentip="Microsoft Snipping Tool"
51+
supertip="Snipping Tool is a screenshot utility included in Microsoft Windows. It can take screenshots of an open window, rectangular areas, a free-form area, or the entire screen."
52+
/>
53+
<button
54+
id="btnProblemStepRecorder1"
55+
label="Record Steps"
56+
onAction="OnAction"
57+
getImage="GetButtonImage"
58+
screentip="Microsoft Problem Steps Recorder"
59+
supertip="Problem Steps Recorder or PSR records the actions you take on your computer which you can then send to the person or group helping you with your computer problem."
60+
/>
2961
</sharedControls>
3062
<documentControls >
3163
<button idMso="Cut"/>
3264
</documentControls>
3365
</qat>
3466
<tabs>
67+
<tab idMso="TabHome" visible="true" />
68+
<tab idMso="TabInsert" visible="true" />
69+
<tab idMso="TabReview" visible="true" />
70+
<tab idMso="TabData" visible="true" />
71+
<tab idMso="TabView" visible="true" />
72+
<tab idMso="TabFormulas" visible="true" />
73+
<tab idMso="TabPageLayoutExcel" visible="true" />
74+
<tab idMso="TabDeveloper" visible="true" />
75+
<tab idMso="TabPrintPreview" visible="true" />
76+
<tab idMso="TabAddIns" visible="true" />
77+
<tab idMso="TabSetTableToolsExcel" visible="true" />
3578
<tab
3679
id="tabScriptHelp"
3780
getLabel="GetLabelText"

CS/ScriptHelp.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@
269269
<None Include="Resources\Download.png" />
270270
<None Include="Resources\problem_steps_recorder.png" />
271271
<None Include="Resources\snipping_tool.png" />
272+
<None Include="Resources\SaveCode.png" />
273+
<None Include="Resources\SaveVersion.png" />
274+
<None Include="Resources\camera.png" />
272275
<Content Include="Resources\ScreenToGif.exe">
273276
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
274277
</Content>

CS/Scripts/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public static string GetAssemblyLocation()
300300
}
301301

302302
/// <summary>
303-
///
303+
/// Set Assembly Folder Version
304304
/// </summary>
305305
public static void SetAssemblyFolderVersion()
306306
{

CS/Scripts/ErrorHandler.cs

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Linq;
3+
using System.Text;
4+
using System.Collections.Generic;
25
using System.Windows.Forms;
36
using System.Runtime.InteropServices;
47
using Excel = Microsoft.Office.Interop.Excel;
@@ -15,7 +18,7 @@ namespace ScriptHelp.Scripts
1518
/// <summary>
1619
/// Used to handle exceptions
1720
/// </summary>
18-
public class ErrorHandler
21+
public static class ErrorHandler
1922
{
2023
private static readonly ILog log = LogManager.GetLogger(typeof(ErrorHandler));
2124

@@ -27,6 +30,7 @@ public static void SetLogPath()
2730
XmlConfigurator.Configure();
2831
log4net.Repository.Hierarchy.Hierarchy h = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
2932
string logFileName = System.IO.Path.Combine(Properties.Settings.Default.App_PathLocalData, AssemblyInfo.Product + ".log");
33+
3034
foreach (var a in h.Root.Appenders)
3135
{
3236
if (a is log4net.Appender.FileAppender)
@@ -48,10 +52,20 @@ public static void CreateLogRecord()
4852
{
4953
try
5054
{
51-
System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(1);
52-
System.Reflection.MethodBase caller = sf.GetMethod();
53-
string currentProcedure = (caller.Name).Trim();
54-
log.Info("[PROCEDURE]=|" + currentProcedure + "|[USER NAME]=|" + Environment.UserName + "|[MACHINE NAME]=|" + Environment.MachineName);
55+
// gather context
56+
var sf = new System.Diagnostics.StackFrame(1);
57+
var caller = sf.GetMethod();
58+
var currentProcedure = caller.Name.Trim();
59+
60+
// handle log record
61+
var logMessage = string.Concat(new Dictionary<string, string>
62+
{
63+
["PROCEDURE"] = currentProcedure,
64+
["USER NAME"] = Environment.UserName,
65+
["MACHINE NAME"] = Environment.MachineName
66+
}.Select(x => $"[{x.Key}]=|{x.Value}|"));
67+
log.Info(logMessage);
68+
5569
}
5670
catch (Exception ex)
5771
{
@@ -73,19 +87,35 @@ public static void CreateLogRecord()
7387
/// <remarks></remarks>
7488
public static void DisplayMessage(Exception ex, Boolean isSilent = false)
7589
{
76-
System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(1);
77-
System.Reflection.MethodBase caller = sf.GetMethod();
78-
string currentProcedure = (caller.Name).Trim();
79-
string currentFileName = AssemblyInfo.GetCurrentFileName();
80-
string errorMessageDescription = ex.ToString();
81-
errorMessageDescription = System.Text.RegularExpressions.Regex.Replace(errorMessageDescription, @"\r\n+", " "); //the carriage returns were messing up my log file
82-
string msg = "Contact your system administrator. A record has been created in the log file." + Environment.NewLine;
83-
msg += "Procedure: " + currentProcedure + Environment.NewLine;
84-
msg += "Description: " + ex.ToString() + Environment.NewLine;
85-
log.Error("[PROCEDURE]=|" + currentProcedure + "|[USER NAME]=|" + Environment.UserName + "|[MACHINE NAME]=|" + Environment.MachineName + "|[FILE NAME]=|" + currentFileName + "|[DESCRIPTION]=|" + errorMessageDescription);
90+
// gather context
91+
var sf = new System.Diagnostics.StackFrame(1);
92+
var caller = sf.GetMethod();
93+
var errorDescription = ex.ToString().Replace("\r\n", " "); // the carriage returns were messing up my log file
94+
var currentProcedure = caller.Name.Trim();
95+
var currentFileName = AssemblyInfo.GetCurrentFileName();
96+
97+
// handle log record
98+
var logMessage = string.Concat(new Dictionary<string, string>
99+
{
100+
["PROCEDURE"] = currentProcedure,
101+
["USER NAME"] = Environment.UserName,
102+
["MACHINE NAME"] = Environment.MachineName,
103+
["FILE NAME"] = currentFileName,
104+
["DESCRIPTION"] = errorDescription,
105+
}.Select(x => $"[{x.Key}]=|{x.Value}|"));
106+
log.Error(logMessage);
107+
108+
// format message
109+
var userMessage = new StringBuilder()
110+
.AppendLine("Contact your system administrator. A record has been created in the log file.")
111+
.AppendLine("Procedure: " + currentProcedure)
112+
.AppendLine("Description: " + errorDescription)
113+
.ToString();
114+
115+
// handle message
86116
if (isSilent == false)
87117
{
88-
MessageBox.Show(msg, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
118+
MessageBox.Show(userMessage, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
89119
}
90120
}
91121

0 commit comments

Comments
 (0)