Skip to content

.net9 dark theme #12111

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

Merged
merged 3 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimenta
csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion

# WFO1000: A property should determine its property content serialization with the DesignerSerializationVisibilityAttribute, DefaultValueAttribute or the ShouldSerializeProperty method
# Silent for now, see https://github.com/dotnet/winforms/issues/12476
dotnet_diagnostic.WFO1000.severity = silent
dotnet_diagnostic.WFO1000.severity = silent

# WFO5001: Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
dotnet_diagnostic.WFO5001.severity = silent
10 changes: 7 additions & 3 deletions setup/installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,11 @@
<Component Id="Themes.light_plus.css" Guid="*">
<File Source="$(var.ArtifactsPublishPath)\Themes\light+.css" />
</Component>
<Component Id="Themes.highcontrast_dark.css" Guid="*">
<File Source="$(var.ArtifactsPublishPath)\Themes\highcontrast_dark.css" />
<Component Id="Themes.dark.css" Guid="*">
<File Source="$(var.ArtifactsPublishPath)\Themes\dark.css" />
</Component>
<Component Id="Themes.dark_plus.css" Guid="*">
<File Source="$(var.ArtifactsPublishPath)\Themes\dark+.css" />
</Component>
</DirectoryRef>
<DirectoryRef Id="PluginsDir">
Expand Down Expand Up @@ -606,8 +609,9 @@
<ComponentGroup Id="Component.Themes">
<ComponentRef Id="Themes.README.md" />
<ComponentRef Id="Themes.invariant.css" />
<ComponentRef Id="Themes.highcontrast_dark.css" />
<ComponentRef Id="Themes.light_plus.css" />
<ComponentRef Id="Themes.dark.css" />
<ComponentRef Id="Themes.dark_plus.css" />
</ComponentGroup>
<ComponentGroup Id="Component.Translation">
<ComponentRef Id="English.gif" />
Expand Down
7 changes: 7 additions & 0 deletions src/app/BugReporter/BugReportForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using GitExtensions.Extensibility.Translations;
using GitExtensions.Extensibility.Translations.Xliff;
using GitExtUtils.GitUI;
using GitExtUtils.GitUI.Theming;
using GitUI;
using Microsoft;
using ResourceManager;
Expand Down Expand Up @@ -126,6 +127,12 @@ public DialogResult ShowDialog(IWin32Window? owner, SerializableException except
return result;
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.FixVisualStyle();
}

protected override void OnShown(EventArgs e)
{
base.OnShown(e);
Expand Down
2 changes: 1 addition & 1 deletion src/app/GitExtUtils/GitUI/Theming/AppColorDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static class AppColorDefaults
{ AppColor.AnsiTerminalWhiteForeNormal, Color.FromArgb(0xbf, 0xbf, 0xbf) },
{ AppColor.AnsiTerminalWhiteBackNormal, Color.FromArgb(0xe0, 0xe0, 0xe0) },
{ AppColor.AnsiTerminalWhiteForeBold, Color.FromArgb(0xff, 0xff, 0xff) },
{ AppColor.AnsiTerminalWhiteBackBold, Color.FromArgb(0xff, 0xff, 0xff) }
{ AppColor.AnsiTerminalWhiteBackBold, Color.FromArgb(0xff, 0xff, 0xff) },
};

private static readonly Dictionary<string, Dictionary<AppColor, Color>> _variations = new()
Expand Down
2 changes: 1 addition & 1 deletion src/app/GitExtUtils/GitUI/Theming/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private Color GetSysColor(KnownColor name) =>
/// </summary>
private static IReadOnlyCollection<KnownColor> SysColorNames { get; } =
new HashSet<KnownColor>(
Enum.GetValues(typeof(KnownColor))
Enum.GetValues<KnownColor>()
.Cast<KnownColor>()
.Where(c => IsSystemColor(c)));

Expand Down
48 changes: 16 additions & 32 deletions src/app/GitExtUtils/GitUI/Theming/ThemeFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@ public static void FixVisualStyle(this Control container)
return;
}

container.DescendantsToFix<GroupBox>()
.ForEach(SetupGroupBox);
container.DescendantsToFix<DataGridView>()
.ForEach(SetupDataGridView);
container.DescendantsToFix<TreeView>()
.ForEach(SetupTreeView);
container.DescendantsToFix<ListBox>()
.ForEach(SetupListBox);
container.DescendantsToFix<TabControl>()
.ForEach(SetupTabControl);
container.DescendantsToFix<TextBoxBase>()
.ForEach(SetupTextBoxBase);
container.DescendantsToFix<ComboBox>()
.ForEach(SetupComboBox);
container.DescendantsToFix<LinkLabel>()
.ForEach(SetupLinkLabel);
container.DescendantsToFix<ToolStrip>()
.ForEach(SetupToolStrip);
container.DescendantsToFix<Button>()
.ForEach(SetupButton);
container.ContextMenusToFix()
.ForEach(SetupContextMenu);
}
Expand Down Expand Up @@ -71,32 +69,29 @@ private static void SetupTextBoxBase(TextBoxBase textBox)
private static void SetupToolStrip(ToolStrip strip)
{
strip.UseExtendedThemeAwareRenderer();
strip.Items.OfType<ToolStripLabel>()
.ForEach(SetupToolStripLabel);
}

