Skip to content

Commit

Permalink
Merge branch 'v3.7_dark_mode' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
elvirbrk committed Feb 9, 2021
2 parents 8388f2a + 80a80bc commit 4c44d51
Show file tree
Hide file tree
Showing 354 changed files with 14,400 additions and 7,711 deletions.
26 changes: 25 additions & 1 deletion NoteHighlightAddin/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ protected Application OneNoteApplication

private bool QuickStyle { get; set; }

private bool DarkMode { get; set; }

public AddIn()
{
}
Expand Down Expand Up @@ -151,6 +153,20 @@ public void cbQuickStyle_OnAction(IRibbonControl control, bool isPressed)
NoteHighlightForm.Properties.Settings.Default.Save();
}


public bool cbDarkMode_GetPressed(IRibbonControl control)
{
this.DarkMode = NoteHighlightForm.Properties.Settings.Default.DarkMode;
return this.DarkMode;
}

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

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

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

System.Windows.Forms.Application.Run(form);
//}
Expand Down Expand Up @@ -608,6 +624,14 @@ private XElement PrepareFormatedContent(string htmlContent, HighLightParameter p
defaultStyle = item.Substring(0, item.IndexOf(">") + 1);
//Sets language to Latin to disable spell check
defaultStyle = defaultStyle.Insert(defaultStyle.Length - 1, " lang=la");

if (this.DarkMode)
{
//Remove background-color element so that text would render with correct contrast in dark mode
int bcIndex = defaultStyle.IndexOf("background-color");
defaultStyle = defaultStyle.Remove(bcIndex, defaultStyle.IndexOf(';', bcIndex) - bcIndex +1);
}

item = item.Substring(item.IndexOf(">") + 1);
}

Expand Down
3 changes: 3 additions & 0 deletions NoteHighlightAddin/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
</setting>
<setting name="QuickStyle" serializeAs="String">
<value>False</value>
</setting>
<setting name="DarkMode" serializeAs="String">
<value>True</value>
</setting>
<setting name="Font" serializeAs="String">
<value>Courier New</value>
Expand Down
6 changes: 3 additions & 3 deletions NoteHighlightAddin/HtmlFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void CopyToClipboard(string htmlFragment, string title, Uri source

string header =
@"Format:HTML Format
Version:1.0
Version:0.9
StartHTML:<<<<<<<1
EndHTML:<<<<<<<2
StartFragment:<<<<<<<3
Expand Down Expand Up @@ -54,10 +54,10 @@ public static void CopyToClipboard(string htmlFragment, string title, Uri source
int fragmentStart = sb.Length;

sb.Append(htmlFragment);
int fragmentEnd = sb.Length;
int fragmentEnd = Encoding.UTF8.GetBytes(sb.ToString()).Length;

sb.Append(post);
int endHTML = sb.Length;
int endHTML = Encoding.UTF8.GetBytes(sb.ToString()).Length;

// Backpatch offsets
sb.Replace("<<<<<<<1", To8DigitString(startHTML));
Expand Down
15 changes: 14 additions & 1 deletion NoteHighlightAddin/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class MainForm : Form
private string _fileName;

private HighLightParameter _parameters;
private bool _darkMode;

//要HighLight的Code
private string CodeContent { get { return this.txtCode.Text; } }
Expand All @@ -48,21 +49,24 @@ public partial class MainForm : Form

private bool _quickStyle;

public bool DarkMode { get { return _darkMode; } }

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

#endregion

#region -- Constructor --

public MainForm(string codeType, string fileName, string selectedText, bool quickStyle)
public MainForm(string codeType, string fileName, string selectedText, bool quickStyle, bool darkMode)
{
_codeType = codeType;
_fileName = fileName;
InitializeComponent();
LoadThemes();
txtCode.Text = selectedText;
_quickStyle = quickStyle;
_darkMode = darkMode;

if (_quickStyle)
{
Expand Down Expand Up @@ -192,6 +196,15 @@ private void InsertToClipboard(string outputFileName)
string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
line = line.Replace(byteOrderMarkUtf8, "");

if (line.StartsWith("<pre") && this.DarkMode)
{

//Remove background-color element so that text would render with correct contrast in dark mode
int bcIndex = line.IndexOf("background-color");
line = line.Remove(bcIndex, line.IndexOf(';', bcIndex) - bcIndex + 1);
}


if (!line.StartsWith("</pre>"))
{
line = line.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").Replace("&apos;", "'") + "<br />";
Expand Down
Loading

0 comments on commit 4c44d51

Please sign in to comment.