2626using System . Web ;
2727using GenerateHighlightContent ;
2828using System . Configuration ;
29+ using System . Globalization ;
2930
3031#pragma warning disable CS3003 // Type is not CLS-compliant
3132
@@ -45,7 +46,9 @@ protected Application OneNoteApplication
4546
4647 string tag ;
4748
48- public AddIn ( )
49+ private bool QuickStyle { get ; set ; }
50+
51+ public AddIn ( )
4952 {
5053 }
5154
@@ -135,7 +138,20 @@ public void OnStartupComplete(ref Array custom)
135138 {
136139 }
137140
138- //public async Task AddInButtonClicked(IRibbonControl control)
141+ public bool cbQuickStyle_GetPressed ( IRibbonControl control )
142+ {
143+ this . QuickStyle = NoteHighlightForm . Properties . Settings . Default . QuickStyle ;
144+ return this . QuickStyle ;
145+ }
146+
147+ public void cbQuickStyle_OnAction ( IRibbonControl control , bool isPressed )
148+ {
149+ this . QuickStyle = isPressed ;
150+ NoteHighlightForm . Properties . Settings . Default . QuickStyle = this . QuickStyle ;
151+ NoteHighlightForm . Properties . Settings . Default . Save ( ) ;
152+ }
153+
154+ //public async Task AddInButtonClicked(IRibbonControl control)
139155 public void AddInButtonClicked ( IRibbonControl control )
140156 {
141157 try
@@ -188,7 +204,7 @@ private void ShowForm()
188204 }
189205 }
190206
191- MainForm form = new MainForm ( tag , outFileName , selectedText ) ;
207+ MainForm form = new MainForm ( tag , outFileName , selectedText , this . QuickStyle ) ;
192208
193209 System . Windows . Forms . Application . Run ( form ) ;
194210 //}
@@ -211,7 +227,36 @@ private void ShowForm()
211227 }
212228 }
213229
230+ public void SettingsButtonClicked ( IRibbonControl control )
231+ {
232+ try
233+ {
234+
235+ Thread t = new Thread ( new ThreadStart ( ShowSettingsForm ) ) ;
236+ t . SetApartmentState ( ApartmentState . STA ) ;
237+ t . Start ( ) ;
238+ }
239+ catch ( Exception e )
240+ {
241+ MessageBox . Show ( "Exception from SettingsButtonClicked: " + e . ToString ( ) ) ;
242+ }
243+ }
214244
245+ private void ShowSettingsForm ( )
246+ {
247+ try
248+ {
249+
250+ SettingsForm form = new SettingsForm ( ) ;
251+
252+ System . Windows . Forms . Application . Run ( form ) ;
253+
254+ }
255+ catch ( Exception e )
256+ {
257+ MessageBox . Show ( "Exception from ShowForm: " + e . ToString ( ) ) ;
258+ }
259+ }
215260
216261 /// <summary>
217262 /// Specified in Ribbon.xml, this method returns the image to display on the ribbon button
@@ -267,6 +312,12 @@ private void InsertHighLightCodeToCurrentSide(string fileName, string pageXml, H
267312 var page = InsertHighLightCode ( htmlContent , position , parameters , outline , ( new GenerateHighLight ( ) ) . Config , selectedTextFormated , IsSelectedTextInline ( pageXml ) ) ;
268313 page . Root . SetAttributeValue ( "ID" , existingPageId ) ;
269314
315+ //Bug fix - remove overflow value for Indents
316+ foreach ( var el in page . Descendants ( ns + "Indent" ) . Where ( n => double . Parse ( n . Attribute ( "indent" ) . Value , new CultureInfo ( page . Root . Attribute ( "lang" ) . Value ) ) > 1000000 ) )
317+ {
318+ el . Attribute ( "indent" ) . Value = "0" ;
319+ }
320+
270321 OneNoteApplication . UpdatePageContent ( page . ToString ( ) , DateTime . MinValue ) ;
271322 }
272323 }
@@ -370,13 +421,21 @@ public string GetSelectedText(string pageXml, out bool selectedTextFormated)
370421 attrPos = table . Descendants ( ns + "Cell" ) . LastOrDefault ( ) . Descendants ( ns + "T" ) . Where ( n => n . Attribute ( "selected" ) != null && n . Attribute ( "selected" ) . Value == "all" ) ;
371422 selectedTextFormated = true ;
372423 }
373-
424+ int tabCount = 0 ;
425+ int initTabCount = - 1 ;
374426 foreach ( var line in attrPos )
375427 {
376428 var htmlDocument = new HtmlAgilityPack . HtmlDocument ( ) ;
377429 htmlDocument . LoadHtml ( line . Value ) ;
378-
379- sb . AppendLine ( HttpUtility . HtmlDecode ( htmlDocument . DocumentNode . InnerText ) ) ;
430+
431+ if ( initTabCount == - 1 )
432+ {
433+ initTabCount = line . Ancestors ( ) . Elements ( ns + "T" ) . Count ( ) ;
434+ }
435+ tabCount = line . Ancestors ( ) . Elements ( ns + "T" ) . Count ( ) - initTabCount ;
436+
437+
438+ sb . AppendLine ( new String ( '\t ' , tabCount ) + HttpUtility . HtmlDecode ( htmlDocument . DocumentNode . InnerText ) ) ;
380439 }
381440 }
382441 return sb . ToString ( ) . TrimEnd ( '\r ' , '\n ' ) ;
@@ -424,6 +483,10 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
424483 else // Update exiting outline
425484 {
426485 update = true ;
486+
487+ //Change outline width
488+ outline . Element ( ns + "Size" ) . Attribute ( "width" ) . Value = "1600" ;
489+
427490 if ( selectedTextFormated )
428491 {
429492 outline . Descendants ( ns + "Table" ) . Where ( n => n . Attribute ( "selected" ) != null &&
@@ -452,6 +515,7 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
452515 {
453516 outline . Descendants ( ns + "T" ) . Where ( n => n . Attribute ( "selected" ) != null && n . Attribute ( "selected" ) . Value == "all" ) . FirstOrDefault ( ) . ReplaceWith ( children . Descendants ( ns + "Table" ) . FirstOrDefault ( ) ) ;
454517 outline . Descendants ( ns + "OE" ) . Where ( t => t . Elements ( ns + "T" ) . Any ( n => n . Attribute ( "selected" ) != null && n . Attribute ( "selected" ) . Value == "all" ) ) . Remove ( ) ;
518+ outline . Descendants ( ns + "OEChildren" ) . Where ( n => n . HasElements == false && n . Attribute ( "selected" ) != null && ( n . Attribute ( "selected" ) . Value == "partial" ) ) . Remove ( ) ;
455519 }
456520 }
457521 }
@@ -497,7 +561,7 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
497561 XElement children = new XElement ( ns + "OEChildren" ) ;
498562
499563 XElement table = new XElement ( ns + "Table" ) ;
500- table . Add ( new XAttribute ( "bordersVisible" , "false" ) ) ;
564+ table . Add ( new XAttribute ( "bordersVisible" , NoteHighlightForm . Properties . Settings . Default . ShowTableBorder ) ) ;
501565
502566 XElement columns = new XElement ( ns + "Columns" ) ;
503567 XElement column1 = new XElement ( ns + "Column" ) ;
@@ -523,7 +587,7 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
523587 table . Add ( columns ) ;
524588
525589 Color color = parameters . HighlightColor ;
526- string colorString = string . Format ( "#{0:X2}{1:X2}{2:X2}" , color . R , color . G , color . B ) ;
590+ string colorString = color . A == 0 ? "none" : string . Format ( "#{0:X2}{1:X2}{2:X2}" , color . R , color . G , color . B ) ;
527591
528592 XElement row = new XElement ( ns + "Row" ) ;
529593 XElement cell1 = new XElement ( ns + "Cell" ) ;
0 commit comments