private static void SetupContextMenu(ContextMenuStrip strip)
{
strip.UseExtendedThemeAwareRenderer();
}

private static void SetupToolStripLabel(ToolStripLabel label)
{
label.LinkColor = label.LinkColor.AdaptTextColor();
label.VisitedLinkColor = label.VisitedLinkColor.AdaptTextColor();
label.ActiveLinkColor = label.ActiveLinkColor.AdaptTextColor();
}

private static void SetupLinkLabel(this LinkLabel label)
{
label.LinkColor = label.LinkColor.AdaptTextColor();
label.VisitedLinkColor = label.VisitedLinkColor.AdaptTextColor();
label.ActiveLinkColor = label.ActiveLinkColor.AdaptTextColor();
}

private static void SetupGroupBox(this GroupBox box)
private static void SetupButton(this Button button)
{
box.TouchForeColor();
// .net9 fix for https://github.com/dotnet/winforms/issues/11949 (only supposed to occur for 100%)
if (Application.IsDarkModeEnabled && button.FlatStyle == FlatStyle.Standard)
{
// In addition to not setting the BackColor (TouchBackColor() will fix),
// FlatStyle.Standard buttons look ugly in dark mode
button.FlatStyle = FlatStyle.Flat;
}
}

private static void SetupTabControl(TabControl tabControl)
Expand All @@ -114,25 +109,14 @@ private static void SetupTabPage(TabPage page)
}
}

private static void SetupTreeView(TreeView view)
private static void SetupDataGridView(DataGridView view)
{
IntPtr unused = view.Handle; // force handle creation
view.TouchBackColor();
view.TouchForeColor();
view.LineColor = SystemColors.ControlDark;
view.EnableHeadersVisualStyles = false;
view.ColumnHeadersDefaultCellStyle.BackColor = view.ColumnHeadersDefaultCellStyle.BackColor;
}

private static void SetupListBox(ListBox view)
{
if (view.BorderStyle == BorderStyle.Fixed3D)
{
view.BorderStyle = BorderStyle.FixedSingle;
}
}

private static void SetupComboBox(this ComboBox menu)
private static void SetupTreeView(TreeView view)
{
menu.TouchBackColor();
}

private static void TouchBackColor(this Control c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using GitExtUtils.GitUI;
using GitExtUtils.GitUI.Theming;
using GitUI.Properties;
using GitUI.Theming;
using ResourceManager;

namespace GitUI.CommandsDialogs.BrowseDialog.DashboardControl
Expand Down Expand Up @@ -56,7 +55,7 @@ protected override void OnVisibleChanged(EventArgs e)

public void RefreshContent()
{
DashboardTheme selectedTheme = ThemeModule.IsDarkTheme ? DashboardTheme.Dark : DashboardTheme.Light;
DashboardTheme selectedTheme = Application.IsDarkModeEnabled ? DashboardTheme.Dark : DashboardTheme.Light;

InitDashboardLayout();
ApplyTheme();
Expand Down
7 changes: 7 additions & 0 deletions src/app/GitUI/CommandsDialogs/FormCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,13 @@ private CommitKind CommitKind
_commitKind = value;

modifyCommitMessageButton.Visible = _useFormCommitMessage && CommitKind is not (CommitKind.Normal or CommitKind.Amend);
modifyCommitMessageButton.ForeColor = Application.IsDarkModeEnabled ? SystemColors.ControlText : SystemColors.HotTrack;

bool messageCanBeChanged = _useFormCommitMessage && CommitKind is (CommitKind.Normal or CommitKind.Amend);
Message.Enabled = messageCanBeChanged;
commitMessageToolStripMenuItem.Enabled = messageCanBeChanged;
commitTemplatesToolStripMenuItem.Enabled = messageCanBeChanged;
Message.EvaluateForecolor();
}
}

