Skip to content

Commit

Permalink
Merge branch 'vs2019'
Browse files Browse the repository at this point in the history
  • Loading branch information
elvirbrk committed Apr 14, 2019
2 parents 6e70bf1 + cc25937 commit 9ef64e6
Show file tree
Hide file tree
Showing 20 changed files with 730 additions and 218 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,4 @@ INSTALLER/*
/Helper/Helper2.snk
/img/ONOMSPY.zip
/img/onomspy.exe
/.vs/
14 changes: 11 additions & 3 deletions GenerateHighlightContent/GenerateHighLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class GenerateHighLight : IGenerateHighLight

public string FileName { get; set; }

public string Font { get; set; }

public int FontSize { get; set; }

/// <summary> highlight.exe 參數 設定於 App.config 的 HighLightSection 區塊 </summary>
private HighLightSection _section;

Expand Down Expand Up @@ -76,6 +80,8 @@ private void InitParameter(HighLightParameter parameter)
HighLightStyle = parameter.HighLightStyle;
ShowLineNumber = parameter.ShowLineNumber;
FileName = parameter.FileName;
Font = parameter.Font;
FontSize = parameter.FontSize;
}

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

string arguments = sb.ToString().TemplateSubstitute(new
{
inputFileName = String.Format("\"{0}\"",inputFileName),
outputFileName = String.Format("\"{0}\"",outputFileName),
inputFileName = String.Format("\"{0}\"", inputFileName),
outputFileName = String.Format("\"{0}\"", outputFileName),
codeType = CodeType,
highLightStyle = HighLightStyle
highLightStyle = HighLightStyle,
font = String.Format("\"{0}\"", Font),
fontSize = FontSize
});

return arguments;
Expand Down
4 changes: 4 additions & 0 deletions GenerateHighlightContent/IGenerateHighLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ public class HighLightParameter
public string FileName { get; set; }

public Color HighlightColor { get; set; }

public string Font { get; set; }

public int FontSize { get; set; }
}
}
4 changes: 2 additions & 2 deletions GenerateHighlightContent/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將組建和修訂編號
// 指定為預設值:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.6.0.0")]
[assembly: AssemblyFileVersion("2.6.0.0")]
[assembly: AssemblyVersion("2.7.0.0")]
[assembly: AssemblyFileVersion("2.7.0.0")]
80 changes: 72 additions & 8 deletions NoteHighlightAddin/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Web;
using GenerateHighlightContent;
using System.Configuration;
using System.Globalization;

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

Expand All @@ -45,7 +46,9 @@ protected Application OneNoteApplication

string tag;

public AddIn()
private bool QuickStyle { get; set; }

public AddIn()
{
}

Expand Down Expand Up @@ -135,7 +138,20 @@ public void OnStartupComplete(ref Array custom)
{
}

//public async Task AddInButtonClicked(IRibbonControl control)
public bool cbQuickStyle_GetPressed(IRibbonControl control)
{
this.QuickStyle = NoteHighlightForm.Properties.Settings.Default.QuickStyle;
return this.QuickStyle;
}

public void cbQuickStyle_OnAction(IRibbonControl control, bool isPressed)
{
this.QuickStyle = isPressed;
NoteHighlightForm.Properties.Settings.Default.QuickStyle = this.QuickStyle;
NoteHighlightForm.Properties.Settings.Default.Save();
}

//public async Task AddInButtonClicked(IRibbonControl control)
public void AddInButtonClicked(IRibbonControl control)
{
try
Expand Down Expand Up @@ -188,7 +204,7 @@ private void ShowForm()
}
}

MainForm form = new MainForm(tag, outFileName, selectedText);
MainForm form = new MainForm(tag, outFileName, selectedText, this.QuickStyle);

System.Windows.Forms.Application.Run(form);
//}
Expand All @@ -211,7 +227,36 @@ private void ShowForm()
}
}

public void SettingsButtonClicked(IRibbonControl control)
{
try
{

Thread t = new Thread(new ThreadStart(ShowSettingsForm));
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
catch (Exception e)
{
MessageBox.Show("Exception from SettingsButtonClicked: " + e.ToString());
}
}

private void ShowSettingsForm()
{
try
{

SettingsForm form = new SettingsForm();

System.Windows.Forms.Application.Run(form);

}
catch (Exception e)
{
MessageBox.Show("Exception from ShowForm: " + e.ToString());
}
}

/// <summary>
/// Specified in Ribbon.xml, this method returns the image to display on the ribbon button
Expand Down Expand Up @@ -267,6 +312,12 @@ private void InsertHighLightCodeToCurrentSide(string fileName, string pageXml, H
var page = InsertHighLightCode(htmlContent, position, parameters, outline, (new GenerateHighLight()).Config, selectedTextFormated, IsSelectedTextInline(pageXml));
page.Root.SetAttributeValue("ID", existingPageId);

//Bug fix - remove overflow value for Indents
foreach (var el in page.Descendants(ns + "Indent").Where(n => double.Parse(n.Attribute("indent").Value, new CultureInfo(page.Root.Attribute("lang").Value)) > 1000000))
{
el.Attribute("indent").Value = "0";
}

OneNoteApplication.UpdatePageContent(page.ToString(), DateTime.MinValue);
}
}
Expand Down Expand Up @@ -370,13 +421,21 @@ public string GetSelectedText(string pageXml, out bool selectedTextFormated)
attrPos = table.Descendants(ns + "Cell").LastOrDefault().Descendants(ns + "T").Where(n => n.Attribute("selected") != null && n.Attribute("selected").Value == "all");
selectedTextFormated = true;
}

int tabCount = 0;
int initTabCount = -1;
foreach (var line in attrPos)
{
var htmlDocument = new HtmlAgilityPack.HtmlDocument();
htmlDocument.LoadHtml(line.Value);

sb.AppendLine(HttpUtility.HtmlDecode(htmlDocument.DocumentNode.InnerText));

if (initTabCount == -1)
{
initTabCount = line.Ancestors().Elements(ns + "T").Count();
}
tabCount = line.Ancestors().Elements(ns + "T").Count() - initTabCount;


sb.AppendLine(new String('\t', tabCount) + HttpUtility.HtmlDecode(htmlDocument.DocumentNode.InnerText));
}
}
return sb.ToString().TrimEnd('\r','\n');
Expand Down Expand Up @@ -424,6 +483,10 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
else // Update exiting outline
{
update = true;

//Change outline width
outline.Element(ns + "Size").Attribute("width").Value = "1600";

if (selectedTextFormated)
{
outline.Descendants(ns + "Table").Where(n => n.Attribute("selected") != null &&
Expand Down Expand Up @@ -452,6 +515,7 @@ public XDocument InsertHighLightCode(string htmlContent, string[] position, High
{
outline.Descendants(ns + "T").Where(n => n.Attribute("selected") != null && n.Attribute("selected").Value == "all").FirstOrDefault().ReplaceWith(children.Descendants(ns + "Table").FirstOrDefault());
outline.Descendants(ns + "OE").Where(t => t.Elements(ns + "T").Any(n => n.Attribute("selected") != null && n.Attribute("selected").Value == "all")).Remove();
outline.Descendants(ns + "OEChildren").Where(n => n.HasElements == false && n.Attribute("selected") != null && (n.Attribute("selected").Value == "partial")).Remove();
}
}
}
Expand Down Expand Up @@ -497,7 +561,7 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
XElement children = new XElement(ns + "OEChildren");

XElement table = new XElement(ns + "Table");
table.Add(new XAttribute("bordersVisible", "false"));
table.Add(new XAttribute("bordersVisible", NoteHighlightForm.Properties.Settings.Default.ShowTableBorder));

XElement columns = new XElement(ns + "Columns");
XElement column1 = new XElement(ns + "Column");
Expand All @@ -523,7 +587,7 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
table.Add(columns);

Color color = parameters.HighlightColor;
string colorString = string.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
string colorString = color.A == 0 ? "none" : 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");
Expand Down
18 changes: 15 additions & 3 deletions NoteHighlightAddin/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="NoteHighLightForm.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.6.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
<section name="HighLightSection" type="GenerateHighlightContent.HighLightSection, GenerateHighlightContent, Version=2.7.0.0, Culture=neutral, PublicKeyToken=77d9ec1ac4fb0cdc"/>
</configSections>
<userSettings>
<NoteHighLightForm.Properties.Settings>
Expand All @@ -20,6 +20,18 @@
<setting name="BackgroundColor" serializeAs="String">
<value>White</value>
</setting>
<setting name="QuickStyle" serializeAs="String">
<value>False</value>
</setting>
<setting name="Font" serializeAs="String">
<value>Courier New</value>
</setting>
<setting name="FontSize" serializeAs="String">
<value>10</value>
</setting>
<setting name="ShowTableBorder" serializeAs="String">
<value>False</value>
</setting>
</NoteHighLightForm.Properties.Settings>
</userSettings>
<!--highlight CLI options Document:http://www.andre-simon.de/doku/highlight/en/highlight.html -->
Expand All @@ -38,8 +50,8 @@
<add Name="LineNumbers" Key="-l" Value="" Option="true"/>
<add Name="Style" Key="-s" Value="{highLightStyle}"/>
<add Name="LineNumberLength" Key="-j" Value="5"/>
<add Name="Font" Key="-k" Value="Courier New"/>
<add Name="FontSize" Key="-K" Value="10"/>
<add Name="Font" Key="-k" Value="{font}"/>
<add Name="FontSize" Key="-K" Value="{fontSize}"/>
<add Name="OutFormat" Key="-O" Value="html"/>
</OutputArguments>
</HighLightSection>
Expand Down
31 changes: 31 additions & 0 deletions NoteHighlightAddin/MainForm.Designer.cs

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

Loading

0 comments on commit 9ef64e6

Please sign in to comment.