Skip to content

Commit f8e884e

Browse files
committed
small optimizations
1 parent ca02f3b commit f8e884e

File tree

9 files changed

+102
-70
lines changed

9 files changed

+102
-70
lines changed

src/LogExpert.UI/Controls/BufferedDataGridView.Designer.cs

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LogExpert.UI/Controls/BufferedDataGridView.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public partial class BufferedDataGridView : DataGridView
1414
{
1515
#region Fields
1616

17-
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
17+
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
1818
private readonly Brush _brush;
1919

20-
private readonly Color _bubbleColor = Color.FromArgb(160, 250, 250, 00);
20+
private readonly Color _bubbleColor = Color.FromArgb(160, 250, 250, 0);
2121
private readonly Font _font = new("Arial", 10);
2222

2323
private readonly SortedList<int, BookmarkOverlay> _overlayList = [];
@@ -230,9 +230,11 @@ private void PaintOverlays (PaintEventArgs e)
230230

231231
base.OnPaint(args);
232232

233-
StringFormat format = new();
234-
format.LineAlignment = StringAlignment.Center;
235-
format.Alignment = StringAlignment.Near;
233+
StringFormat format = new()
234+
{
235+
LineAlignment = StringAlignment.Center,
236+
Alignment = StringAlignment.Near
237+
};
236238

237239
myBuffer.Graphics.SetClip(DisplayRectangle, CombineMode.Intersect);
238240

@@ -247,8 +249,7 @@ private void PaintOverlays (PaintEventArgs e)
247249
foreach (BookmarkOverlay overlay in _overlayList.Values)
248250
{
249251
SizeF textSize = myBuffer.Graphics.MeasureString(overlay.Bookmark.Text, _font, 300);
250-
Rectangle rectBubble = new(overlay.Position,
251-
new Size((int)textSize.Width, (int)textSize.Height));
252+
Rectangle rectBubble = new(overlay.Position, new Size((int)textSize.Width, (int)textSize.Height));
252253
rectBubble.Offset(60, -(rectBubble.Height + 40));
253254
rectBubble.Inflate(3, 3);
254255
rectBubble.Location += overlay.Bookmark.OverlayOffset;
@@ -264,7 +265,7 @@ private void PaintOverlays (PaintEventArgs e)
264265

265266
if (_logger.IsDebugEnabled)
266267
{
267-
_logger.Debug("ClipRgn: {0},{1},{2},{3}", myBuffer.Graphics.ClipBounds.Left, myBuffer.Graphics.ClipBounds.Top, myBuffer.Graphics.ClipBounds.Width, myBuffer.Graphics.ClipBounds.Height);
268+
_logger.Debug($"ClipRgn: {myBuffer.Graphics.ClipBounds.Left},{myBuffer.Graphics.ClipBounds.Top},{myBuffer.Graphics.ClipBounds.Width},{myBuffer.Graphics.ClipBounds.Height}");
268269
}
269270
}
270271
}

src/LogExpert.UI/Controls/LogWindow/LogWindow.designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LogExpert.UI/Controls/LogWindow/LogWindowPrivate.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ private void CreateDefaultViewStyle ()
6060
dataGridViewCellStyleMainGrid.ForeColor = SystemColors.ControlText;
6161
dataGridViewCellStyleMainGrid.SelectionBackColor = SystemColors.Highlight;
6262
dataGridViewCellStyleMainGrid.SelectionForeColor = SystemColors.HighlightText;
63+
64+
Color highlightColor = SystemColors.Highlight;
65+
//Color is smaller than 128, means its darker
66+
var isDark = (highlightColor.R * 0.2126) + (highlightColor.G * 0.7152) + (highlightColor.B * 0.0722) < 255 / 2;
67+
68+
if (isDark)
69+
{
70+
dataGridViewCellStyleMainGrid.SelectionForeColor = Color.White;
71+
}
72+
else
73+
{
74+
dataGridViewCellStyleMainGrid.SelectionForeColor = Color.Black;
75+
76+
}
77+
6378
dataGridViewCellStyleMainGrid.WrapMode = DataGridViewTriState.False;
6479
dataGridView.DefaultCellStyle = dataGridViewCellStyleMainGrid;
6580