Expand Down Expand Up @@ -348,6 +351,10 @@ public FormCommit(IGitUICommands commands, CommitKind commitKind = CommitKind.No

toolStripStatusBranchIcon.AdaptImageLightness();

// Change the link color
commitAuthorStatus.LinkColor = Application.IsDarkModeEnabled ? Color.CornflowerBlue : Color.FromArgb(0, 0, 0xff);
remoteNameLabel.LinkColor = Application.IsDarkModeEnabled ? Color.CornflowerBlue : Color.Blue;

splitLeft.Panel1.BackColor = OtherColors.PanelBorderColor;
splitLeft.Panel2.BackColor = OtherColors.PanelBorderColor;
splitRight.Panel1.BackColor = OtherColors.PanelBorderColor;
Expand Down
2 changes: 1 addition & 1 deletion src/app/GitUI/CommandsDialogs/FormRebase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void EnableButtons()
AcceptButton = btnSolveConflicts;
btnSolveConflicts.Focus();
btnSolveConflicts.Text = _solveConflictsText2.Text;
MergeToolPanel.BackColor = Color.Yellow.AdaptBackColor();
MergeToolPanel.BackColor = Application.IsDarkModeEnabled ? Color.FromArgb(136, 136, 0) : Color.Yellow.AdaptBackColor();
}
else if (Module.InTheMiddleOfRebase())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using GitCommands.Utils;
using GitExtUtils;
using GitExtUtils.GitUI;
using GitExtUtils.GitUI.Theming;
using GitUI.ScriptsEngine;
using Microsoft;
using ResourceManager;
Expand Down Expand Up @@ -177,7 +176,7 @@ public override void OnPageShown()
{
if (icon.Value is Bitmap bitmap)
{
EmbeddedIcons.Images.Add(icon.Key.ToString()!, bitmap.AdaptLightness());
EmbeddedIcons.Images.Add(icon.Key.ToString()!, bitmap);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/GitUI/Editor/Diff/AnsiEscapeUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using GitExtensions.Extensibility;
Expand All @@ -13,7 +12,7 @@ public partial class AnsiEscapeUtilities
{
[GeneratedRegex(@"\u001b\[((?<escNo>\d+)\s*[:;]?\s*)*m", RegexOptions.ExplicitCapture)]
private static partial Regex EscapeRegex();
private static readonly int _defaultForeColorId = ThemeModule.IsDarkTheme ? _whiteId : _blackId;
private static readonly int _defaultForeColorId = Application.IsDarkModeEnabled ? _whiteId : _blackId;

// Color code definitions
private const int _blackId = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/app/GitUI/Editor/FileViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using GitUI.CommandsDialogs;
using GitUI.CommandsDialogs.SettingsDialog.Pages;
using GitUI.Properties;
using GitUI.Theming;
using GitUI.UserControls;
using GitUIPluginInterfaces;
using ICSharpCode.TextEditor.Util;
Expand Down Expand Up @@ -436,7 +435,9 @@ public ArgumentString GetExtraDiffArguments(bool isRangeDiff = false, bool isCom
// Difftastic coloring is always used (AppSettings.UseGitColoring.Value is not used).
// Allow user to override with difftool command line options.
SetEnvironmentVariable("DFT_COLOR", "always");
SetEnvironmentVariable("DFT_BACKGROUND", ThemeModule.IsDarkTheme ? "dark" : "light");

// DFT_BACKGROUND="dark" applies bold-bold colors, "light" corresponds better with Git colors
SetEnvironmentVariable("DFT_BACKGROUND", "light");
SetEnvironmentVariable("DFT_SYNTAX_HIGHLIGHT", ShowSyntaxHighlightingInDiff ? "on" : "off");
int contextLines = ShowEntireFile ? 9000 : NumberOfContextLines;
SetEnvironmentVariable("DFT_CONTEXT", contextLines.ToString());
Expand Down
1 change: 0 additions & 1 deletion src/app/GitUI/Editor/GitHighlightingStrategyBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GitExtensions.Extensibility.Git;
using GitExtUtils.GitUI.Theming;
using ICSharpCode.TextEditor.Document;

namespace GitUI.Editor
Expand Down
15 changes: 7 additions & 8 deletions src/app/GitUI/Editor/RebaseTodoHighlightingStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GitExtensions.Extensibility.Git;
using GitExtUtils.GitUI.Theming;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;

Expand All @@ -18,15 +17,15 @@ internal sealed class RebaseTodoHighlightingStrategy : GitHighlightingStrategyBa
d, drop = remove commit
*/

private static readonly Dictionary<char, (string longForm, HighlightColor color, string[] options)> _commandByFirstChar = new()
private readonly Dictionary<char, (string longForm, HighlightColor color, string[] options)> _commandByFirstChar = new()
{
{ 'p', ("pick", new HighlightColor(nameof(SystemColors.InfoText), bold: true, italic: false), Array.Empty<string>()) },
{ 'r', ("reword", new HighlightColor(Color.Purple.AdaptTextColor(), bold: true, italic: false), Array.Empty<string>()) },
{ 'e', ("edit", new HighlightColor(Color.DarkGray.AdaptTextColor(), bold: true, italic: false), Array.Empty<string>()) },
{ 's', ("squash", new HighlightColor(Color.DarkBlue.AdaptTextColor(), bold: true, italic: false), Array.Empty<string>()) },
{ 'f', ("fixup", new HighlightColor(Color.LightCoral.AdaptTextColor(), bold: true, italic: false), new[] { "-C", "-c" }) },
{ 'r', ("reword", new HighlightColor(Application.IsDarkModeEnabled ? Color.MediumPurple : Color.Purple, bold: true, italic: false, adaptable: false), Array.Empty<string>()) },
{ 'e', ("edit", new HighlightColor(Application.IsDarkModeEnabled ? Color.LightGray : Color.DarkGray, bold: true, italic: false, adaptable: false), Array.Empty<string>()) },
{ 's', ("squash", new HighlightColor(Application.IsDarkModeEnabled ? Color.CornflowerBlue : Color.DarkBlue, bold: true, italic: false, adaptable: false), Array.Empty<string>()) },
{ 'f', ("fixup", new HighlightColor(Application.IsDarkModeEnabled ? Color.Coral : Color.LightCoral, bold: true, italic: false, adaptable: false), new[] { "-C", "-c" }) },
{ 'x', ("exec", new HighlightColor(nameof(SystemColors.GrayText), bold: true, italic: false), Array.Empty<string>()) },
{ 'd', ("drop", new HighlightColor(Color.Red.AdaptTextColor(), bold: true, italic: false), Array.Empty<string>()) }
{ 'd', ("drop", new HighlightColor(Application.IsDarkModeEnabled ? Color.IndianRed : Color.Red, bold: true, italic: false, adaptable: false), Array.Empty<string>()) }
};

public RebaseTodoHighlightingStrategy(IGitModule module)
Expand Down Expand Up @@ -57,7 +56,7 @@ private enum State
Id
}

private static bool TryHighlightInteractiveRebaseCommand(IDocument document, LineSegment line)
private bool TryHighlightInteractiveRebaseCommand(IDocument document, LineSegment line)
{
if (line.Length < 1)
{
Expand Down
6 changes: 0 additions & 6 deletions src/app/GitUI/GitUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,4 @@
</Content>
</ItemGroup>

<ItemGroup>
<Content Update="Themes\dark.css">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions src/app/GitUI/LeftPanel/BaseRevisionNode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using GitExtensions.Extensibility.Git;
using GitExtUtils.GitUI.Theming;
using GitUI.Properties;

namespace GitUI.LeftPanel
Expand All @@ -9,7 +8,7 @@ namespace GitUI.LeftPanel
internal abstract class BaseRevisionNode : Node
{
protected const char PathSeparator = '/';
private static readonly Color _invisibleForeColor = Color.Silver.AdaptTextColor();
private static readonly Color _invisibleForeColor = Application.IsDarkModeEnabled ? SystemColors.GrayText : Color.Silver;

protected BaseRevisionNode(Tree tree, string fullPath, bool visible)
: base(tree)
Expand Down
6 changes: 1 addition & 5 deletions src/app/GitUI/ScriptsEngine/SplitButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,17 @@ protected override void OnPaint(PaintEventArgs pevent)

Graphics g = pevent.Graphics;
Rectangle bounds = ClientRectangle;
pevent.Graphics.Clear(SystemColors.Window);

// draw the button background as according to the current state.
if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles)
{
Rectangle backgroundBounds = bounds;
backgroundBounds.Inflate(-1, -1);
ButtonRenderer.DrawButton(g, backgroundBounds, State);

// button renderer doesn't draw the black frame when themes are off
g.DrawRectangle(SystemPens.WindowFrame, 0, 0, bounds.Width - 1, bounds.Height - 1);
}
else
{
ButtonRenderer.DrawButton(g, bounds, State);
}

// calculate the current dropdown rectangle.
_dropDownRectangle = new Rectangle(bounds.Right - SplitSectionWidth, 0, SplitSectionWidth, bounds.Height);
Expand Down
11 changes: 11 additions & 0 deletions src/app/GitUI/SpellChecker/EditNetSpell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,23 @@ public override string Text
set
{
HideWatermark();
EvaluateForecolor();
TextBox.Text = value;
ShowWatermark();
OnTextAssigned();
}
}

public void EvaluateForecolor()
{
if (Application.IsDarkModeEnabled)
{
// In dark mode the background color is set to White, but still reported as SystemColors.Window (or adjusted)
// The Forecolor must be changed manually
TextBox.ForeColor = TextBox.Enabled ? SystemColors.WindowText : SystemColors.HighlightText;
}
}

private void OnTextAssigned()
{
TextAssigned?.Invoke(this, EventArgs.Empty);
Expand Down
Loading
Loading