Skip to content

Commit 9fff030

Browse files
committed
Merge branch 'BoxIn'
2 parents 5cc7e55 + c653694 commit 9fff030

12 files changed

+202
-24
lines changed

GenerateHighlightContent/GenerateHighlightContent.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<Reference Include="System" />
4141
<Reference Include="System.Configuration" />
4242
<Reference Include="System.Core" />
43+
<Reference Include="System.Drawing" />
4344
<Reference Include="System.Xml.Linq" />
4445
<Reference Include="System.Data.DataSetExtensions" />
4546
<Reference Include="Microsoft.CSharp" />

GenerateHighlightContent/IGenerateHighLight.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Drawing;
34
using System.Linq;
45
using System.Text;
56

@@ -28,5 +29,7 @@ public class HighLightParameter
2829

2930
/// <summary> 檔案名稱 </summary>
3031
public string FileName { get; set; }
32+
33+
public Color HighlightColor { get; set; }
3134
}
3235
}

NoteHighlightAddin/AddIn.cs

+90-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Helper;
2525
using System.Threading;
2626
using System.Web;
27+
using GenerateHighlightContent;
2728

2829
#pragma warning disable CS3003 // Type is not CLS-compliant
2930

@@ -153,7 +154,7 @@ private void ShowForm()
153154

154155
if (File.Exists(fileName))
155156
{
156-
InsertHighLightCodeToCurrentSide(fileName);
157+
InsertHighLightCodeToCurrentSide(fileName, form.Parameters);
157158
}
158159
}
159160

@@ -189,7 +190,7 @@ public IStream GetImage(string imageName)
189190
/// 插入 HighLight Code 至滑鼠游標的位置
190191
/// Insert HighLight Code To Mouse Position
191192
/// </summary>
192-
private void InsertHighLightCodeToCurrentSide(string fileName)
193+
private void InsertHighLightCodeToCurrentSide(string fileName, HighLightParameter parameters)
193194
{
194195
// Trace.TraceInformation(System.Reflection.MethodBase.GetCurrentMethod().Name);
195196
string htmlContent = File.ReadAllText(fileName, Encoding.UTF8);
@@ -218,7 +219,7 @@ private void InsertHighLightCodeToCurrentSide(string fileName)
218219

219220
string[] position = GetMousePointPosition(existingPageId);
220221

221-
var page = InsertHighLightCode(htmlContent, position);
222+
var page = InsertHighLightCode(htmlContent, position, parameters);
222223
page.Root.SetAttributeValue("ID", existingPageId);
223224

224225
OneNoteApplication.UpdatePageContent(page.ToString(), DateTime.MinValue);
@@ -254,21 +255,98 @@ private string[] GetMousePointPosition(string pageID)
254255
/// 產生 XML 插入至 OneNote
255256
/// Generate XML Insert To OneNote
256257
/// </summary>
257-
public XDocument InsertHighLightCode(string htmlContent, string[] position)
258+
public XDocument InsertHighLightCode(string htmlContent, string[] position, HighLightParameter parameters)
258259
{
259260
XElement children = new XElement(ns + "OEChildren");
260261

262+
XElement table = new XElement(ns + "Table");
263+
table.Add(new XAttribute("bordersVisible", "false"));
264+
265+
XElement columns = new XElement(ns + "Columns");
266+
XElement column1 = new XElement(ns + "Column");
267+
column1.Add(new XAttribute("index", "0"));
268+
column1.Add(new XAttribute("width", "40"));
269+
if (parameters.ShowLineNumber)
270+
{
271+
columns.Add(column1);
272+
}
273+
XElement column2 = new XElement(ns + "Column");
274+
if (parameters.ShowLineNumber)
275+
{
276+
column2.Add(new XAttribute("index", "1"));
277+
}
278+
else
279+
{
280+
column2.Add(new XAttribute("index", "0"));
281+
}
282+
283+
column2.Add(new XAttribute("width", "1400"));
284+
columns.Add(column2);
285+
286+
table.Add(columns);
287+
288+
Color color = parameters.HighlightColor;
289+
string colorString = string.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
290+
291+
XElement row = new XElement(ns + "Row");
292+
XElement cell1 = new XElement(ns + "Cell");
293+
cell1.Add(new XAttribute("shadingColor", colorString));
294+
XElement cell2 = new XElement(ns + "Cell");
295+
cell2.Add(new XAttribute("shadingColor", colorString));
296+
261297
var arrayLine = htmlContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
262298
foreach (var item in arrayLine)
263299
{
300+
var itemNr = "";
301+
var itemLine = "";
302+
if (parameters.ShowLineNumber)
303+
{
304+
if (item.Contains("</span>"))
305+
{
306+
int ind = item.IndexOf("</span>");
307+
itemNr = item.Substring(0, ind + ("</span>").Length);
308+
itemLine = item.Substring(ind);
309+
}
310+
else
311+
{
312+
itemNr = "";
313+
itemLine = item;
314+
}
315+
316+
string nr = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
317+
itemNr.Replace("&apos;", "'") + "</body>";
318+
319+
cell1.Add(new XElement(ns + "OEChildren",
320+
new XElement(ns + "OE",
321+
new XElement(ns + "T",
322+
new XCData(nr)))));
323+
}
324+
else
325+
{
326+
itemLine = item;
327+
}
264328
//string s = item.Replace(@"style=""", string.Format(@"style=""font-family:{0}; ", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value));
265329
string s = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
266-
HttpUtility.HtmlDecode(item) + "</body>";
267-
children.Add(new XElement(ns + "OE",
330+
itemLine.Replace("&apos;", "'") + "</body>";
331+
332+
cell2.Add(new XElement(ns + "OEChildren",
333+
new XElement(ns + "OE",
268334
new XElement(ns + "T",
269-
new XCData(s))));
335+
new XCData(s)))));
336+
270337
}
271338

339+
if (parameters.ShowLineNumber)
340+
{
341+
row.Add(cell1);
342+
}
343+
row.Add(cell2);
344+
345+
table.Add(row);
346+
347+
children.Add(new XElement(ns + "OE",
348+
table));
349+
272350
XElement outline = new XElement(ns + "Outline");
273351

274352
if (position != null && position.Length == 2)
@@ -277,6 +355,11 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position)
277355
pos.Add(new XAttribute("x", position[0]));
278356
pos.Add(new XAttribute("y", position[1]));
279357
outline.Add(pos);
358+
359+
XElement size = new XElement(ns + "Size");
360+
size.Add(new XAttribute("width", "1600"));
361+
size.Add(new XAttribute("height", "200"));
362+
outline.Add(size);
280363
}
281364
outline.Add(children);
282365