@@ -69,6 +84,16 @@ private void CreateDefaultViewStyle ()
6984
dataGridViewCellStyleFilterGrid.ForeColor = SystemColors.ControlText;
7085
dataGridViewCellStyleFilterGrid.SelectionBackColor = SystemColors.Highlight;
7186
dataGridViewCellStyleFilterGrid.SelectionForeColor = SystemColors.HighlightText;
87+
88+
if (isDark)
89+
{
90+
dataGridViewCellStyleFilterGrid.SelectionForeColor = Color.White;
91+
}
92+
else
93+
{
94+
dataGridViewCellStyleFilterGrid.SelectionForeColor = Color.Black;
95+
}
96+
7297
dataGridViewCellStyleFilterGrid.WrapMode = DataGridViewTriState.False;
7398
filterGridView.DefaultCellStyle = dataGridViewCellStyleFilterGrid;
7499
}
@@ -1196,11 +1221,6 @@ private void PaintHighlightedCell (DataGridViewCellPaintingEventArgs e, Buffered
11961221
}
11971222
}
11981223

1199-
if (foreColor == Color.Black)
1200-
{
1201-
foreColor = ColorMode.ForeColor;
1202-
}
1203-
12041224
TextRenderer.DrawText(e.Graphics, matchWord, font, wordRect, foreColor, flags);
12051225

12061226
wordPos.Offset(wordSize.Width, 0);

src/LogExpert.UI/Controls/LogWindow/LogWindowPublic.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,13 @@ public IList<HighlightMatchEntry> FindHighlightMatches (ITextValue column)
558558
{
559559
GetHighlightEntryMatches(column, _currentHighlightGroup.HighlightEntryList, resultList);
560560
}
561+
561562
lock (_tempHighlightEntryList)
562563
{
563564
GetHighlightEntryMatches(column, _tempHighlightEntryList, resultList);
564565
}
565566
}
567+
566568
return resultList;
567569
}
568570

@@ -1193,6 +1195,7 @@ public void CopyMarkedLinesToTab ()
11931195
lineNumList.Add(row.Index);
11941196
}
11951197
}
1198+
11961199
lineNumList.Sort();
11971200
// create dummy FilterPipe for connecting line numbers to original window
11981201
// setting IsStopped to true prevents further filter processing
@@ -1390,6 +1393,7 @@ public int FindTimestampLine (int lineNum, DateTime timestamp, bool roundToSecon
13901393
GetTimestampForLineForward(ref foundLine, roundToSeconds); // fwd to next valid timestamp
13911394
return foundLine;
13921395
}
1396+
13931397
return -foundLine;
13941398
}
13951399

@@ -1403,6 +1407,7 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd
14031407
{
14041408
return lineNum;
14051409
}
1410+
14061411
if (timestamp < currentTimestamp)
14071412
{
14081413
//rangeStart = rangeStart;
@@ -1419,7 +1424,7 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd
14191424
return -lineNum;
14201425
}
14211426

1422-
lineNum = (rangeEnd - rangeStart) / 2 + rangeStart;
1427+
lineNum = ((rangeEnd - rangeStart) / 2) + rangeStart;
14231428
// prevent endless loop
14241429
if (rangeEnd - rangeStart < 2)
14251430
{
@@ -1428,12 +1433,12 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd
14281433
{
14291434
return rangeStart;
14301435
}
1436+
14311437
currentTimestamp = GetTimestampForLine(ref rangeEnd, roundToSeconds);
1432-
if (currentTimestamp.CompareTo(timestamp) == 0)
1433-
{
1434-
return rangeEnd;
1435-
}
1436-
return -lineNum;
1438+
1439+
return currentTimestamp.CompareTo(timestamp) == 0
1440+
? rangeEnd
1441+
: -lineNum;
14371442
}
14381443

