Skip to content

Commit 9ef64e6

Browse files
committed
Merge branch 'vs2019'
2 parents 6e70bf1 + cc25937 commit 9ef64e6

20 files changed

Lines changed: 730 additions & 218 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,4 @@ INSTALLER/*
193193
/Helper/Helper2.snk
194194
/img/ONOMSPY.zip
195195
/img/onomspy.exe
196+
/.vs/

GenerateHighlightContent/GenerateHighLight.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public class GenerateHighLight : IGenerateHighLight
2424

2525
public string FileName { get; set; }
2626

27+
public string Font { get; set; }
28+
29+
public int FontSize { get; set; }
30+
2731
/// <summary> highlight.exe 參數 設定於 App.config 的 HighLightSection 區塊 </summary>
2832
private HighLightSection _section;
2933

@@ -76,6 +80,8 @@ private void InitParameter(HighLightParameter parameter)
7680
HighLightStyle = parameter.HighLightStyle;
7781
ShowLineNumber = parameter.ShowLineNumber;
7882
FileName = parameter.FileName;
83+
Font = parameter.Font;
84+
FontSize = parameter.FontSize;
7985
}
8086

8187
/// <summary> 產生HighLight.exe 所需的參數 </summary>
@@ -91,10 +97,12 @@ private string GenerateArguments(string inputFileName, string outputFileName)
9197

9298
string arguments = sb.ToString().TemplateSubstitute(new
9399
{
94-
inputFileName = String.Format("\"{0}\"",inputFileName),
95-
outputFileName = String.Format("\"{0}\"",outputFileName),
100+
inputFileName = String.Format("\"{0}\"", inputFileName),
101+
outputFileName = String.Format("\"{0}\"", outputFileName),
96102
codeType = CodeType,
97-
highLightStyle = HighLightStyle
103+
highLightStyle = HighLightStyle,
104+
font = String.Format("\"{0}\"", Font),
105+
fontSize = FontSize
98106
});
99107

100108
return arguments;

GenerateHighlightContent/IGenerateHighLight.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ public class HighLightParameter
3131
public string FileName { get; set; }
3232

3333
public Color HighlightColor { get; set; }
34+
35+
public string Font { get; set; }
36+
37+
public int FontSize { get; set; }
3438
}
3539
}

GenerateHighlightContent/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號
3333
// 指定為預設值:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.6.0.0")]
36-
[assembly: AssemblyFileVersion("2.6.0.0")]
35+
[assembly: AssemblyVersion("2.7.0.0")]
36+
[assembly: AssemblyFileVersion("2.7.0.0")]

NoteHighlightAddin/AddIn.cs

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Web;
2727
using GenerateHighlightContent;
2828
using 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");

NoteHighlightAddin/App.config

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
55
<section name="NoteHighLightForm.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
66
</sectionGroup>
7-
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.6.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
7+
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.7.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
88
</configSections>
99
<userSettings>
1010
<NoteHighLightForm.Properties.Settings>
@@ -20,6 +20,18 @@
2020
<setting name="BackgroundColor" serializeAs="String">
2121
<value>White</value>
2222
</setting>
23+
<setting name="QuickStyle" serializeAs="String">
24+
<value>False</value>
25+
</setting>
26+
<setting name="Font" serializeAs="String">
27+
<value>Courier New</value>
28+
</setting>
29+
<setting name="FontSize" serializeAs="String">
30+
<value>10</value>
31+
</setting>
32+
<setting name="ShowTableBorder" serializeAs="String">
33+
<value>False</value>
34+
</setting>
2335
</NoteHighLightForm.Properties.Settings>
2436
</userSettings>
2537
<!--highlight CLI options Document:http://www.andre-simon.de/doku/highlight/en/highlight.html -->
@@ -38,8 +50,8 @@
3850
<add Name="LineNumbers" Key="-l" Value="" Option="true"/>
3951
<add Name="Style" Key="-s" Value="{highLightStyle}"/>
4052
<add Name="LineNumberLength" Key="-j" Value="5"/>
41-
<add Name="Font" Key="-k" Value="Courier New"/>
42-
<add Name="FontSize" Key="-K" Value="10"/>
53+
<add Name="Font" Key="-k" Value="{font}"/>
54+
<add Name="FontSize" Key="-K" Value="{fontSize}"/>
4355
<add Name="OutFormat" Key="-O" Value="html"/>
4456
</OutputArguments>
4557
</HighLightSection>

NoteHighlightAddin/MainForm.Designer.cs

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

0 commit comments

Comments
 (0)