NoteHighlightAddin/App.config

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<setting name="HighLightStyle" serializeAs="String">
1818
<value>0</value>
1919
</setting>
20+
<setting name="BackgroundColor" serializeAs="String">
21+
<value>White</value>
22+
</setting>
2023
</NoteHighLightForm.Properties.Settings>
2124
</userSettings>
2225
<!--highlight CLI options Document:http://www.andre-simon.de/doku/highlight/en/highlight.html -->

NoteHighlightAddin/MainForm.Designer.cs

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

NoteHighlightAddin/MainForm.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public partial class MainForm : Form
2525
//檔案名稱
2626
private string _fileName;
2727

28+
private HighLightParameter _parameters;
29+
2830
//要HighLight的Code
2931
private string CodeContent { get { return this.txtCode.Text; } }
3032

@@ -37,6 +39,10 @@ public partial class MainForm : Form
3739
//是否存到剪貼簿
3840
private bool IsClipboard { get { return this.cbx_Clipboard.Checked; } }
3941

42+
private Color BackgroundColor { get { return this.btnBackground.BackColor; } }
43+
44+
public HighLightParameter Parameters { get { return _parameters; } }
45+
4046
#endregion
4147

4248
#region -- Constructor --
@@ -61,6 +67,7 @@ private void CodeForm_Load(object sender, EventArgs e)
6167
this.txtCode.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy(CodeTypeTransform(_codeType));
6268
this.txtCode.Encoding = Encoding.UTF8;
6369
this.cbx_style.SelectedIndex = NoteHighlightForm.Properties.Settings.Default.HighLightStyle;
70+
this.btnBackground.BackColor = NoteHighlightForm.Properties.Settings.Default.BackgroundColor;
6471
this.TopMost = true;
6572
this.TopMost = false;
6673
}
@@ -82,18 +89,19 @@ private void btnCodeHighLight_Click(object sender, EventArgs e)
8289

8390
string outputFileName = String.Empty;
8491

85-
HighLightParameter parameter = new HighLightParameter()
92+
_parameters = new HighLightParameter()
8693
{
8794
FileName = _fileName,
8895
Content = CodeContent,
8996
CodeType = _codeType,
9097
HighLightStyle = CodeStyle,
91-
ShowLineNumber = IsShowLineNumber
98+
ShowLineNumber = IsShowLineNumber,
99+
HighlightColor = BackgroundColor
92100
};
93101

94102
try
95103
{
96-
outputFileName = generate.GenerateHighLightCode(parameter);
104+
outputFileName = generate.GenerateHighLightCode(_parameters);
97105
}
98106
catch (Exception ex)
99107
{
@@ -214,7 +222,16 @@ private void SaveSetting()
214222
defaultSettings.ShowLineNumber = this.cbx_lineNumber.Checked;
215223
defaultSettings.SaveOnClipboard = this.cbx_Clipboard.Checked;
216224
defaultSettings.HighLightStyle = this.cbx_style.SelectedIndex;
225+
defaultSettings.BackgroundColor = this.btnBackground.BackColor;
217226
defaultSettings.Save();
218227
}
228+
229+
private void btnBackground_Click(object sender, EventArgs e)
230+
{
231+
if (colorDialog1.ShowDialog() == DialogResult.OK)
232+
{
233+
btnBackground.BackColor = colorDialog1.Color;
234+
}
235+
}
219236
}
220237
}

NoteHighlightAddin/MainForm.resx

+6
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,10 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+
<value>17, 17</value>
122+
</metadata>
123+
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124+
<value>186, 17</value>
125+
</metadata>
120126
</root>

NoteHighlightAddin/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
//
3434
// You can specify all the values or you can default the Build and Revision Numbers
3535
// by using the '*' as shown below:
36-
[assembly: AssemblyVersion("2.1.*")]
37-
[assembly: AssemblyFileVersion("2.1.*")]
36+
[assembly: AssemblyVersion("2.2.*")]
37+
[assembly: AssemblyFileVersion("2.2.*")]

NoteHighlightAddin/Properties/Settings.Designer.cs

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

NoteHighlightAddin/Properties/Settings.settings

+3
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
<Setting Name="HighLightStyle" Type="System.Int32" Scope="User">
1212
<Value Profile="(Default)">0</Value>
1313
</Setting>
14+
<Setting Name="BackgroundColor" Type="System.Drawing.Color" Scope="User">
15+
<Value Profile="(Default)">White</Value>
16+
</Setting>
1417
</Settings>
1518
</SettingsFile>

NoteHighlightAddin/Properties/Settings1.Designer.cs

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)