@@ -138,11 +138,18 @@ public void OnStartupComplete(ref Array custom)
138
138
//public async Task AddInButtonClicked(IRibbonControl control)
139
139
public void AddInButtonClicked ( IRibbonControl control )
140
140
{
141
- tag = control . Tag ;
141
+ try
142
+ {
143
+ tag = control . Tag ;
142
144
143
- Thread t = new Thread ( new ThreadStart ( ShowForm ) ) ;
144
- t . SetApartmentState ( ApartmentState . STA ) ;
145
- t . Start ( ) ;
145
+ Thread t = new Thread ( new ThreadStart ( ShowForm ) ) ;
146
+ t . SetApartmentState ( ApartmentState . STA ) ;
147
+ t . Start ( ) ;
148
+ }
149
+ catch ( Exception e )
150
+ {
151
+ MessageBox . Show ( "Exception from AddInButtonClicked: " + e . ToString ( ) ) ;
152
+ }
146
153
147
154
//t.Join(5000);
148
155
@@ -151,49 +158,56 @@ public void AddInButtonClicked(IRibbonControl control)
151
158
152
159
private void ShowForm ( )
153
160
{
154
- string outFileName = Guid . NewGuid ( ) . ToString ( ) ;
155
-
156
- //try
157
- //{
158
- //ProcessHelper processHelper = new ProcessHelper("NoteHighLightForm.exe", new string[] { control.Tag, outFileName });
159
- //processHelper.IsWaitForInputIdle = true;
160
- //processHelper.ProcessStart();
161
+ try
162
+ {
163
+ string outFileName = Guid . NewGuid ( ) . ToString ( ) ;
161
164
162
- //CodeForm form = new CodeForm(tag, outFileName);
163
- //form.ShowDialog();
165
+ //try
166
+ //{
167
+ //ProcessHelper processHelper = new ProcessHelper("NoteHighLightForm.exe", new string[] { control.Tag, outFileName });
168
+ //processHelper.IsWaitForInputIdle = true;
169
+ //processHelper.ProcessStart();
164
170
165
- //TestForm t = new TestForm();
166
- var pageNode = GetPageNode ( ) ;
167
- string selectedText = "" ;
168
- XElement outline = null ;
169
- bool selectedTextFormated = false ;
171
+ //CodeForm form = new CodeForm(tag, outFileName);
172
+ //form.ShowDialog();
170
173
171
- if ( pageNode != null )
172
- {
173
- var existingPageId = pageNode . Attribute ( "ID" ) . Value ;
174
- selectedText = GetSelectedText ( existingPageId , out selectedTextFormated ) ;
174
+ //TestForm t = new TestForm();
175
+ var pageNode = GetPageNode ( ) ;
176
+ string selectedText = "" ;
177
+ XElement outline = null ;
178
+ bool selectedTextFormated = false ;
175
179
176
- if ( selectedText . Trim ( ) != "" )
180
+ if ( pageNode != null )
177
181
{
178
- outline = GetOutline ( existingPageId ) ;
182
+ var existingPageId = pageNode . Attribute ( "ID" ) . Value ;
183
+ selectedText = GetSelectedText ( existingPageId , out selectedTextFormated ) ;
184
+
185
+ if ( selectedText . Trim ( ) != "" )
186
+ {
187
+ outline = GetOutline ( existingPageId ) ;
188
+ }
179
189
}
180
- }
181
190
182
191
MainForm form = new MainForm ( tag , outFileName , selectedText ) ;
183
192
184
- System . Windows . Forms . Application . Run ( form ) ;
185
- //}
186
- //catch (Exception ex)
187
- //{
188
- // MessageBox.Show("Error executing NoteHighLightForm.exe:" + ex.Message);
189
- // return;
190
- //}
193
+ System . Windows . Forms . Application . Run ( form ) ;
194
+ //}
195
+ //catch (Exception ex)
196
+ //{
197
+ // MessageBox.Show("Error executing NoteHighLightForm.exe:" + ex.Message);
198
+ // return;
199
+ //}
191
200
192
- string fileName = Path . Combine ( Path . GetTempPath ( ) , outFileName + ".html" ) ;
201
+ string fileName = Path . Combine ( Path . GetTempPath ( ) , outFileName + ".html" ) ;
193
202
194
- if ( File . Exists ( fileName ) )
203
+ if ( File . Exists ( fileName ) )
204
+ {
205
+ InsertHighLightCodeToCurrentSide ( fileName , form . Parameters , outline , selectedTextFormated ) ;
206
+ }
207
+ }
208
+ catch ( Exception e )
195
209
{
196
- InsertHighLightCodeToCurrentSide ( fileName , form . Parameters , outline , selectedTextFormated ) ;
210
+ MessageBox . Show ( "Exception from ShowForm: " + e . ToString ( ) ) ;
197
211
}
198
212
}
199
213
@@ -231,24 +245,31 @@ public IStream GetImage(string imageName)
231
245
/// </summary>
232
246
private void InsertHighLightCodeToCurrentSide ( string fileName , HighLightParameter parameters , XElement outline , bool selectedTextFormated )
233
247
{
234
- // Trace.TraceInformation(System.Reflection.MethodBase.GetCurrentMethod().Name);
235
- string htmlContent = File . ReadAllText ( fileName , Encoding . UTF8 ) ;
248
+ try
249
+ {
250
+ // Trace.TraceInformation(System.Reflection.MethodBase.GetCurrentMethod().Name);
251
+ string htmlContent = File . ReadAllText ( fileName , Encoding . UTF8 ) ;
236
252
237
- var pageNode = GetPageNode ( ) ;
253
+ var pageNode = GetPageNode ( ) ;
238
254
239
- if ( pageNode != null )
240
- {
241
- var existingPageId = pageNode . Attribute ( "ID" ) . Value ;
242
- string [ ] position = null ;
243
- if ( outline == null )
255
+ if ( pageNode != null )
244
256
{
245
- position = GetMousePointPosition ( existingPageId ) ;
246
- }
257
+ var existingPageId = pageNode . Attribute ( "ID" ) . Value ;
258
+ string [ ] position = null ;
259
+ if ( outline == null )
260
+ {
261
+ position = GetMousePointPosition ( existingPageId ) ;
262
+ }
247
263
248
- var page = InsertHighLightCode ( htmlContent , position , parameters , outline , selectedTextFormated ) ;
249
- page . Root . SetAttributeValue ( "ID" , existingPageId ) ;
264
+ var page = InsertHighLightCode ( htmlContent , position , parameters , outline , selectedTextFormated ) ;
265
+ page . Root . SetAttributeValue ( "ID" , existingPageId ) ;
250
266
251
- OneNoteApplication . UpdatePageContent ( page . ToString ( ) , DateTime . MinValue ) ;
267
+ OneNoteApplication . UpdatePageContent ( page . ToString ( ) , DateTime . MinValue ) ;
268
+ }
269
+ }
270
+ catch ( Exception e )
271
+ {
272
+ MessageBox . Show ( "Exception from InsertHighLightCodeToCurrentSide: " + e . ToString ( ) ) ;
252
273
}
253
274
}
254
275
@@ -402,6 +423,7 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
402
423
XElement cell2 = new XElement ( ns + "Cell" ) ;
403
424
cell2 . Add ( new XAttribute ( "shadingColor" , colorString ) ) ;
404
425
426
+
405
427
string defaultStyle = "" ;
406
428
407
429
var arrayLine = htmlContent . Split ( new string [ ] { Environment . NewLine } , StringSplitOptions . None ) ;
@@ -412,6 +434,8 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
412
434
if ( item . StartsWith ( "<pre" ) )
413
435
{
414
436
defaultStyle = item . Substring ( 0 , item . IndexOf ( "<span" ) ) ;
437
+ //Sets language to Latin to disable spell check
438
+ defaultStyle = defaultStyle . Insert ( defaultStyle . Length - 1 , " lang=la" ) ;
415
439
item = item . Substring ( item . IndexOf ( "<span" ) ) ;
416
440
}
417
441
@@ -452,7 +476,7 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
452
476
//string s = item.Replace(@"style=""", string.Format(@"style=""font-family:{0}; ", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value));
453
477
//string s = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
454
478
// itemLine.Replace("'", "'") + "</body>";
455
- string s = defaultStyle + itemLine . Replace ( "'" , "'" ) + "</body >" ;
479
+ string s = defaultStyle + itemLine . Replace ( "'" , "'" ) + "</pre >" ;
456
480
457
481
cell2 . Add ( new XElement ( ns + "OEChildren" ,
458
482
new XElement ( ns + "OE" ,
0 commit comments