diff --git a/src/LogExpert.Core/Interface/ILogWindow.cs b/src/LogExpert.Core/Interface/ILogWindow.cs index a0181219..c165b347 100644 --- a/src/LogExpert.Core/Interface/ILogWindow.cs +++ b/src/LogExpert.Core/Interface/ILogWindow.cs @@ -1,6 +1,5 @@ using LogExpert.Core.Classes.Log; using LogExpert.Core.Classes.Persister; -using LogExpert.Core.Entities; namespace LogExpert.Core.Interface; @@ -11,15 +10,17 @@ public interface ILogWindow ILogLine GetLine (int lineNum); + ILogLine GetLogLineWithWait (int lineNum); + //TODO Find a way to not use a referenced int (https://github.com/LogExperts/LogExpert/issues/404) - DateTime GetTimestampForLineForward (ref int lineNum, bool v); + DateTime GetTimestampForLineForward (ref int lineNum, bool roundToSeconds); //TODO Find a way to not use a referenced int (https://github.com/LogExperts/LogExpert/issues/404) - DateTime GetTimestampForLine (ref int lastLineNum, bool v); + DateTime GetTimestampForLine (ref int lastLineNum, bool roundToSeconds); - int FindTimestampLine_Internal (int lineNum1, int lineNum2, int lastLineNum, DateTime searchTimeStamp, bool v); + int FindTimestampLineInternal (int lineNum, int rangeStart, int rangeEnd, DateTime timestamp, bool roundToSeconds); - void SelectLine (int lineNum, bool v1, bool v2); + void SelectLine (int lineNum, bool triggerSyncCall, bool shouldScroll); PersistenceData GetPersistenceData (); diff --git a/src/LogExpert.UI/Controls/LogWindow/LogWindow.cs b/src/LogExpert.UI/Controls/LogWindow/LogWindow.cs index 0c8488a3..ba4eac84 100644 --- a/src/LogExpert.UI/Controls/LogWindow/LogWindow.cs +++ b/src/LogExpert.UI/Controls/LogWindow/LogWindow.cs @@ -119,7 +119,7 @@ internal partial class LogWindow : DockContent, ILogPaintContextUI, ILogView, IL private int _lineHeight; - internal LogfileReader _logFileReader; + private LogfileReader _logFileReader; private MultiFileOptions _multiFileOptions = new(); private bool _noSelectionUpdates; private PatternArgs _patternArgs = new(); @@ -339,6 +339,10 @@ public bool ShowBookmarkBubbles } } + public int CurrentLineNum => dataGridView.CurrentRow == null + ? -1 + : dataGridView.CurrentRow.Index; + public string FileName { get; private set; } public string SessionFileName { get; set; } @@ -408,6 +412,11 @@ public ILogLine GetLogLine (int lineNum) return _logFileReader.GetLogLine(lineNum); } + public ILogLine GetLogLineWithWait (int lineNum) + { + return _logFileReader.GetLogLineWithWait(lineNum).Result; + } + public Bookmark GetBookmarkForLine (int lineNum) { return _bookmarkProvider.GetBookmarkForLine(lineNum); @@ -551,9 +560,9 @@ internal void DumpBufferDiagnostic () } [SupportedOSPlatform("windows")] - void ILogWindow.SelectLine (int lineNum, bool v1, bool v2) + void ILogWindow.SelectLine (int lineNum, bool triggerSyncCall, bool shouldScroll) { - SelectLine(lineNum, v1, v2); + SelectLine(lineNum, triggerSyncCall, shouldScroll); } [SupportedOSPlatform("windows")] @@ -938,72 +947,7 @@ private void OnFilterSearchButtonClick (object sender, EventArgs e) private void OnFilterGridViewCellPainting (object sender, DataGridViewCellPaintingEventArgs e) { var gridView = (BufferedDataGridView)sender; - - if (e.RowIndex < 0 || e.ColumnIndex < 0 || _filterResultList.Count <= e.RowIndex) - { - e.Handled = false; - return; - } - - var lineNum = _filterResultList[e.RowIndex]; - var line = _logFileReader.GetLogLineWithWait(lineNum).Result; - - if (line != null) - { - var entry = FindFirstNoWordMatchHilightEntry(line); - e.Graphics.SetClip(e.CellBounds); - - if (e.State.HasFlag(DataGridViewElementStates.Selected)) - { - using var brush = PaintHelper.GetBrushForFocusedControl(gridView.Focused, e.CellStyle.SelectionBackColor); - e.Graphics.FillRectangle(brush, e.CellBounds); - } - else - { - e.CellStyle.BackColor = PaintHelper.GetBackColorFromHighlightEntry(entry); - e.PaintBackground(e.ClipBounds, false); - } - - if (DebugOptions.DisableWordHighlight) - { - e.PaintContent(e.CellBounds); - } - else - { - PaintCell(e, entry); - } - - if (e.ColumnIndex == 0) - { - if (_bookmarkProvider.IsBookmarkAtLine(lineNum)) - { - //This was the OLD rect, left for future Information - //(e.CellBounds.Left + 2, e.CellBounds.Top + 2, 6, 6); - var rect = e.CellBounds; - rect.Inflate(-2, -2); - using var brush = new SolidBrush(BookmarkColor); - e.Graphics.FillRectangle(brush, rect); - - var bookmark = _bookmarkProvider.GetBookmarkForLine(lineNum); - - if (bookmark.Text.Length > 0) - { - StringFormat format = new() - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }; - - using var brush2 = new SolidBrush(Color.FromArgb(255, 190, 100, 0)); - using var font = new Font("Verdana", Preferences.FontSize, FontStyle.Bold); - e.Graphics.DrawString("!", font, brush2, new RectangleF(rect.Left, rect.Top, rect.Width, rect.Height), format); - } - } - } - - e.Paint(e.CellBounds, DataGridViewPaintParts.Border); - e.Handled = true; - } + CellPainting(gridView.Focused, e.RowIndex, e.ColumnIndex, true, e); } [SupportedOSPlatform("windows")] @@ -3904,7 +3848,7 @@ private void ResetProgressBar () } [SupportedOSPlatform("windows")] - private void SelectLine (int line, bool triggerSyncCall, bool shouldScroll) + private void SelectLine (int lineNum, bool triggerSyncCall, bool shouldScroll) { try { @@ -3920,7 +3864,7 @@ private void SelectLine (int line, bool triggerSyncCall, bool shouldScroll) return; } - if (line == -1) + if (lineNum == -1) { // Hmm... is that experimental code from early days? MessageBox.Show(this, "Not found:", "Search result"); @@ -3928,16 +3872,16 @@ private void SelectLine (int line, bool triggerSyncCall, bool shouldScroll) } // Prevent ArgumentOutOfRangeException - if (line >= dataGridView.Rows.GetRowCount(DataGridViewElementStates.None)) + if (lineNum >= dataGridView.Rows.GetRowCount(DataGridViewElementStates.None)) { - line = dataGridView.Rows.GetRowCount(DataGridViewElementStates.None) - 1; + lineNum = dataGridView.Rows.GetRowCount(DataGridViewElementStates.None) - 1; } - dataGridView.Rows[line].Selected = true; + dataGridView.Rows[lineNum].Selected = true; if (shouldScroll) { - dataGridView.CurrentCell = dataGridView.Rows[line].Cells[0]; + dataGridView.CurrentCell = dataGridView.Rows[lineNum].Cells[0]; _ = dataGridView.Focus(); } } @@ -4732,12 +4676,7 @@ private bool IsFilterSearchDirty (FilterParams filterParams) return true; } - if (filterParams.IsCaseSensitive != filterCaseSensitiveCheckBox.Checked) - { - return true; - } - - return false; + return filterParams.IsCaseSensitive != filterCaseSensitiveCheckBox.Checked; } [SupportedOSPlatform("windows")] @@ -6374,14 +6313,19 @@ public IColumn GetCellValue (int rowIndex, int columnIndex) return Column.EmptyColumn; } - public void CellPainting (bool focused, int rowIndex, DataGridViewCellPaintingEventArgs e) + public void CellPainting (bool focused, int rowIndex, int columnIndex, bool isFilteredGridView, DataGridViewCellPaintingEventArgs e) { - if (rowIndex < 0 || e.ColumnIndex < 0) + if (rowIndex < 0 || columnIndex < 0 || (isFilteredGridView && _filterResultList.Count <= rowIndex)) { e.Handled = false; return; } + if (isFilteredGridView) + { + rowIndex = _filterResultList[rowIndex]; + } + var line = _logFileReader.GetLogLineWithWait(rowIndex).Result; if (line != null) @@ -6409,16 +6353,16 @@ public void CellPainting (bool focused, int rowIndex, DataGridViewCellPaintingEv PaintCell(e, entry); } - if (e.ColumnIndex == 0) + if (columnIndex == 0) { if (_bookmarkProvider.IsBookmarkAtLine(rowIndex)) { //keeping this comment, because it's the original code // = new Rectangle(e.CellBounds.Left + 2, e.CellBounds.Top + 2, 6, 6); - var r = e.CellBounds; - r.Inflate(-2, -2); + var rect = e.CellBounds; + rect.Inflate(-2, -2); using var brush = new SolidBrush(BookmarkColor); - e.Graphics.FillRectangle(brush, r); + e.Graphics.FillRectangle(brush, rect); var bookmark = _bookmarkProvider.GetBookmarkForLine(rowIndex); @@ -6430,9 +6374,13 @@ public void CellPainting (bool focused, int rowIndex, DataGridViewCellPaintingEv Alignment = StringAlignment.Center }; + //Todo Add this as a Settings Option + var fontName = isFilteredGridView ? "Verdana" : "Courier New"; + var stringToDraw = isFilteredGridView ? "!" : "i"; + using var brush2 = new SolidBrush(Color.FromArgb(255, 190, 100, 0)); //dark orange - using var font = new Font("Courier New", Preferences.FontSize, FontStyle.Bold); - e.Graphics.DrawString("i", font, brush2, new RectangleF(r.Left, r.Top, r.Width, r.Height), format); + using var font = new Font(fontName, Preferences.FontSize, FontStyle.Bold); + e.Graphics.DrawString(stringToDraw, font, brush2, new RectangleF(rect.Left, rect.Top, rect.Width, rect.Height), format); } } } @@ -6445,7 +6393,7 @@ public void CellPainting (bool focused, int rowIndex, DataGridViewCellPaintingEv public void OnDataGridViewCellPainting (object sender, DataGridViewCellPaintingEventArgs e) { var gridView = (BufferedDataGridView)sender; - CellPainting(gridView.Focused, e.RowIndex, e); + CellPainting(gridView.Focused, e.RowIndex, e.ColumnIndex, false, e); } /// @@ -6564,7 +6512,8 @@ public void GotoLine (int line) { SelectLine(dataGridView.RowCount - 1, false, true); } - dataGridView.Focus(); + + _ = dataGridView.Focus(); } } @@ -7335,8 +7284,7 @@ public bool ScrollToTimestampWorker (DateTime timestamp, bool roundToSeconds, bo public int FindTimestampLine (int lineNum, DateTime timestamp, bool roundToSeconds) { - var foundLine = - FindTimestampLine_Internal(lineNum, 0, dataGridView.RowCount - 1, timestamp, roundToSeconds); + var foundLine = FindTimestampLineInternal(lineNum, 0, dataGridView.RowCount - 1, timestamp, roundToSeconds); if (foundLine >= 0) { // go backwards to the first occurence of the hit @@ -7359,10 +7307,9 @@ public int FindTimestampLine (int lineNum, DateTime timestamp, bool roundToSecon return -foundLine; } - public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd, DateTime timestamp, - bool roundToSeconds) + public int FindTimestampLineInternal (int lineNum, int rangeStart, int rangeEnd, DateTime timestamp, bool roundToSeconds) { - _logger.Debug("FindTimestampLine_Internal(): timestamp={0}, lineNum={1}, rangeStart={2}, rangeEnd={3}", timestamp, lineNum, rangeStart, rangeEnd); + _logger.Debug($"FindTimestampLine_Internal(): timestamp={timestamp}, lineNum={lineNum}, rangeStart={rangeStart}, rangeEnd={rangeEnd}"); var refLine = lineNum; var currentTimestamp = GetTimestampForLine(ref refLine, roundToSeconds); if (currentTimestamp.CompareTo(timestamp) == 0) @@ -7403,7 +7350,7 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd : -lineNum; } - return FindTimestampLine_Internal(lineNum, rangeStart, rangeEnd, timestamp, roundToSeconds); + return FindTimestampLineInternal(lineNum, rangeStart, rangeEnd, timestamp, roundToSeconds); } /** @@ -7455,7 +7402,7 @@ public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds) lineNum++; } - _logger.Debug("GetTimestampForLine() leave with lineNum={0}", lineNum); + _logger.Debug($"GetTimestampForLine() leave with lineNum={lineNum}"); return timeStamp; } } @@ -7482,23 +7429,29 @@ public DateTime GetTimestampForLineForward (ref int lineNum, bool roundToSeconds { lookFwd = true; var logLine = _logFileReader.GetLogLine(lineNum); + if (logLine == null) { timeStamp = DateTime.MinValue; break; } + timeStamp = CurrentColumnizer.GetTimestamp(ColumnizerCallbackObject, logLine); + if (roundToSeconds) { timeStamp = timeStamp.Subtract(TimeSpan.FromMilliseconds(timeStamp.Millisecond)); } + lineNum++; } } + if (lookFwd) { lineNum--; } + return timeStamp; } } @@ -7515,48 +7468,31 @@ public void AppFocusGained () public ILogLine GetCurrentLine () { - if (dataGridView.CurrentRow != null && dataGridView.CurrentRow.Index != -1) - { - return _logFileReader.GetLogLine(dataGridView.CurrentRow.Index); - } - return null; + return dataGridView.CurrentRow != null && dataGridView.CurrentRow.Index != -1 + ? _logFileReader.GetLogLine(dataGridView.CurrentRow.Index) + : null; } public ILogLine GetLine (int lineNum) { - if (lineNum < 0 || _logFileReader == null || lineNum >= _logFileReader.LineCount) - { - return null; - } - return _logFileReader.GetLogLine(lineNum); - } - - public int GetCurrentLineNum () - { - if (dataGridView.CurrentRow == null) - { - return -1; - } - return dataGridView.CurrentRow.Index; + return lineNum < 0 || _logFileReader == null || lineNum >= _logFileReader.LineCount + ? null + : _logFileReader.GetLogLine(lineNum); } public int GetRealLineNum () { - var lineNum = GetCurrentLineNum(); - if (lineNum == -1) - { - return -1; - } - return _logFileReader.GetRealLineNumForVirtualLineNum(lineNum); + var lineNum = CurrentLineNum; + return lineNum == -1 + ? -1 + : _logFileReader.GetRealLineNumForVirtualLineNum(lineNum); } public ILogFileInfo GetCurrentFileInfo () { - if (dataGridView.CurrentRow != null && dataGridView.CurrentRow.Index != -1) - { - return _logFileReader.GetLogFileInfoForLine(dataGridView.CurrentRow.Index); - } - return null; + return dataGridView.CurrentRow != null && dataGridView.CurrentRow.Index != -1 + ? _logFileReader.GetLogFileInfoForLine(dataGridView.CurrentRow.Index) + : null; } /// diff --git a/src/LogExpert.UI/Controls/LogWindow/PatternWindow.cs b/src/LogExpert.UI/Controls/LogWindow/PatternWindow.cs index 94b5c5c4..7e784b6d 100644 --- a/src/LogExpert.UI/Controls/LogWindow/PatternWindow.cs +++ b/src/LogExpert.UI/Controls/LogWindow/PatternWindow.cs @@ -245,7 +245,7 @@ private void OnPatternHitsDataGridViewCellPainting (object sender, DataGridViewC { var gridView = (BufferedDataGridView)sender; var rowIndex = GetLineForHitGrid(e.RowIndex); - _logWindow.CellPainting(gridView.Focused, rowIndex, e); + _logWindow.CellPainting(gridView.Focused, rowIndex, e.ColumnIndex, false, e); } } @@ -314,7 +314,7 @@ private void OnContentDataGridViewCellPainting (object sender, DataGridViewCellP var gridView = (BufferedDataGridView)sender; var rowIndex = GetLineForContentGrid(e.RowIndex); - _logWindow.CellPainting(gridView.Focused, rowIndex, e); + _logWindow.CellPainting(gridView.Focused, rowIndex, e.ColumnIndex, false, e); } private void OnContentDataGridViewCellMouseDoubleClick (object sender, DataGridViewCellMouseEventArgs e) diff --git a/src/LogExpert.UI/Controls/LogWindow/TimeSpreadCalculator.cs b/src/LogExpert.UI/Controls/LogWindow/TimeSpreadCalculator.cs index 9c91fce3..ab326b5d 100644 --- a/src/LogExpert.UI/Controls/LogWindow/TimeSpreadCalculator.cs +++ b/src/LogExpert.UI/Controls/LogWindow/TimeSpreadCalculator.cs @@ -306,7 +306,7 @@ private void DoCalc_via_Time () while (searchTimeStamp.CompareTo(_endTimestamp) <= 0) { - lineNum = _logWindow.FindTimestampLine_Internal(lineNum, lineNum, lastLineNum, searchTimeStamp, false); + lineNum = _logWindow.FindTimestampLineInternal(lineNum, lineNum, lastLineNum, searchTimeStamp, false); if (lineNum < 0) { lineNum = -lineNum; diff --git a/src/LogExpert.UI/Dialogs/BookmarkWindow.cs b/src/LogExpert.UI/Dialogs/BookmarkWindow.cs index a78c6c49..6b08cef7 100644 --- a/src/LogExpert.UI/Dialogs/BookmarkWindow.cs +++ b/src/LogExpert.UI/Dialogs/BookmarkWindow.cs @@ -324,10 +324,10 @@ private void OnBoomarkDataGridViewCellPainting (object sender, DataGridViewCellP // { // CommentPainting(this.bookmarkDataGridView, lineNum, e); // } - { - // else - PaintHelper.CellPainting(_logPaintContext, bookmarkDataGridView, lineNum, e); - } + //{ + // else + PaintHelper.CellPainting(_logPaintContext, bookmarkDataGridView.Focused, lineNum, e.ColumnIndex, e); + //} } catch (Exception ex) { diff --git a/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindow.cs b/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindow.cs index b27cd020..1d305985 100644 --- a/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindow.cs +++ b/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindow.cs @@ -2108,7 +2108,7 @@ private void OnSelectFilterToolStripMenuItemClick (object sender, EventArgs e) return; } - CurrentLogWindow.ColumnizerCallbackObject.LineNum = CurrentLogWindow.GetCurrentLineNum(); + CurrentLogWindow.ColumnizerCallbackObject.LineNum = CurrentLogWindow.CurrentLineNum; FilterSelectorForm form = new(PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers, CurrentLogWindow.CurrentColumnizer, CurrentLogWindow.ColumnizerCallbackObject, ConfigManager) { Owner = this, diff --git a/src/LogExpert.UI/Entities/PaintHelper.cs b/src/LogExpert.UI/Entities/PaintHelper.cs index ed0c2283..b58b26a4 100644 --- a/src/LogExpert.UI/Entities/PaintHelper.cs +++ b/src/LogExpert.UI/Entities/PaintHelper.cs @@ -22,9 +22,9 @@ internal static class PaintHelper #region Public methods [SupportedOSPlatform("windows")] - public static void CellPainting (ILogPaintContextUI logPaintCtx, BufferedDataGridView gridView, int rowIndex, DataGridViewCellPaintingEventArgs e) + public static void CellPainting (ILogPaintContextUI logPaintCtx, bool focused, int rowIndex, int columnIndex, DataGridViewCellPaintingEventArgs e) { - if (rowIndex < 0 || e.ColumnIndex < 0) + if (rowIndex < 0 || columnIndex < 0) { e.Handled = false; return; @@ -39,7 +39,7 @@ public static void CellPainting (ILogPaintContextUI logPaintCtx, BufferedDataGri if (e.State.HasFlag(DataGridViewElementStates.Selected)) { - using var brush = GetBrushForFocusedControl(gridView.Focused, e.CellStyle.SelectionBackColor); + using var brush = GetBrushForFocusedControl(focused, e.CellStyle.SelectionBackColor); e.Graphics.FillRectangle(brush, e.CellBounds); } else @@ -54,7 +54,7 @@ public static void CellPainting (ILogPaintContextUI logPaintCtx, BufferedDataGri } else { - PaintCell(logPaintCtx, e, gridView, false, entry); + PaintCell(logPaintCtx, e, entry); } if (e.ColumnIndex == 0) @@ -229,6 +229,7 @@ public static Color GetForeColorBasedOnBackColor (Color backColor) return isSelectionBackColorDark ? Color.White : Color.Black; } + //TODO Make this configurable => this should close https://github.com/LogExperts/LogExpert/issues/85 [SupportedOSPlatform("windows")] public static DataGridViewCellStyle GetDataGridViewCellStyle () { @@ -244,6 +245,7 @@ public static DataGridViewCellStyle GetDataGridViewCellStyle () }; } + //TODO Make this configurable => this should close https://github.com/LogExperts/LogExpert/issues/85 [SupportedOSPlatform("windows")] public static DataGridViewCellStyle GetDataGridDefaultRowStyle () { @@ -313,13 +315,13 @@ private static int GetBorderSize (DataGridViewAdvancedCellBorderStyle borderStyl #region Private Methods [SupportedOSPlatform("windows")] - private static void PaintCell (ILogPaintContextUI logPaintCtx, DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, bool noBackgroundFill, HighlightEntry groundEntry) + private static void PaintCell (ILogPaintContextUI logPaintCtx, DataGridViewCellPaintingEventArgs e, HighlightEntry groundEntry) { - PaintHighlightedCell(logPaintCtx, e, gridView, noBackgroundFill, groundEntry); + PaintHighlightedCell(logPaintCtx, e, groundEntry); } [SupportedOSPlatform("windows")] - private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, bool noBackgroundFill, HighlightEntry groundEntry) + private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGridViewCellPaintingEventArgs e, HighlightEntry groundEntry) { //TODO Refactor if possible since Column is ITextValue var value = e.Value ?? string.Empty; @@ -428,14 +430,14 @@ private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGr } else { - if (!noBackgroundFill && bgBrush != null && !matchEntry.HighlightEntry.NoBackground) + if (bgBrush != null && !matchEntry.HighlightEntry.NoBackground) { e.Graphics.FillRectangle(bgBrush, wordRect); } + } TextRenderer.DrawText(e.Graphics, matchWord, font, wordRect, foreColor, flags); - wordPos.Offset(wordSize.Width, 0); } }