@@ -39,7 +39,7 @@ public class AddIn : IDTExtensibility2, IRibbonExtensibility
39
39
protected Application OneNoteApplication
40
40
{ get ; set ; }
41
41
42
- private XNamespace ns ;
42
+ public XNamespace ns ;
43
43
44
44
private MainForm mainForm ;
45
45
@@ -173,18 +173,18 @@ private void ShowForm()
173
173
174
174
//TestForm t = new TestForm();
175
175
var pageNode = GetPageNode ( ) ;
176
+ string pageXml = GetPageXml ( pageNode . Attribute ( "ID" ) . Value ) ;
176
177
string selectedText = "" ;
177
178
XElement outline = null ;
178
179
bool selectedTextFormated = false ;
179
180
180
181
if ( pageNode != null )
181
182
{
182
- var existingPageId = pageNode . Attribute ( "ID" ) . Value ;
183
- selectedText = GetSelectedText ( existingPageId , out selectedTextFormated ) ;
183
+ selectedText = GetSelectedText ( pageXml , out selectedTextFormated ) ;
184
184
185
185
if ( selectedText . Trim ( ) != "" )
186
186
{
187
- outline = GetOutline ( existingPageId ) ;
187
+ outline = GetOutline ( pageXml ) ;
188
188
}
189
189
}
190
190
@@ -202,7 +202,7 @@ private void ShowForm()
202
202
203
203
if ( File . Exists ( fileName ) )
204
204
{
205
- InsertHighLightCodeToCurrentSide ( fileName , form . Parameters , outline , selectedTextFormated ) ;
205
+ InsertHighLightCodeToCurrentSide ( fileName , pageXml , form . Parameters , outline , selectedTextFormated ) ;
206
206
}
207
207
}
208
208
catch ( Exception e )
@@ -243,7 +243,7 @@ public IStream GetImage(string imageName)
243
243
/// 插入 HighLight Code 至滑鼠游標的位置
244
244
/// Insert HighLight Code To Mouse Position
245
245
/// </summary>
246
- private void InsertHighLightCodeToCurrentSide ( string fileName , HighLightParameter parameters , XElement outline , bool selectedTextFormated )
246
+ private void InsertHighLightCodeToCurrentSide ( string fileName , string pageXml , HighLightParameter parameters , XElement outline , bool selectedTextFormated )
247
247
{
248
248
try
249
249
{
@@ -261,10 +261,10 @@ private void InsertHighLightCodeToCurrentSide(string fileName, HighLightParamete
261
261
string [ ] position = null ;
262
262
if ( outline == null )
263
263
{
264
- position = GetMousePointPosition ( existingPageId ) ;
264
+ position = GetMousePointPosition ( pageXml ) ;
265
265
}
266
266
267
- var page = InsertHighLightCode ( htmlContent , position , parameters , outline , selectedTextFormated , IsSelectedTextInline ( existingPageId ) ) ;
267
+ var page = InsertHighLightCode ( htmlContent , position , parameters , outline , ( new GenerateHighLight ( ) ) . Config , selectedTextFormated , IsSelectedTextInline ( pageXml ) ) ;
268
268
page . Root . SetAttributeValue ( "ID" , existingPageId ) ;
269
269
270
270
OneNoteApplication . UpdatePageContent ( page . ToString ( ) , DateTime . MinValue ) ;
@@ -302,11 +302,8 @@ XElement GetPageNode()
302
302
/// 取得滑鼠所在的點
303
303
/// Get Mouse Point
304
304
/// </summary>
305
- private string [ ] GetMousePointPosition ( string pageID )
305
+ private string [ ] GetMousePointPosition ( string pageXml )
306
306
{
307
- string pageXml ;
308
- OneNoteApplication . GetPageContent ( pageID , out pageXml , PageInfo . piSelection ) ;
309
-
310
307
var node = XDocument . Parse ( pageXml ) . Descendants ( ns + "Outline" )
311
308
. Where ( n => n . Attribute ( "selected" ) != null && n . Attribute ( "selected" ) . Value == "partial" )
312
309
. FirstOrDefault ( ) ;
@@ -323,11 +320,8 @@ private string[] GetMousePointPosition(string pageID)
323
320
return null ;
324
321
}
325
322
326
- private XElement GetOutline ( string pageID )
323
+ private XElement GetOutline ( string pageXml )
327
324
{
328
- string pageXml ;
329
- OneNoteApplication . GetPageContent ( pageID , out pageXml , PageInfo . piSelection ) ;
330
-
331
325
var node = XDocument . Parse ( pageXml ) . Descendants ( ns + "Outline" )
332
326
. Where ( n => n . Attribute ( "selected" ) != null && ( n . Attribute ( "selected" ) . Value == "all" || n . Attribute ( "selected" ) . Value == "partial" ) )
333
327
. FirstOrDefault ( ) ;
@@ -346,11 +340,16 @@ private XElement GetOutline(string pageID)
346
340
return node ;
347
341
}
348
342
349
- private string GetSelectedText ( string pageID , out bool selectedTextFormated )
343
+ private string GetPageXml ( string pageID )
350
344
{
351
345
string pageXml ;
352
346
OneNoteApplication . GetPageContent ( pageID , out pageXml , PageInfo . piSelection ) ;
353
347
348
+ return pageXml ;
349
+ }
350
+
351
+ public string GetSelectedText ( string pageXml , out bool selectedTextFormated )
352
+ {
354
353
var node = XDocument . Parse ( pageXml ) . Descendants ( ns + "Outline" )
355
354
. Where ( n => n . Attribute ( "selected" ) != null && ( n . Attribute ( "selected" ) . Value == "all" || n . Attribute ( "selected" ) . Value == "partial" ) )
356
355
. FirstOrDefault ( ) ;
@@ -383,11 +382,8 @@ private string GetSelectedText(string pageID, out bool selectedTextFormated)
383
382
return sb . ToString ( ) . TrimEnd ( '\r ' , '\n ' ) ;
384
383
}
385
384
386
- private bool IsSelectedTextInline ( string pageID )
385
+ public bool IsSelectedTextInline ( string pageXml )
387
386
{
388
- string pageXml ;
389
- OneNoteApplication . GetPageContent ( pageID , out pageXml , PageInfo . piSelection ) ;
390
-
391
387
var node = XDocument . Parse ( pageXml ) . Descendants ( ns + "Outline" )
392
388
. Where ( n => n . Attribute ( "selected" ) != null && ( n . Attribute ( "selected" ) . Value == "all" || n . Attribute ( "selected" ) . Value == "partial" ) )
393
389
. FirstOrDefault ( ) ;
@@ -416,9 +412,9 @@ private bool IsSelectedTextInline(string pageID)
416
412
/// 產生 XML 插入至 OneNote
417
413
/// Generate XML Insert To OneNote
418
414
/// </summary>
419
- public XDocument InsertHighLightCode ( string htmlContent , string [ ] position , HighLightParameter parameters , XElement outline , bool selectedTextFormated , bool isInline )
415
+ public XDocument InsertHighLightCode ( string htmlContent , string [ ] position , HighLightParameter parameters , XElement outline , HighLightSection config , bool selectedTextFormated , bool isInline )
420
416
{
421
- XElement children = PrepareFormatedContent ( htmlContent , parameters , isInline ) ;
417
+ XElement children = PrepareFormatedContent ( htmlContent , parameters , config , isInline ) ;
422
418
423
419
bool update = false ;
424
420
if ( outline == null )
@@ -496,10 +492,8 @@ private XElement CreateOutline(string[] position, XElement children)
496
492
return outline ;
497
493
}
498
494
499
- private XElement PrepareFormatedContent ( string htmlContent , HighLightParameter parameters , bool isInline )
495
+ private XElement PrepareFormatedContent ( string htmlContent , HighLightParameter parameters , HighLightSection config , bool isInline )
500
496
{
501
- HighLightSection config = ( new GenerateHighLight ( ) ) . Config ;
502
-
503
497
XElement children = new XElement ( ns + "OEChildren" ) ;
504
498
505
499
XElement table = new XElement ( ns + "Table" ) ;
0 commit comments