14391444
return FindTimestampLine_Internal(lineNum, rangeStart, rangeEnd, timestamp, roundToSeconds);
@@ -1444,7 +1449,6 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd
14441449
* has no timestamp, the previous line will be checked until a
14451450
* timestamp is found.
14461451
*/
1447-
14481452
public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds)
14491453
{
14501454
lock (_currentColumnizerLock)
@@ -1453,7 +1457,8 @@ public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds)
14531457
{
14541458
return DateTime.MinValue;
14551459
}
1456-
_logger.Debug("GetTimestampForLine({0}) enter", lineNum);
1460+
1461+
_logger.Debug($"GetTimestampForLine({lineNum}) enter");
14571462
DateTime timeStamp = DateTime.MinValue;
14581463
var lookBack = false;
14591464
if (lineNum >= 0 && lineNum < dataGridView.RowCount)
@@ -1464,25 +1469,30 @@ public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds)
14641469
{
14651470
return DateTime.MinValue;
14661471
}
1472+
14671473
lookBack = true;
14681474
ILogLine logLine = _logFileReader.GetLogLine(lineNum);
14691475
if (logLine == null)
14701476
{
14711477
return DateTime.MinValue;
14721478
}
1479+
14731480
ColumnizerCallbackObject.LineNum = lineNum;
14741481
timeStamp = CurrentColumnizer.GetTimestamp(ColumnizerCallbackObject, logLine);
14751482
if (roundToSeconds)
14761483
{
14771484
timeStamp = timeStamp.Subtract(TimeSpan.FromMilliseconds(timeStamp.Millisecond));
14781485
}
1486+
14791487
lineNum--;
14801488
}
14811489
}
1490+
14821491
if (lookBack)
14831492
{
14841493
lineNum++;
14851494
}
1495+
14861496
_logger.Debug("GetTimestampForLine() leave with lineNum={0}", lineNum);
14871497
return timeStamp;
14881498
}
@@ -1493,7 +1503,6 @@ public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds)
14931503
* has no timestamp, the next line will be checked until a
14941504
* timestamp is found.
14951505
*/
1496-
14971506
public DateTime GetTimestampForLineForward (ref int lineNum, bool roundToSeconds)
14981507
{
14991508
lock (_currentColumnizerLock)

src/LogExpert.UI/Dialogs/BookmarkWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public BookmarkWindow ()
5050
public void ChangeTheme (Control.ControlCollection container)
5151
{
5252
#region ApplyColorToAllControls
53+
5354
foreach (Control component in container)
5455
{
5556
if (component.Controls != null && component.Controls.Count > 0)
@@ -65,6 +66,7 @@ public void ChangeTheme (Control.ControlCollection container)
6566
}
6667

6768
}
69+
6870
#endregion
6971

7072
#region DataGridView

src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPublic.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ public LogWindow.LogWindow AddFileTab (string givenFileName, bool isTempFile, st
7272

7373
EncodingOptions encodingOptions = new();
7474
FillDefaultEncodingFromSettings(encodingOptions);
75-
LogWindow.LogWindow logWindow = new(this, logFileName, isTempFile, forcePersistenceLoading, ConfigManager);
76-
77-
logWindow.GivenFileName = givenFileName;
75+
LogWindow.LogWindow logWindow = new(this, logFileName, isTempFile, forcePersistenceLoading, ConfigManager)
76+
{
77+
GivenFileName = givenFileName
78+
};
7879

7980
if (preProcessColumnizer != null)
8081
{

src/LogExpert.UI/Extensions/Forms/LineToolStripSeparatorExtension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
using LogExpert.Core.Config;
2-
31
using System.Runtime.Versioning;
42

3+
using LogExpert.Core.Config;
4+
55
namespace LogExpert.UI.Extensions.Forms;
66

77
[SupportedOSPlatform("windows")]
88
public class LineToolStripSeparatorExtension : ToolStripSeparator
99
{
10-
public LineToolStripSeparatorExtension()
10+
public LineToolStripSeparatorExtension ()
1111
{
1212
Paint += OnExtendedToolStripSeparatorPaint;
1313
}
1414

15-
private void OnExtendedToolStripSeparatorPaint(object sender, PaintEventArgs e)
15+
private void OnExtendedToolStripSeparatorPaint (object sender, PaintEventArgs e)
1616
{
1717
// Get the separator's width and height.
1818
var toolStripSeparator = (ToolStripSeparator)sender;

0 commit comments

Comments
 (0)