Skip to content

Commit 294655f

Browse files
committed
Merge branch 'unit-testing'
2 parents 7b6e24f + 44b6b17 commit 294655f

9 files changed

+3955
-27
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,8 @@ GeneratedArtifacts/
188188
_Pvt_Extensions/
189189
ModelManifest.xml
190190
INSTALLER/*
191-
.vs/config/applicationhost.config
191+
.vs/config/applicationhost.config
192+
/GenerateHighlightContent/HighlightContent2.snk
193+
/Helper/Helper2.snk
194+
/img/ONOMSPY.zip
195+
/img/onomspy.exe

NoteHighlight2016.sln

+20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenerateHighlightContent",
1313
EndProject
1414
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "SetupX86", "SetupX86\SetupX86.vdproj", "{610B97A7-752E-4501-8415-A40251735F85}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting", "UnitTesting\UnitTesting.csproj", "{3E05522E-BD98-4813-8430-83AE4F320EB2}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -113,6 +115,24 @@ Global
113115
{610B97A7-752E-4501-8415-A40251735F85}.Release|x64.Build.0 = Release
114116
{610B97A7-752E-4501-8415-A40251735F85}.Release|x86.ActiveCfg = Release
115117
{610B97A7-752E-4501-8415-A40251735F85}.Release|x86.Build.0 = Release
118+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
120+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Debug|x64.ActiveCfg = Debug|Any CPU
121+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Debug|x64.Build.0 = Debug|Any CPU
122+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Debug|x86.ActiveCfg = Debug|Any CPU
123+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Debug|x86.Build.0 = Debug|Any CPU
124+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.LocalDebug|Any CPU.ActiveCfg = Debug|Any CPU
125+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.LocalDebug|Any CPU.Build.0 = Debug|Any CPU
126+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.LocalDebug|x64.ActiveCfg = Debug|Any CPU
127+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.LocalDebug|x64.Build.0 = Debug|Any CPU
128+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.LocalDebug|x86.ActiveCfg = Debug|Any CPU
129+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.LocalDebug|x86.Build.0 = Debug|Any CPU
130+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
131+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Release|x64.ActiveCfg = Release|Any CPU
133+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Release|x64.Build.0 = Release|Any CPU
134+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Release|x86.ActiveCfg = Release|Any CPU
135+
{3E05522E-BD98-4813-8430-83AE4F320EB2}.Release|x86.Build.0 = Release|Any CPU
116136
EndGlobalSection
117137
GlobalSection(SolutionProperties) = preSolution
118138
HideSolutionNode = FALSE

NoteHighlightAddin/AddIn.cs

+20-26
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class AddIn : IDTExtensibility2, IRibbonExtensibility
3939
protected Application OneNoteApplication
4040
{ get; set; }
4141

42-
private XNamespace ns;
42+
public XNamespace ns;
4343

4444
private MainForm mainForm;
4545

@@ -173,18 +173,18 @@ private void ShowForm()
173173

174174
//TestForm t = new TestForm();
175175
var pageNode = GetPageNode();
176+
string pageXml = GetPageXml(pageNode.Attribute("ID").Value);
176177
string selectedText = "";
177178
XElement outline = null;
178179
bool selectedTextFormated = false;
179180

180181
if (pageNode != null)
181182
{
182-
var existingPageId = pageNode.Attribute("ID").Value;
183-
selectedText = GetSelectedText(existingPageId, out selectedTextFormated);
183+
selectedText = GetSelectedText(pageXml, out selectedTextFormated);
184184

185185
if (selectedText.Trim() != "")
186186
{
187-
outline = GetOutline(existingPageId);
187+
outline = GetOutline(pageXml);
188188
}
189189
}
190190

@@ -202,7 +202,7 @@ private void ShowForm()
202202

203203
if (File.Exists(fileName))
204204
{
205-
InsertHighLightCodeToCurrentSide(fileName, form.Parameters, outline, selectedTextFormated);
205+
InsertHighLightCodeToCurrentSide(fileName, pageXml, form.Parameters, outline, selectedTextFormated);
206206
}
207207
}
208208
catch (Exception e)
@@ -243,7 +243,7 @@ public IStream GetImage(string imageName)
243243
/// 插入 HighLight Code 至滑鼠游標的位置
244244
/// Insert HighLight Code To Mouse Position
245245
/// </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)
247247
{
248248
try
249249
{
@@ -261,10 +261,10 @@ private void InsertHighLightCodeToCurrentSide(string fileName, HighLightParamete
261261
string[] position = null;
262262
if (outline == null)
263263
{
264-
position = GetMousePointPosition(existingPageId);
264+
position = GetMousePointPosition(pageXml);
265265
}
266266

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));
268268
page.Root.SetAttributeValue("ID", existingPageId);
269269

270270
OneNoteApplication.UpdatePageContent(page.ToString(), DateTime.MinValue);
@@ -302,11 +302,8 @@ XElement GetPageNode()
302302
/// 取得滑鼠所在的點
303303
/// Get Mouse Point
304304
/// </summary>
305-
private string[] GetMousePointPosition(string pageID)
305+
private string[] GetMousePointPosition(string pageXml)
306306
{
307-
string pageXml;
308-
OneNoteApplication.GetPageContent(pageID, out pageXml, PageInfo.piSelection);
309-
310307
var node = XDocument.Parse(pageXml).Descendants(ns + "Outline")
311308
.Where(n => n.Attribute("selected") != null && n.Attribute("selected").Value == "partial")
312309
.FirstOrDefault();
@@ -323,11 +320,8 @@ private string[] GetMousePointPosition(string pageID)
323320
return null;
324321
}
325322

326-
private XElement GetOutline(string pageID)
323+
private XElement GetOutline(string pageXml)
327324
{
328-
string pageXml;
329-
OneNoteApplication.GetPageContent(pageID, out pageXml, PageInfo.piSelection);
330-
331325
var node = XDocument.Parse(pageXml).Descendants(ns + "Outline")
332326
.Where(n => n.Attribute("selected") != null && (n.Attribute("selected").Value == "all" || n.Attribute("selected").Value == "partial"))
333327
.FirstOrDefault();
@@ -346,11 +340,16 @@ private XElement GetOutline(string pageID)
346340
return node;
347341
}
348342

349-
private string GetSelectedText(string pageID, out bool selectedTextFormated)
343+
private string GetPageXml(string pageID)
350344
{
351345
string pageXml;
352346
OneNoteApplication.GetPageContent(pageID, out pageXml, PageInfo.piSelection);
353347

348+
return pageXml;
349+
}
350+
351+
public string GetSelectedText(string pageXml, out bool selectedTextFormated)
352+
{
354353
var node = XDocument.Parse(pageXml).Descendants(ns + "Outline")
355354
.Where(n => n.Attribute("selected") != null && (n.Attribute("selected").Value == "all" || n.Attribute("selected").Value == "partial"))
356355
.FirstOrDefault();
@@ -383,11 +382,8 @@ private string GetSelectedText(string pageID, out bool selectedTextFormated)
383382
return sb.ToString().TrimEnd('\r','\n');
384383
}
385384

386-
private bool IsSelectedTextInline(string pageID)
385+
public bool IsSelectedTextInline(string pageXml)
387386
{
388-
string pageXml;
389-
OneNoteApplication.GetPageContent(pageID, out pageXml, PageInfo.piSelection);
390-
391387
var node = XDocument.Parse(pageXml).Descendants(ns + "Outline")
392388
.Where(n => n.Attribute("selected") != null && (n.Attribute("selected").Value == "all" || n.Attribute("selected").Value == "partial"))
393389
.FirstOrDefault();
@@ -416,9 +412,9 @@ private bool IsSelectedTextInline(string pageID)
416412
/// 產生 XML 插入至 OneNote
417413
/// Generate XML Insert To OneNote
418414
/// </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)
420416
{
421-
XElement children = PrepareFormatedContent(htmlContent, parameters, isInline);
417+
XElement children = PrepareFormatedContent(htmlContent, parameters, config, isInline);
422418

423419
bool update = false;
424420
if (outline == null)
@@ -496,10 +492,8 @@ private XElement CreateOutline(string[] position, XElement children)
496492
return outline;
497493
}
498494

499-
private XElement PrepareFormatedContent(string htmlContent, HighLightParameter parameters, bool isInline)
495+
private XElement PrepareFormatedContent(string htmlContent, HighLightParameter parameters, HighLightSection config, bool isInline)
500496
{
501-
HighLightSection config = (new GenerateHighLight()).Config;
502-
503497
XElement children = new XElement(ns + "OEChildren");
504498

505499
XElement table = new XElement(ns + "Table");
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("UnitTesting")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("UnitTesting")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("3e05522e-bd98-4813-8430-83ae4f320eb2")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)