Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Mode Styling #1325

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
92 changes: 46 additions & 46 deletions Plugins/MsCrmTools.SampleTool/app.config
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.3.0.0" newVersion="5.3.0.0"/>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.3.0.0" newVersion="5.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.29.0.1078" newVersion="2.29.0.1078"/>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.29.0.1078" newVersion="2.29.0.1078" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Xrm.Tooling.Connector" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
<assemblyIdentity name="Microsoft.Xrm.Tooling.Connector" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="McTools.Xrm.Connection" publicKeyToken="96037217801d9658" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.2017.4.13" newVersion="1.2017.4.13"/>
<assemblyIdentity name="McTools.Xrm.Connection" publicKeyToken="96037217801d9658" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2017.4.13" newVersion="1.2017.4.13" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Xrm.Sdk" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/>
<assemblyIdentity name="Microsoft.Xrm.Sdk" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Web.XmlTransform" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.34420" newVersion="3.0.0.34420"/>
<assemblyIdentity name="Microsoft.Web.XmlTransform" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.34420" newVersion="3.0.0.34420" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Xrm.Tooling.CrmConnectControl" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
<assemblyIdentity name="Microsoft.Xrm.Tooling.CrmConnectControl" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3"/>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Frameworks" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.4.0.123" newVersion="6.4.0.123"/>
<assemblyIdentity name="NuGet.Frameworks" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.4.0.123" newVersion="6.4.0.123" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Versioning" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.4.0.123" newVersion="6.4.0.123"/>
<assemblyIdentity name="NuGet.Versioning" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.4.0.123" newVersion="6.4.0.123" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Common" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.9.1.11" newVersion="5.9.1.11"/>
<assemblyIdentity name="NuGet.Common" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.9.1.11" newVersion="5.9.1.11" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Packaging" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.4.0.123" newVersion="6.4.0.123"/>
<assemblyIdentity name="NuGet.Packaging" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.4.0.123" newVersion="6.4.0.123" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Pkcs" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
<assemblyIdentity name="System.Security.Cryptography.Pkcs" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Cng" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
<assemblyIdentity name="System.Security.Cryptography.Cng" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.ContentModel" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0"/>
<assemblyIdentity name="NuGet.ContentModel" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.RuntimeModel" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0"/>
<assemblyIdentity name="NuGet.RuntimeModel" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Packaging.Core.Types" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0"/>
<assemblyIdentity name="NuGet.Packaging.Core.Types" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.2" newVersion="7.0.0.2"/>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.2" newVersion="7.0.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.ProtectedData" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
<assemblyIdentity name="System.Security.Cryptography.ProtectedData" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration>
237 changes: 237 additions & 0 deletions XrmToolBox.Extensibility/CustomTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
using ScintillaNET;
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace XrmToolBox.Extensibility
{
public class CustomTheme
{
private static CustomTheme theme;

public CustomTheme()
{
}

public static CustomTheme Instance
{
get
{
if (theme == null)
{
theme = new CustomTheme();
}
return theme;
}
}

public Color Background1 { get; protected set; }
public Color Background2 { get; protected set; }
public Color Background3 { get; protected set; }
public Color Background4 { get; protected set; }
public Color Background5 { get; protected set; }
public Color ForeColor1 { get; protected set; }
public Color ForeColor2 { get; protected set; }
public Color ForeColor3 { get; protected set; }
public Color ForeColor4 { get; protected set; }
public Color ForeColor5 { get; protected set; }
public Color HighlightColor { get; protected set; }
public bool IsActive { get; private set; }
public ProfessionalColorTable MenuColorTable { get; protected set; }

public void ApplyTheme(Control control)
{
if (!IsActive) return;

UpdateChildControlsTheme(control);

foreach (var ts in control.Controls.OfType<ToolStrip>())
{
ts.Renderer = new ToolStripProfessionalRenderer(MenuColorTable);

UpdateDropdownItemsTheme(ts.Items);
}
}

public void SetTheme(CustomTheme customTheme)
{
theme = customTheme;
theme.IsActive = customTheme != null;
}

private void UpdateChildControlsTheme(Control control)
{
control.ForeColor = ForeColor1;
control.BackColor = Background1;

//Update plugins that have custom controls + extra logic
UpdateSql4CDSTheme(control);
UpdateFetchXmlBuilderTheme(control);
UpdatePluginRegistrationTheme(control);
//TODO - support more plugins here...

if (control is TextBox
|| control is ComboBox
|| control is RichTextBox
)
{
control.BackColor = Background2;
control.ForeColor = ForeColor2;
}
else if (control is LinkLabel ll)
{
ll.ActiveLinkColor = HighlightColor;
ll.DisabledLinkColor = ForeColor5;
ll.ForeColor = HighlightColor;
ll.LinkColor = HighlightColor;
}
else if (control is Button b)
{
if (b.FlatAppearance.BorderSize > 0)
{
b.BackColor = Background2;
b.ForeColor = ForeColor2;
b.FlatStyle = FlatStyle.Flat;
}
}

if (control is TextBox tb)
{
tb.BorderStyle = BorderStyle.FixedSingle;
}

if (control is RichTextBox rtb && rtb.ReadOnly)
{
control.BackColor = Background1;
control.ForeColor = ForeColor1;
}

foreach (Control childControl in control.Controls)
{
UpdateChildControlsTheme(childControl);
}
}

private void UpdateDropdownItemsTheme(ToolStripItemCollection items)
{
foreach (ToolStripItem item in items)
{
item.ForeColor = ForeColor1;
item.BackColor = Background1;

if (item is ToolStripMenuItem tsmi)
{
UpdateDropdownItemsTheme(tsmi.DropDownItems);
}

if (item is ToolStripTextBox tstb)
{
tstb.TextBox.BackColor = Background2;
tstb.TextBox.ForeColor = ForeColor2;
}

if (item is ToolStripComboBox tstc)
{
tstc.ComboBox.BackColor = Background2;
tstc.ComboBox.ForeColor = ForeColor2;
}

if (item is ToolStripDropDownButton tsddb)
{
UpdateDropdownItemsTheme(tsddb.DropDownItems);
}
}
}
//TODO: Use more properties from subclass (ex: 'DarkTheme')
private void UpdateSql4CDSTheme(Control control)
{
//No need to update theme if not in dark mode.
//TODO: More checks for other types of themes?
if (GetType() != typeof(DarkTheme))
{
return;
}

//Theme main editor
if (control is Scintilla scintilla)
{
var darkGrey = Background1;
var lightGrey = Color.FromArgb(255, 170, 170, 170);
var lightGreen = Color.FromArgb(255, 84, 198, 82);
var lightRed = Color.FromArgb(255, 235, 117, 120);
var lightPurple = Color.FromArgb(255, 200, 120, 255);
var lightBlueGreen = Color.FromArgb(255, 127, 219, 255);
var orange = Color.FromArgb(255, 214, 93, 14);

scintilla.StyleResetDefault();

scintilla.CaretForeColor = Color.White;
scintilla.CaretLineBackColor = darkGrey;

scintilla.Styles[Style.Default].BackColor = darkGrey;
scintilla.Styles[Style.Default].ForeColor = darkGrey;

scintilla.Styles[Style.LineNumber].ForeColor = lightGrey;
scintilla.Styles[Style.LineNumber].BackColor = darkGrey;

scintilla.Styles[Style.Sql.Default].BackColor = darkGrey;
scintilla.Styles[Style.Sql.Default].BackColor = darkGrey;

scintilla.Styles[Style.Sql.Comment].ForeColor = lightGreen;
scintilla.Styles[Style.Sql.Comment].BackColor = darkGrey;

scintilla.Styles[Style.Sql.CommentLine].ForeColor = lightGreen;
scintilla.Styles[Style.Sql.CommentLine].BackColor = darkGrey;

scintilla.Styles[Style.Sql.CommentLineDoc].ForeColor = lightGreen;
scintilla.Styles[Style.Sql.CommentLineDoc].BackColor = darkGrey;

scintilla.Styles[Style.Sql.Number].ForeColor = lightRed;
scintilla.Styles[Style.Sql.Number].BackColor = darkGrey;

scintilla.Styles[Style.Sql.Word].ForeColor = lightPurple;
scintilla.Styles[Style.Sql.Word].BackColor = darkGrey;

scintilla.Styles[Style.Sql.Word2].ForeColor = lightPurple;
scintilla.Styles[Style.Sql.Word2].BackColor = darkGrey;

scintilla.Styles[Style.Sql.Identifier].ForeColor = lightGrey;
scintilla.Styles[Style.Sql.Identifier].BackColor = darkGrey;

scintilla.Styles[Style.Sql.User1].ForeColor = lightGrey;
scintilla.Styles[Style.Sql.User1].BackColor = darkGrey;

scintilla.Styles[Style.Sql.User2].ForeColor = lightBlueGreen;
scintilla.Styles[Style.Sql.User2].BackColor = darkGrey;

scintilla.Styles[Style.Sql.String].ForeColor = orange;
scintilla.Styles[Style.Sql.String].BackColor = darkGrey;

scintilla.Styles[Style.Sql.Character].ForeColor = orange;
scintilla.Styles[Style.Sql.Character].BackColor = darkGrey;

scintilla.Styles[Style.Sql.Operator].ForeColor = lightBlueGreen;
scintilla.Styles[Style.Sql.Operator].BackColor = darkGrey;
}

//TODO: Theme result set window
}
private void UpdateFetchXmlBuilderTheme(Control control)
{
//TODO
if (control is Scintilla scintilla)
{
var lightGrey = Color.FromArgb(255, 170, 170, 170);
scintilla.Styles[Style.Xml.Attribute].BackColor = Background1;
scintilla.Styles[Style.Xml.Default].BackColor = Background1;
scintilla.Styles[Style.Xml.Other].BackColor = Background1;
scintilla.Styles[Style.Xml.Other].ForeColor = lightGrey;
}
}
private void UpdatePluginRegistrationTheme(Control control)
{
//TODO
}
}
}
Loading