Skip to content

Commit

Permalink
Merge pull request #252 from jrouzies-fr/Dark-Theme
Browse files Browse the repository at this point in the history
Dark theme V1
  • Loading branch information
Hirogen authored Jul 28, 2022
2 parents 6390095 + adbcd03 commit 059bae6
Show file tree
Hide file tree
Showing 24 changed files with 1,409 additions and 704 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LogExpert [![Build status](https://ci.appveyor.com/api/projects/status/hxwxyyxy81l4tee8/branch/master?svg=true)](https://ci.appveyor.com/project/Zarunbal/logexpert/branch/master)

Clone from https://logexpert.codeplex.com/
This is a clone from (no longer exists) https://logexpert.codeplex.com/

# Overview
LogExpert is a Windows tail program (a GUI replacement for the Unix tail command).
Expand All @@ -21,6 +21,7 @@ Summary of (most) features:
* Plugin API for more log file data sources
* Automatical determine columnizer with given file name and content (Experimental)
* Serilog.Formatting.Compact format support (Experimental)
* Portable (all options / settings saved in application startup directory)

# Download
Follow the [Link](https://github.com/zarunbal/LogExpert/releases/latest) and download the latest package. Just extract it where you want and execute the application or download the Setup and install it
Expand Down Expand Up @@ -56,3 +57,13 @@ Nuke.build Requirements
Please checkout the wiki for FAQ / HELP / Informations / Examples

https://github.com/zarunbal/LogExpert/wiki

## Credits
### Contributors

This project exists thanks to all the people who contribute.
<a href="https://github.com/zarunbal/LogExpert/graphs/contributors">
<img src="https://contrib.rocks/image?repo=zarunbal/LogExpert" />
</a>

Made with [contrib.rocks](https://contrib.rocks).
4 changes: 2 additions & 2 deletions src/LogExpert/Classes/PaintHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridV
}
else
{
Color bgColor = Color.White;
Color bgColor = LogExpert.Config.ColorMode.DockBackgroundColor;
if (!DebugOptions.disableWordHighlight)
{
if (entry != null)
Expand Down Expand Up @@ -311,7 +311,7 @@ private static void PaintHighlightedCell(ILogPaintContext logPaintCtx, DataGridV
HilightMatchEntry hme = new HilightMatchEntry();
hme.StartPos = 0;
hme.Length = column.FullValue.Length;
hme.HilightEntry = new HilightEntry(column.FullValue, groundEntry?.ForegroundColor ?? Color.FromKnownColor(KnownColor.Black), groundEntry?.BackgroundColor ?? Color.Empty, false);
hme.HilightEntry = new HilightEntry(column.FullValue, groundEntry?.ForegroundColor ?? LogExpert.Config.ColorMode.ForeColor, groundEntry?.BackgroundColor ?? Color.Empty, false);
matchList = MergeHighlightMatchEntries(matchList, hme);
}
}
Expand Down
115 changes: 115 additions & 0 deletions src/LogExpert/Config/ColorMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace LogExpert.Config
{
public static class ColorMode
{
// Bright Theme
// https://paletton.com/#uid=15-0u0k00sH00kJ0pq+00RL00RL
private static readonly Color BrightBookmarkDefaultSystemColor = SystemColors.Control; // Important: only supports SystemColors
private static readonly Color LessBrightBackgroundColor = Color.FromArgb(208, 205, 206);
private static readonly Color BrightBackgroundColor = Color.FromArgb(221, 221, 221);
private static readonly Color BrighterBackgroundColor = Color.FromArgb(253, 253, 253);
private static readonly Color BrightForeColor = Color.FromArgb(0, 0, 0);

// Dark Theme
// https://paletton.com/#uid=15-0u0k005U0670008J003Y003Y
private static readonly Color DarkBookmarkDefaultSystemColor = SystemColors.ControlDarkDark; // Important: only supports SystemColors
private static readonly Color LessLessDarkBackgroundColor = Color.FromArgb(90, 90, 90);
private static readonly Color LessDarkBackgroundColor = Color.FromArgb(67, 67, 67);
private static readonly Color DarkBackgroundColor = Color.FromArgb(45, 45, 45);
private static readonly Color DarkerBackgroundColor = Color.FromArgb(30, 30, 30);
private static readonly Color DarkForeColor = Color.FromArgb(255, 255, 255);

// Default
public static Color BackgroundColor = LessBrightBackgroundColor;
public static Color DockBackgroundColor = BrighterBackgroundColor;
public static Color BookmarksDefaultBackgroundColor = BrightBookmarkDefaultSystemColor;
public static Color ForeColor = BrightForeColor;
public static Color MenuBackgroundColor = BrighterBackgroundColor;
public static Color HoverMenuBackgroundColor = LessBrightBackgroundColor;
public static Color ActiveTabColor = BrighterBackgroundColor;
public static Color InactiveTabColor = LessBrightBackgroundColor;
public static Color TabsBackgroundStripColor = LessBrightBackgroundColor;


public static bool DarkModeEnabled = false;

public static void LoadColorMode()
{
var preferences = Config.ConfigManager.Settings.preferences;

if (preferences.darkMode)
{
SetDarkMode();
}
else
{
SetBrightMode();
}
}

private static void SetDarkMode()
{
BackgroundColor = DarkBackgroundColor;
ForeColor = DarkForeColor;
MenuBackgroundColor = DarkerBackgroundColor;
DockBackgroundColor = LessDarkBackgroundColor;
HoverMenuBackgroundColor = LessDarkBackgroundColor;
BookmarksDefaultBackgroundColor = DarkBookmarkDefaultSystemColor;
TabsBackgroundStripColor = LessDarkBackgroundColor;
ActiveTabColor = LessLessDarkBackgroundColor;
InactiveTabColor = LessDarkBackgroundColor;
DarkModeEnabled = true;
}

private static void SetBrightMode()
{
BackgroundColor = BrightBackgroundColor;
ForeColor = BrightForeColor;
MenuBackgroundColor = BrighterBackgroundColor;
DockBackgroundColor = BrighterBackgroundColor;
BookmarksDefaultBackgroundColor = BrightBookmarkDefaultSystemColor;
HoverMenuBackgroundColor = LessBrightBackgroundColor;
TabsBackgroundStripColor = BrighterBackgroundColor;
ActiveTabColor = BrighterBackgroundColor;
InactiveTabColor = LessBrightBackgroundColor;
DarkModeEnabled = false;
}

#region TitleBarDarkMode
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

private const int DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19;
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;

public static bool UseImmersiveDarkMode(IntPtr handle, bool enabled)
{

var attribute = DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1;
if (IsWindows10OrGreater(18985))
{
attribute = DWMWA_USE_IMMERSIVE_DARK_MODE;
}

int useImmersiveDarkMode = enabled ? 1 : 0;
return DwmSetWindowAttribute(handle, (int)attribute, ref useImmersiveDarkMode, sizeof(int)) == 0;

}

private static bool IsWindows10OrGreater(int build = -1)
{
return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= build;
}

#endregion TitleBarDarkMode

}
}
2 changes: 2 additions & 0 deletions src/LogExpert/Config/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Preferences

public bool askForClose = false;

public bool darkMode = false;

public int bufferCount = 100;

public List<ColumnizerMaskEntry> columnizerMaskList = new List<ColumnizerMaskEntry>();
Expand Down
125 changes: 115 additions & 10 deletions src/LogExpert/Controls/LogTabWindow/LogTabWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public partial class LogTabWindow : Form

public LogTabWindow(string[] fileNames, int instanceNumber, bool showInstanceNumbers)
{
InitializeComponent();
InitializeComponent();

ChangeTheme(Controls);

_startupFileNames = fileNames;
this._instanceNumber = instanceNumber;
this._showInstanceNumbers = showInstanceNumbers;
Expand All @@ -83,7 +86,7 @@ public LogTabWindow(string[] fileNames, int instanceNumber, bool showInstanceNum
HilightGroupList = ConfigManager.Settings.hilightGroupList;

Rectangle led = new Rectangle(0, 0, 8, 2);

for (int i = 0; i < _leds.Length; ++i)
{
_leds[i] = led;
Expand All @@ -97,27 +100,27 @@ public LogTabWindow(string[] fileNames, int instanceNumber, bool showInstanceNum
_ledBrushes[2] = new SolidBrush(Color.FromArgb(255, 0, 220, 0));
_ledBrushes[3] = new SolidBrush(Color.FromArgb(255, 0, 220, 0));
_ledBrushes[4] = new SolidBrush(Color.FromArgb(255, 0, 220, 0));

_offLedBrush = new SolidBrush(Color.FromArgb(grayAlpha, 160, 160, 160));

_dirtyLedBrush = new SolidBrush(Color.FromArgb(255, 220, 0, 00));

_tailLedBrush[0] = new SolidBrush(Color.FromArgb(255, 50, 100, 250)); // Follow tail: blue-ish
_tailLedBrush[1] = new SolidBrush(Color.FromArgb(grayAlpha, 160, 160, 160)); // Don't follow tail: gray
_tailLedBrush[2] = new SolidBrush(Color.FromArgb(255, 220, 220, 0)); // Stop follow tail (trigger): yellow-ish

_syncLedBrush = new SolidBrush(Color.FromArgb(255, 250, 145, 30));

CreateIcons();

_tabStringFormat.LineAlignment = StringAlignment.Center;
_tabStringFormat.Alignment = StringAlignment.Near;

ToolStripControlHost host = new ToolStripControlHost(checkBoxFollowTail);

host.Padding = new Padding(20, 0, 0, 0);
host.BackColor = Color.FromKnownColor(KnownColor.Transparent);

int index = buttonToolStrip.Items.IndexOfKey("toolStripButtonTail");

toolStripEncodingASCIIItem.Text = Encoding.ASCII.HeaderName;
Expand Down Expand Up @@ -151,6 +154,108 @@ public LogTabWindow(string[] fileNames, int instanceNumber, bool showInstanceNum

#endregion

#region ColorTheme
public void ChangeTheme(Control.ControlCollection container)
{
LogExpert.Config.ColorMode.LoadColorMode();
LogExpert.Config.ColorMode.UseImmersiveDarkMode(this.Handle, LogExpert.Config.ColorMode.DarkModeEnabled);

#region ApplyColorToAllControls
foreach (Control component in container)
{
if (component.Controls != null && component.Controls.Count > 0)
{
ChangeTheme(component.Controls);
component.BackColor = LogExpert.Config.ColorMode.BackgroundColor;
component.ForeColor = LogExpert.Config.ColorMode.ForeColor;
}
else
{
component.BackColor = LogExpert.Config.ColorMode.BackgroundColor;
component.ForeColor = LogExpert.Config.ColorMode.ForeColor;
}

if (component is MenuStrip)
{
var menu = (MenuStrip)component;

foreach (ToolStripMenuItem item in menu.Items)
{
item.ForeColor = LogExpert.Config.ColorMode.ForeColor;
item.BackColor = LogExpert.Config.ColorMode.BackgroundColor;

try
{
for(var x = 0; x< item.DropDownItems.Count; x++)
{
var children = item.DropDownItems[x];
children.ForeColor = LogExpert.Config.ColorMode.ForeColor;
children.BackColor = LogExpert.Config.ColorMode.MenuBackgroundColor;


if(children is ToolStripDropDownItem) {

for (var y = 0; y < ((ToolStripDropDownItem)children).DropDownItems.Count; y++)
{
var subChildren = ((ToolStripDropDownItem)children).DropDownItems[y];
subChildren.ForeColor = LogExpert.Config.ColorMode.ForeColor;
subChildren.BackColor = LogExpert.Config.ColorMode.MenuBackgroundColor;
}
}
}
}
catch (Exception ex)
{
_logger.Error(ex, "An error occured while applying style dynamically to all Controls under LogTabWindow:");
}
}
}
}
#endregion

// Colors for selected menus
mainMenuStrip.Renderer = new LogExpert.Extensions.ExtendedMenuStripRenderer();

// Dock special color
dockPanel.DockBackColor = LogExpert.Config.ColorMode.DockBackgroundColor;

// Remove toolstrip bottom border
buttonToolStrip.Renderer = new LogExpert.Extensions.ToolStripRendererExtension();

#region Tabs
tabContextMenuStrip.Renderer = new LogExpert.Extensions.ExtendedMenuStripRenderer();

// Tabs menu
for (var y = 0; y < tabContextMenuStrip.Items.Count; y++)
{
var item = tabContextMenuStrip.Items[y];
item.ForeColor = LogExpert.Config.ColorMode.ForeColor;
item.BackColor = LogExpert.Config.ColorMode.MenuBackgroundColor;
}

// Tabs line
dockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.StartColor = LogExpert.Config.ColorMode.TabsBackgroundStripColor;
dockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.EndColor = LogExpert.Config.ColorMode.TabsBackgroundStripColor;

dockPanel.Skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.StartColor = LogExpert.Config.ColorMode.TabsBackgroundStripColor;
dockPanel.Skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.EndColor = LogExpert.Config.ColorMode.TabsBackgroundStripColor;

// Tabs
dockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.StartColor = LogExpert.Config.ColorMode.ActiveTabColor;
dockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.EndColor = LogExpert.Config.ColorMode.ActiveTabColor;
dockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.TextColor = LogExpert.Config.ColorMode.ForeColor;

dockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.StartColor = LogExpert.Config.ColorMode.ActiveTabColor;
dockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.EndColor = LogExpert.Config.ColorMode.ActiveTabColor;
dockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.TextColor = LogExpert.Config.ColorMode.ForeColor;

dockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.StartColor = LogExpert.Config.ColorMode.InactiveTabColor;
dockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.EndColor = LogExpert.Config.ColorMode.InactiveTabColor;
dockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.TextColor = LogExpert.Config.ColorMode.ForeColor;
#endregion Tabs
}
#endregion

#region Delegates

private delegate void AddFileTabsDelegate(string[] fileNames);
Expand Down
Loading

0 comments on commit 059bae6

Please sign in to comment.