Skip to content

Commit 5c05a50

Browse files
committed
review comments
1 parent 32eeda0 commit 5c05a50

4 files changed

Lines changed: 45 additions & 89 deletions

File tree

src/ColumnizerLib/ITextValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace LogExpert;
1+
namespace LogExpert;
22

33
public interface ITextValue
44
{

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,6 @@ private void MeasureItem (object sender, MeasureItemEventArgs e)
22672267
[SupportedOSPlatform("windows")]
22682268
private void CreateDefaultViewStyle ()
22692269
{
2270-
22712270
dataGridView.DefaultCellStyle = PaintHelper.GetDataGridViewCellStyle();
22722271
filterGridView.DefaultCellStyle = PaintHelper.GetDataGridViewCellStyle();
22732272
dataGridView.RowsDefaultCellStyle = PaintHelper.GetDataGridDefaultRowStyle();
@@ -3206,14 +3205,9 @@ private void SetColumnizerInternal (ILogLineColumnizer columnizer)
32063205

32073206
if (_logFileReader != null)
32083207
{
3209-
if (CurrentColumnizer is IPreProcessColumnizer columnizer1)
3210-
{
3211-
_logFileReader.PreProcessColumnizer = columnizer1;
3212-
}
3213-
else
3214-
{
3215-
_logFileReader.PreProcessColumnizer = null;
3216-
}
3208+
_logFileReader.PreProcessColumnizer = CurrentColumnizer is IPreProcessColumnizer columnizer1
3209+
? columnizer1
3210+
: null;
32173211
}
32183212

32193213
// always reload when choosing XML columnizers
@@ -3413,18 +3407,18 @@ private void PaintHighlightedCell (DataGridViewCellPaintingEventArgs e, Highligh
34133407
Rectangle wordRect = new(wordPos, wordSize);
34143408

34153409
var foreColor = matchEntry.HighlightEntry.ForegroundColor;
3416-
if (!e.State.HasFlag(DataGridViewElementStates.Selected))
3410+
if (e.State.HasFlag(DataGridViewElementStates.Selected))
34173411
{
3418-
if (bgBrush != null && !matchEntry.HighlightEntry.NoBackground)
3412+
if (foreColor.Equals(Color.Black))
34193413
{
3420-
e.Graphics.FillRectangle(bgBrush, wordRect);
3414+
foreColor = Color.White;
34213415
}
34223416
}
34233417
else
34243418
{
3425-
if (foreColor.Equals(Color.Black))
3419+
if (bgBrush != null && !matchEntry.HighlightEntry.NoBackground)
34263420
{
3427-
foreColor = Color.White;
3421+
e.Graphics.FillRectangle(bgBrush, wordRect);
34283422
}
34293423
}
34303424

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,23 @@ private void OnHighlightListBoxDrawItem (object sender, DrawItemEventArgs e)
413413
var entry = (HighlightEntry)listBoxHighlight.Items[e.Index];
414414
Rectangle rectangle = new(0, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
415415

416-
var selected = e.State.HasFlag(DrawItemState.Selected);
417-
var forgroundColor = selected
418-
? PaintHelper.GetForeColorBasedOnBackColor(entry.ForegroundColor)
419-
: entry.ForegroundColor;
416+
SolidBrush foregroundBrush;
420417

421-
if (!selected)
418+
if (e.State.HasFlag(DrawItemState.Selected))
422419
{
423-
e.Graphics.FillRectangle(new SolidBrush(entry.BackgroundColor), rectangle);
420+
foregroundBrush = new SolidBrush(PaintHelper.GetForeColorBasedOnBackColor(entry.ForegroundColor));
421+
}
422+
else
423+
{
424+
using var backgroundBrush = new SolidBrush(entry.BackgroundColor);
425+
e.Graphics.FillRectangle(backgroundBrush, rectangle);
426+
foregroundBrush = new SolidBrush(entry.ForegroundColor);
424427
}
425428

426-
e.Graphics.DrawString(entry.SearchText, e.Font, new SolidBrush(forgroundColor), new PointF(rectangle.Left, rectangle.Top));
429+
using (foregroundBrush)
430+
{
431+
e.Graphics.DrawString(entry.SearchText, e.Font, foregroundBrush, new PointF(rectangle.Left, rectangle.Top));
432+
}
427433

428434
e.DrawFocusRectangle();
429435
}

src/LogExpert.UI/Entities/PaintHelper.cs

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,7 @@ public static void CellPainting (ILogPaintContextUI logPaintCtx, BufferedDataGri
9090

9191
public static Color GetBackColorFromHighlightEntry (HighlightEntry? entry)
9292
{
93-
var bgColor = Color.White;
94-
95-
if (!DebugOptions.DisableWordHighlight)
96-
{
97-
if (entry != null)
98-
{
99-
bgColor = entry.BackgroundColor;
100-
}
101-
}
102-
else
103-
{
104-
if (entry != null)
105-
{
106-
bgColor = entry.BackgroundColor;
107-
}
108-
}
109-
110-
return bgColor;
93+
return entry?.BackgroundColor ?? Color.White;
11194
}
11295

11396
[SupportedOSPlatform("windows")]
@@ -305,52 +288,24 @@ public static void ApplyDataGridViewPrefs (BufferedDataGridView dataGridView, bo
305288
}
306289

307290
[SupportedOSPlatform("windows")]
308-
public static Rectangle BorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
291+
public static Rectangle BorderWidths (DataGridViewAdvancedBorderStyle style)
309292
{
310-
Rectangle rect = new()
311-
{
312-
X = advancedBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.None
313-
? 0
314-
: 1
315-
};
316-
317-
if (advancedBorderStyle.Left is DataGridViewAdvancedCellBorderStyle.OutsetDouble or DataGridViewAdvancedCellBorderStyle.InsetDouble)
318-
{
319-
rect.X++;
320-
}
321-
322-
rect.Y = advancedBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.None
323-
? 0
324-
: 1;
325-
326-
if (advancedBorderStyle.Top is DataGridViewAdvancedCellBorderStyle.OutsetDouble or DataGridViewAdvancedCellBorderStyle.InsetDouble)
327-
{
328-
rect.Y++;
329-
}
330-
331-
rect.Width = advancedBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.None
332-
? 0
333-
: 1;
334-
335-
if (advancedBorderStyle.Right is DataGridViewAdvancedCellBorderStyle.OutsetDouble or DataGridViewAdvancedCellBorderStyle.InsetDouble)
336-
{
337-
rect.Width++;
338-
}
339-
340-
rect.Height = advancedBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.None
341-
? 0
342-
: 1;
293+
return new Rectangle(
294+
GetBorderSize(style.Left),
295+
GetBorderSize(style.Top),
296+
GetBorderSize(style.Right),
297+
GetBorderSize(style.Bottom));
298+
}
343299

344-
if (advancedBorderStyle.Bottom is DataGridViewAdvancedCellBorderStyle.OutsetDouble or
345-
DataGridViewAdvancedCellBorderStyle.InsetDouble)
300+
[SupportedOSPlatform("windows")]
301+
private static int GetBorderSize (DataGridViewAdvancedCellBorderStyle borderStyle)
302+
{
303+
return borderStyle switch
346304
{
347-
rect.Height++;
348-
}
349-
350-
//rect.Width += this.owningColumn.DividerWidth;
351-
//rect.Height += this.owningRow.DividerHeight;
352-
353-
return rect;
305+
DataGridViewAdvancedCellBorderStyle.None => 0,
306+
DataGridViewAdvancedCellBorderStyle.InsetDouble or DataGridViewAdvancedCellBorderStyle.OutsetDouble => 2,
307+
_ => 1
308+
};
354309
}
355310

356311
#endregion
@@ -366,9 +321,10 @@ private static void PaintCell (ILogPaintContextUI logPaintCtx, DataGridViewCellP
366321
[SupportedOSPlatform("windows")]
367322
private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, bool noBackgroundFill, HighlightEntry groundEntry)
368323
{
324+
//TODO Refactor if possible since Column is ITextValue
369325
var value = e.Value ?? string.Empty;
370326

371-
var matchList = logPaintCtx.FindHighlightMatches(value as ILogLine);
327+
var matchList = logPaintCtx.FindHighlightMatches(value as ITextValue);
372328
// too many entries per line seem to cause problems with the GDI
373329
while (matchList.Count > 50)
374330
{
@@ -463,18 +419,18 @@ private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGr
463419
Rectangle wordRect = new(wordPos, wordSize);
464420

465421
var foreColor = matchEntry.HighlightEntry.ForegroundColor;
466-
if ((e.State & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected)
422+
if (e.State.HasFlag(DataGridViewElementStates.Selected))
467423
{
468-
if (!noBackgroundFill && bgBrush != null && !matchEntry.HighlightEntry.NoBackground)
424+
if (foreColor.Equals(Color.Black))
469425
{
470-
e.Graphics.FillRectangle(bgBrush, wordRect);
426+
foreColor = Color.White;
471427
}
472428
}
473429
else
474430
{
475-
if (foreColor.Equals(Color.Black))
431+
if (!noBackgroundFill && bgBrush != null && !matchEntry.HighlightEntry.NoBackground)
476432
{
477-
foreColor = Color.White;
433+
e.Graphics.FillRectangle(bgBrush, wordRect);
478434
}
479435
}
480436

0 commit comments

Comments
 (0)