Browse Source

feat: themeable HighlightingManager (#46)

* The default environment is set as static, so it can be
updated by GitExtensions with theme colors.
Any overrides in the actual themes would still be overriding the default
environment colors (the theme overrides were recently removed though).

* Make it possible to set colors as adaptable, to control if they should
be adapted for the themes or not.
Highlight colors hardcoded in the interface or in .xshd files
(unless they are system colors)
should generally be adapted, but colors in themes are likely to be
set to the intended color.
pull/48/head
Gerhard Olsson 6 months ago
committed by GitHub
parent
commit
1cb6d9c201
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 26
      Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs
  2. 4
      Project/Src/Document/HighlightingStrategy/HighlightBackground.cs
  3. 14
      Project/Src/Document/HighlightingStrategy/HighlightColor.cs
  4. 4
      Project/Src/Document/HighlightingStrategy/HighlightingManager.cs
  5. 2
      Project/Src/Document/LineManager/LineSegment.cs

26
Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs

@ -34,22 +34,32 @@ namespace ICSharpCode.TextEditor.Document
// Span state variables
protected bool inSpan;
public DefaultHighlightingStrategy() : this("Default")
{
}
// Default environment, can be overridden
public static readonly DefaultHighlightingStrategy Default = new();
public DefaultHighlightingStrategy(string name)
{
Name = name;
DigitColor = new HighlightColor(SystemColors.WindowText, bold: false, italic: false);
DefaultTextColor = new HighlightColor(SystemColors.WindowText, bold: false, italic: false);
environmentColors = Default.environmentColors;
DigitColor = Default.DigitColor;
DefaultTextColor = Default.DefaultTextColor;
}
private DefaultHighlightingStrategy() {}
static DefaultHighlightingStrategy()
{
Default.Name = "Default";
Default.DigitColor = new HighlightColor(nameof(SystemColors.WindowText), bold: false, italic: false);
Default.DefaultTextColor = new HighlightColor(nameof(SystemColors.WindowText), bold: false, italic: false);
// set small 'default color environment'
environmentColors = new Dictionary<string, HighlightColor>
// colors that are not system colors will be adapted to the theme
Default.environmentColors = new Dictionary<string, HighlightColor>
{
["Default"] = new HighlightBackground(nameof(SystemColors.WindowText), nameof(SystemColors.Window), bold: false, italic: false),
["Selection"] = new HighlightColor(SystemColors.WindowText, Color.FromArgb(0xc3, 0xc3, 0xff), bold: false, italic: false),
["Selection"] = new HighlightColor(SystemColors.WindowText, Color.FromArgb(0xc3, 0xc3, 0xff), bold: false, italic: false, adaptable: true),
["VRuler"] = new HighlightColor(nameof(SystemColors.ControlLight), nameof(SystemColors.Window), bold: false, italic: false),
["InvalidLines"] = new HighlightColor(Color.FromArgb(0xB6, 0xB6, 0xC0), bold: false, italic: false),
["CaretMarker"] = new HighlightColor(nameof(SystemColors.MenuBar), bold: false, italic: false),
@ -284,7 +294,7 @@ namespace ICSharpCode.TextEditor.Document
public void SetColorFor(string name, HighlightColor color)
{
if (name == "Default")
DefaultTextColor = new HighlightColor(color.Color, color.Bold, color.Italic);
DefaultTextColor = new HighlightColor(color.Color, color.Bold, color.Italic, adaptable: color.Adaptable);
environmentColors[name] = color;
}

4
Project/Src/Document/HighlightingStrategy/HighlightBackground.cs

@ -27,10 +27,6 @@ namespace ICSharpCode.TextEditor.Document
/// <summary>
/// Creates a new instance of <see cref="HighlightBackground" />
/// </summary>
public HighlightBackground(Color color, Color backgroundcolor, bool bold, bool italic) : base(color, backgroundcolor, bold, italic)
{
}
public HighlightBackground(string systemColor, string systemBackgroundColor, bool bold, bool italic) : base(systemColor, systemBackgroundColor, bold, italic)
{
}

14
Project/Src/Document/HighlightingStrategy/HighlightColor.cs

@ -117,6 +117,7 @@ namespace ICSharpCode.TextEditor.Document
Italic = original.Italic;
HasForeground = original.HasForeground;
HasBackground = original.HasBackground;
Adaptable = original.Adaptable;
Color = color;
BackgroundColor = backColor;
}
@ -124,18 +125,19 @@ namespace ICSharpCode.TextEditor.Document
/// <summary>
/// Creates a new instance of <see cref="HighlightColor" />
/// </summary>
public HighlightColor(Color color, bool bold, bool italic)
public HighlightColor(Color color, bool bold, bool italic, bool adaptable = true)
{
HasForeground = true;
Color = color;
Bold = bold;
Italic = italic;
Adaptable = adaptable;
}
/// <summary>
/// Creates a new instance of <see cref="HighlightColor" />
/// </summary>
public HighlightColor(Color color, Color backgroundcolor, bool bold, bool italic)
public HighlightColor(Color color, Color backgroundcolor, bool bold, bool italic, bool adaptable = true)
{
HasForeground = true;
HasBackground = true;
@ -143,6 +145,7 @@ namespace ICSharpCode.TextEditor.Document
BackgroundColor = backgroundcolor;
Bold = bold;
Italic = italic;
Adaptable = adaptable;
}
/// <summary>
@ -158,6 +161,7 @@ namespace ICSharpCode.TextEditor.Document
Bold = bold;
Italic = italic;
Adaptable = false;
}
/// <summary>
@ -171,6 +175,7 @@ namespace ICSharpCode.TextEditor.Document
Bold = bold;
Italic = italic;
Adaptable = false;
}
public bool HasForeground { get; }
@ -197,6 +202,11 @@ namespace ICSharpCode.TextEditor.Document
/// </value>
public Color Color { get; }
/// <value>
/// If the color should be adpted to the theme or if it is absolute
/// </value>
public bool Adaptable { get; } = true;
/// <value>
/// The font used
/// </value>

4
Project/Src/Document/HighlightingStrategy/HighlightingManager.cs

@ -74,7 +74,7 @@ namespace ICSharpCode.TextEditor.Document
private void CreateDefaultHighlightingStrategy()
{
var defaultHighlightingStrategy = new DefaultHighlightingStrategy();
var defaultHighlightingStrategy = DefaultHighlightingStrategy.Default;
defaultHighlightingStrategy.Extensions = new string[] { };
defaultHighlightingStrategy.Rules.Add(new HighlightRuleSet());
HighlightingDefinitions["Default"] = defaultHighlightingStrategy;
@ -144,4 +144,4 @@ namespace ICSharpCode.TextEditor.Document
public event EventHandler ReloadSyntaxHighlighting;
}
}
}

2
Project/Src/Document/LineManager/LineSegment.cs

@ -74,7 +74,7 @@ namespace ICSharpCode.TextEditor.Document
}
}
return new HighlightColor(SystemColors.WindowText, bold: false, italic: false);
return new HighlightColor(nameof(SystemColors.WindowText), bold: false, italic: false);
}
/// <summary>

Loading…
Cancel
Save