Skip to content

Commit

Permalink
Merge branch 'BoxIn'
Browse files Browse the repository at this point in the history
  • Loading branch information
elvirbrk committed Mar 9, 2017
2 parents 5cc7e55 + c653694 commit 9fff030
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 24 deletions.
1 change: 1 addition & 0 deletions GenerateHighlightContent/GenerateHighlightContent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
3 changes: 3 additions & 0 deletions GenerateHighlightContent/IGenerateHighLight.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

Expand Down Expand Up @@ -28,5 +29,7 @@ public class HighLightParameter

/// <summary> 檔案名稱 </summary>
public string FileName { get; set; }

public Color HighlightColor { get; set; }
}
}
97 changes: 90 additions & 7 deletions NoteHighlightAddin/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Helper;
using System.Threading;
using System.Web;
using GenerateHighlightContent;

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

Expand Down Expand Up @@ -153,7 +154,7 @@ private void ShowForm()

if (File.Exists(fileName))
{
InsertHighLightCodeToCurrentSide(fileName);
InsertHighLightCodeToCurrentSide(fileName, form.Parameters);
}
}

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

string[] position = GetMousePointPosition(existingPageId);

var page = InsertHighLightCode(htmlContent, position);
var page = InsertHighLightCode(htmlContent, position, parameters);
page.Root.SetAttributeValue("ID", existingPageId);

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

XElement table = new XElement(ns + "Table");
table.Add(new XAttribute("bordersVisible", "false"));

XElement columns = new XElement(ns + "Columns");
XElement column1 = new XElement(ns + "Column");
column1.Add(new XAttribute("index", "0"));
column1.Add(new XAttribute("width", "40"));
if (parameters.ShowLineNumber)
{
columns.Add(column1);
}
XElement column2 = new XElement(ns + "Column");
if (parameters.ShowLineNumber)
{
column2.Add(new XAttribute("index", "1"));
}
else
{
column2.Add(new XAttribute("index", "0"));
}

column2.Add(new XAttribute("width", "1400"));
columns.Add(column2);

table.Add(columns);

Color color = parameters.HighlightColor;
string colorString = string.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);

XElement row = new XElement(ns + "Row");
XElement cell1 = new XElement(ns + "Cell");
cell1.Add(new XAttribute("shadingColor", colorString));
XElement cell2 = new XElement(ns + "Cell");
cell2.Add(new XAttribute("shadingColor", colorString));

var arrayLine = htmlContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
foreach (var item in arrayLine)
{
var itemNr = "";
var itemLine = "";
if (parameters.ShowLineNumber)
{
if (item.Contains("</span>"))
{
int ind = item.IndexOf("</span>");
itemNr = item.Substring(0, ind + ("</span>").Length);
itemLine = item.Substring(ind);
}
else
{
itemNr = "";
itemLine = item;
}

string nr = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
itemNr.Replace("&apos;", "'") + "</body>";

cell1.Add(new XElement(ns + "OEChildren",
new XElement(ns + "OE",
new XElement(ns + "T",
new XCData(nr)))));
}
else
{
itemLine = item;
}
//string s = item.Replace(@"style=""", string.Format(@"style=""font-family:{0}; ", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value));
string s = string.Format(@"<body style=""font-family:{0}"">", GenerateHighlightContent.GenerateHighLight.Config.OutputArguments["Font"].Value) +
HttpUtility.HtmlDecode(item) + "</body>";
children.Add(new XElement(ns + "OE",
itemLine.Replace("&apos;", "'") + "</body>";

cell2.Add(new XElement(ns + "OEChildren",
new XElement(ns + "OE",
new XElement(ns + "T",
new XCData(s))));
new XCData(s)))));

}

if (parameters.ShowLineNumber)
{
row.Add(cell1);
}
row.Add(cell2);

table.Add(row);

children.Add(new XElement(ns + "OE",
table));

XElement outline = new XElement(ns + "Outline");

if (position != null && position.Length == 2)
Expand All @@ -277,6 +355,11 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position)
pos.Add(new XAttribute("x", position[0]));
pos.Add(new XAttribute("y", position[1]));
outline.Add(pos);

XElement size = new XElement(ns + "Size");
size.Add(new XAttribute("width", "1600"));
size.Add(new XAttribute("height", "200"));
outline.Add(size);
}
outline.Add(children);

Expand Down
3 changes: 3 additions & 0 deletions NoteHighlightAddin/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<setting name="HighLightStyle" serializeAs="String">
<value>0</value>
</setting>
<setting name="BackgroundColor" serializeAs="String">
<value>White</value>
</setting>
</NoteHighLightForm.Properties.Settings>
</userSettings>
<!--highlight CLI options Document:http://www.andre-simon.de/doku/highlight/en/highlight.html -->
Expand Down
17 changes: 16 additions & 1 deletion NoteHighlightAddin/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions NoteHighlightAddin/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public partial class MainForm : Form
//檔案名稱
private string _fileName;

private HighLightParameter _parameters;

//要HighLight的Code
private string CodeContent { get { return this.txtCode.Text; } }

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

private Color BackgroundColor { get { return this.btnBackground.BackColor; } }

public HighLightParameter Parameters { get { return _parameters; } }

#endregion

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

string outputFileName = String.Empty;

HighLightParameter parameter = new HighLightParameter()
_parameters = new HighLightParameter()
{
FileName = _fileName,
Content = CodeContent,
CodeType = _codeType,
HighLightStyle = CodeStyle,
ShowLineNumber = IsShowLineNumber
ShowLineNumber = IsShowLineNumber,
HighlightColor = BackgroundColor
};

try
{
outputFileName = generate.GenerateHighLightCode(parameter);
outputFileName = generate.GenerateHighLightCode(_parameters);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -214,7 +222,16 @@ private void SaveSetting()
defaultSettings.ShowLineNumber = this.cbx_lineNumber.Checked;
defaultSettings.SaveOnClipboard = this.cbx_Clipboard.Checked;
defaultSettings.HighLightStyle = this.cbx_style.SelectedIndex;
defaultSettings.BackgroundColor = this.btnBackground.BackColor;
defaultSettings.Save();
}

private void btnBackground_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
btnBackground.BackColor = colorDialog1.Color;
}
}
}
}
6 changes: 6 additions & 0 deletions NoteHighlightAddin/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>186, 17</value>
</metadata>
</root>
4 changes: 2 additions & 2 deletions NoteHighlightAddin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.1.*")]
[assembly: AssemblyFileVersion("2.1.*")]
[assembly: AssemblyVersion("2.2.*")]
[assembly: AssemblyFileVersion("2.2.*")]
15 changes: 15 additions & 0 deletions NoteHighlightAddin/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions NoteHighlightAddin/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
<Setting Name="HighLightStyle" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="BackgroundColor" Type="System.Drawing.Color" Scope="User">
<Value Profile="(Default)">White</Value>
</Setting>
</Settings>
</SettingsFile>
12 changes: 12 additions & 0 deletions NoteHighlightAddin/Properties/Settings1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9fff030

Please sign in to comment.