diff --git a/src/LogExpert.Core/Classes/Highlight/HighlightMatchEntry.cs b/src/LogExpert.Core/Classes/Highlight/HighlightMatchEntry.cs new file mode 100644 index 00000000..91c38160 --- /dev/null +++ b/src/LogExpert.Core/Classes/Highlight/HighlightMatchEntry.cs @@ -0,0 +1,26 @@ +namespace LogExpert.Core.Classes.Highlight; + +/// +/// Class for storing word-wise highlight matches. Used for colouring different matches on one line. +/// +public class HighlightMatchEntry +{ + #region Properties + + public HighlightEntry HighlightEntry { get; set; } + + public int StartPos { get; set; } + + public int Length { get; set; } + + #endregion + + #region Public methods + + public override string ToString () + { + return $"{HighlightEntry.SearchText}/{StartPos}/{Length}"; + } + + #endregion +} \ No newline at end of file diff --git a/src/LogExpert.Core/Classes/Highlight/HilightMatchEntry.cs b/src/LogExpert.Core/Classes/Highlight/HilightMatchEntry.cs deleted file mode 100644 index 1052ac4b..00000000 --- a/src/LogExpert.Core/Classes/Highlight/HilightMatchEntry.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace LogExpert.Core.Classes.Highlight; - -/// -/// Class for storing word-wise hilight matches. Used for colouring different matches on one line. -/// -public class HilightMatchEntry -{ - #region Properties - - public HighlightEntry HilightEntry { get; set; } - - public int StartPos { get; set; } - - public int Length { get; set; } - - #endregion - - #region Public methods - - public override string ToString() - { - return $"{HilightEntry.SearchText}/{StartPos}/{Length}"; - } - - #endregion -} \ No newline at end of file diff --git a/src/LogExpert.Core/Config/ColorMode.cs b/src/LogExpert.Core/Config/ColorMode.cs index b8297b95..02a0c876 100644 --- a/src/LogExpert.Core/Config/ColorMode.cs +++ b/src/LogExpert.Core/Config/ColorMode.cs @@ -1,5 +1,4 @@ -using System.Drawing; -using System.Runtime.InteropServices; +using System.Drawing; namespace LogExpert.Core.Config; @@ -10,8 +9,8 @@ public static class ColorMode 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); + private static readonly Color BrighterBackgroundColor = Color.White; + private static readonly Color BrightForeColor = Color.Black; // Dark Theme // https://paletton.com/#uid=15-0u0k005U0670008J003Y003Y @@ -20,7 +19,7 @@ public static class ColorMode 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); + private static readonly Color DarkForeColor = Color.White; // Default public static Color BackgroundColor = BrightBackgroundColor; @@ -35,7 +34,7 @@ public static class ColorMode public static bool DarkModeEnabled; - public static void LoadColorMode(bool darkMode) + public static void LoadColorMode (bool darkMode) { if (darkMode) { @@ -47,7 +46,7 @@ public static void LoadColorMode(bool darkMode) } } - private static void SetDarkMode() + private static void SetDarkMode () { BackgroundColor = DarkBackgroundColor; ForeColor = DarkForeColor; @@ -61,7 +60,7 @@ private static void SetDarkMode() DarkModeEnabled = true; } - private static void SetBrightMode() + private static void SetBrightMode () { BackgroundColor = BrightBackgroundColor; ForeColor = BrightForeColor; diff --git a/src/LogExpert.Core/Interface/ISharedToolWindow.cs b/src/LogExpert.Core/Interface/ISharedToolWindow.cs index 1d2a80e8..6c091cae 100644 --- a/src/LogExpert.Core/Interface/ISharedToolWindow.cs +++ b/src/LogExpert.Core/Interface/ISharedToolWindow.cs @@ -1,4 +1,4 @@ -using LogExpert.Core.Config; +using LogExpert.Core.Config; namespace LogExpert.Core.Interface; @@ -15,16 +15,16 @@ public interface ISharedToolWindow /// Called when a file becomes the active file (e.g. when user selects a tab). /// /// - void SetCurrentFile(IFileViewContext ctx); + void SetCurrentFile (IFileViewContext ctx); /// /// Called whenever the current file has been changed. /// - void FileChanged(); + void FileChanged (); - void SetColumnizer(ILogLineColumnizer columnizer); + void SetColumnizer (ILogLineColumnizer columnizer); - void PreferencesChanged(Preferences newPreferences, bool isLoadTime, SettingsFlags flags); + void PreferencesChanged (string fontName, float fontSize, bool setLastColumnWidth, int lastColumnWidth, SettingsFlags flags); #endregion } \ No newline at end of file diff --git a/src/LogExpert.UI/Controls/BufferedDataGridView.Designer.cs b/src/LogExpert.UI/Controls/BufferedDataGridView.Designer.cs index 694fce0a..f4908a0f 100644 --- a/src/LogExpert.UI/Controls/BufferedDataGridView.Designer.cs +++ b/src/LogExpert.UI/Controls/BufferedDataGridView.Designer.cs @@ -1,35 +1,35 @@ -namespace LogExpert.Dialogs; +namespace LogExpert.Dialogs; partial class BufferedDataGridView { -/// -/// Required designer variable. -/// -private System.ComponentModel.IContainer components = null; + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; -/// -/// Clean up any resources being used. -/// -/// true if managed resources should be disposed; otherwise, false. -protected override void Dispose(bool disposing) -{ - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); -} + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } -#region Component Designer generated code + #region Component Designer generated code -/// -/// Required method for Designer support - do not modify -/// the contents of this method with the code editor. -/// -private void InitializeComponent() -{ - components = new System.ComponentModel.Container(); -} + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } -#endregion -} + #endregion +} \ No newline at end of file diff --git a/src/LogExpert.UI/Controls/BufferedDataGridView.cs b/src/LogExpert.UI/Controls/BufferedDataGridView.cs index 83dd2575..cc249ece 100644 --- a/src/LogExpert.UI/Controls/BufferedDataGridView.cs +++ b/src/LogExpert.UI/Controls/BufferedDataGridView.cs @@ -14,10 +14,10 @@ internal partial class BufferedDataGridView : DataGridView { #region Fields - private static readonly ILogger _logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); private readonly Brush _brush; - private readonly Color _bubbleColor = Color.FromArgb(160, 250, 250, 00); + private readonly Color _bubbleColor = Color.FromArgb(160, 250, 250, 0); private readonly Font _font = new("Arial", 10); private readonly SortedList _overlayList = []; @@ -230,9 +230,11 @@ private void PaintOverlays (PaintEventArgs e) base.OnPaint(args); - StringFormat format = new(); - format.LineAlignment = StringAlignment.Center; - format.Alignment = StringAlignment.Near; + StringFormat format = new() + { + LineAlignment = StringAlignment.Center, + Alignment = StringAlignment.Near + }; myBuffer.Graphics.SetClip(DisplayRectangle, CombineMode.Intersect); @@ -247,8 +249,7 @@ private void PaintOverlays (PaintEventArgs e) foreach (BookmarkOverlay overlay in _overlayList.Values) { SizeF textSize = myBuffer.Graphics.MeasureString(overlay.Bookmark.Text, _font, 300); - Rectangle rectBubble = new(overlay.Position, - new Size((int)textSize.Width, (int)textSize.Height)); + Rectangle rectBubble = new(overlay.Position, new Size((int)textSize.Width, (int)textSize.Height)); rectBubble.Offset(60, -(rectBubble.Height + 40)); rectBubble.Inflate(3, 3); rectBubble.Location += overlay.Bookmark.OverlayOffset; @@ -264,7 +265,7 @@ private void PaintOverlays (PaintEventArgs e) if (_logger.IsDebugEnabled) { - _logger.Debug("ClipRgn: {0},{1},{2},{3}", myBuffer.Graphics.ClipBounds.Left, myBuffer.Graphics.ClipBounds.Top, myBuffer.Graphics.ClipBounds.Width, myBuffer.Graphics.ClipBounds.Height); + _logger.Debug($"ClipRgn: {myBuffer.Graphics.ClipBounds.Left},{myBuffer.Graphics.ClipBounds.Top},{myBuffer.Graphics.ClipBounds.Width},{myBuffer.Graphics.ClipBounds.Height}"); } } } diff --git a/src/LogExpert.UI/Controls/LogWindow/LogWindow.cs b/src/LogExpert.UI/Controls/LogWindow/LogWindow.cs index b1d52dbb..c593387e 100644 --- a/src/LogExpert.UI/Controls/LogWindow/LogWindow.cs +++ b/src/LogExpert.UI/Controls/LogWindow/LogWindow.cs @@ -32,14 +32,14 @@ internal partial class LogWindow : DockContent, ILogPaintContextUI, ILogView, IL private const int SPREAD_MAX = 99; private const int PROGRESS_BAR_MODULO = 1000; private const int FILTER_ADVANCED_SPLITTER_DISTANCE = 150; - private static readonly ILogger _logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); private readonly Image _advancedButtonImage; private readonly object _bookmarkLock = new(); private readonly BookmarkDataProvider _bookmarkProvider = new(); - private readonly IList _cancelHandlerList = new List(); + private readonly IList _cancelHandlerList = []; private readonly object _currentColumnizerLock = new(); @@ -47,7 +47,7 @@ internal partial class LogWindow : DockContent, ILogPaintContextUI, ILogView, IL private readonly EventWaitHandle _externaLoadingFinishedEvent = new ManualResetEvent(false); - private readonly IList _filterPipeList = new List(); + private readonly IList _filterPipeList = []; private readonly Dictionary _freezeStateMap = []; private readonly GuiStateArgs _guiStateArgs = new(); @@ -141,10 +141,11 @@ public LogWindow (LogTabWindow.LogTabWindow parent, string fileName, bool isTemp { SuspendLayout(); + //HighDPI Functionality must be called before all UI Elements are initialized, to make sure they work as intended AutoScaleDimensions = new SizeF(96F, 96F); AutoScaleMode = AutoScaleMode.Dpi; - InitializeComponent(); //TODO: Move this to be the first line of the constructor? + InitializeComponent(); CreateDefaultViewStyle(); @@ -210,15 +211,9 @@ public LogWindow (LogTabWindow.LogTabWindow parent, string fileName, bool isTemp _timeShiftSyncTask = new Task(SyncTimestampDisplayWorker, cts.Token); _timeShiftSyncTask.Start(); - //_timeShiftSyncThread = new Thread(SyncTimestampDisplayWorker); - //_timeShiftSyncThread.IsBackground = true; - //_timeShiftSyncThread.Start(); _logEventHandlerTask = new Task(LogEventWorker, cts.Token); _logEventHandlerTask.Start(); - //_logEventHandlerThread = new Thread(LogEventWorker); - //_logEventHandlerThread.IsBackground = true; - //_logEventHandlerThread.Start(); //this.filterUpdateThread = new Thread(new ThreadStart(this.FilterUpdateWorker)); //this.filterUpdateThread.Start(); @@ -355,7 +350,7 @@ public void ChangeTheme (Control.ControlCollection container) for (var y = 0; y < filterContextMenuStrip.Items.Count; y++) { - var item = filterContextMenuStrip.Items[y]; + ToolStripItem item = filterContextMenuStrip.Items[y]; item.ForeColor = ColorMode.ForeColor; item.BackColor = ColorMode.MenuBackgroundColor; } @@ -482,18 +477,9 @@ public bool IsMultiFile internal FilterPipe FilterPipe { get; set; } - public string Title - { - get - { - if (IsTempFile) - { - return TempTitleName; - } - - return FileName; - } - } + public string Title => IsTempFile + ? TempTitleName + : FileName; public ColumnizerCallback ColumnizerCallbackObject { get; } @@ -501,7 +487,7 @@ public string Title public string ForcedPersistenceFileName { get; set; } - public Preferences Preferences => ConfigManager.Settings.Preferences; + public Preferences Preferences => _parentLogTabWin.Preferences; public string GivenFileName { get; set; } @@ -601,11 +587,13 @@ internal void ChangeMultifileMask () internal void ToggleColumnFinder (bool show, bool setFocus) { _guiStateArgs.ColumnFinderVisible = show; + if (show) { columnComboBox.AutoCompleteMode = AutoCompleteMode.Suggest; columnComboBox.AutoCompleteSource = AutoCompleteSource.CustomSource; columnComboBox.AutoCompleteCustomSource = [.. CurrentColumnizer.GetColumnNames()]; + if (setFocus) { columnComboBox.Focus(); diff --git a/src/LogExpert.UI/Controls/LogWindow/LogWindow.designer.cs b/src/LogExpert.UI/Controls/LogWindow/LogWindow.designer.cs index 82822995..27d15a90 100644 --- a/src/LogExpert.UI/Controls/LogWindow/LogWindow.designer.cs +++ b/src/LogExpert.UI/Controls/LogWindow/LogWindow.designer.cs @@ -1,4 +1,4 @@ -using LogExpert.Dialogs; +using LogExpert.Dialogs; using LogExpert.UI.Extensions.Forms; using System; using System.Drawing; diff --git a/src/LogExpert.UI/Controls/LogWindow/LogWindowEventHandlers.cs b/src/LogExpert.UI/Controls/LogWindow/LogWindowEventHandlers.cs index 40d1647c..2b8e367a 100644 --- a/src/LogExpert.UI/Controls/LogWindow/LogWindowEventHandlers.cs +++ b/src/LogExpert.UI/Controls/LogWindow/LogWindowEventHandlers.cs @@ -104,7 +104,12 @@ protected void OnDeRegisterCancelHandler (IBackgroundProcessCancelHandler handle [SupportedOSPlatform("windows")] private void OnLogWindowLoad (object sender, EventArgs e) { - PreferencesChanged(_parentLogTabWin.Preferences, true, SettingsFlags.GuiOrColors); + var setLastColumnWidth = _parentLogTabWin.Preferences.SetLastColumnWidth; + var lastColumnWidth = _parentLogTabWin.Preferences.LastColumnWidth; + var fontName = _parentLogTabWin.Preferences.FontName; + var fontSize = _parentLogTabWin.Preferences.FontSize; + + PreferencesChanged(fontName, fontSize, setLastColumnWidth, lastColumnWidth, true, SettingsFlags.GuiOrColors); } [SupportedOSPlatform("windows")] diff --git a/src/LogExpert.UI/Controls/LogWindow/LogWindowPrivate.cs b/src/LogExpert.UI/Controls/LogWindow/LogWindowPrivate.cs index 49b9f505..e484a366 100644 --- a/src/LogExpert.UI/Controls/LogWindow/LogWindowPrivate.cs +++ b/src/LogExpert.UI/Controls/LogWindow/LogWindowPrivate.cs @@ -60,6 +60,21 @@ private void CreateDefaultViewStyle () dataGridViewCellStyleMainGrid.ForeColor = SystemColors.ControlText; dataGridViewCellStyleMainGrid.SelectionBackColor = SystemColors.Highlight; dataGridViewCellStyleMainGrid.SelectionForeColor = SystemColors.HighlightText; + + Color highlightColor = SystemColors.Highlight; + //Color is smaller than 128, means its darker + var isDark = (highlightColor.R * 0.2126) + (highlightColor.G * 0.7152) + (highlightColor.B * 0.0722) < 255 / 2; + + if (isDark) + { + dataGridViewCellStyleMainGrid.SelectionForeColor = Color.White; + } + else + { + dataGridViewCellStyleMainGrid.SelectionForeColor = Color.Black; + + } + dataGridViewCellStyleMainGrid.WrapMode = DataGridViewTriState.False; dataGridView.DefaultCellStyle = dataGridViewCellStyleMainGrid; @@ -69,6 +84,16 @@ private void CreateDefaultViewStyle () dataGridViewCellStyleFilterGrid.ForeColor = SystemColors.ControlText; dataGridViewCellStyleFilterGrid.SelectionBackColor = SystemColors.Highlight; dataGridViewCellStyleFilterGrid.SelectionForeColor = SystemColors.HighlightText; + + if (isDark) + { + dataGridViewCellStyleFilterGrid.SelectionForeColor = Color.White; + } + else + { + dataGridViewCellStyleFilterGrid.SelectionForeColor = Color.Black; + } + dataGridViewCellStyleFilterGrid.WrapMode = DataGridViewTriState.False; filterGridView.DefaultCellStyle = dataGridViewCellStyleFilterGrid; } @@ -590,7 +615,12 @@ private void LoadingFinished () _statusEventArgs.FileSize = _logFileReader.FileSize; SendStatusLineUpdate(); - PreferencesChanged(_parentLogTabWin.Preferences, true, SettingsFlags.All); + var setLastColumnWidth = _parentLogTabWin.Preferences.SetLastColumnWidth; + var lastColumnWidth = _parentLogTabWin.Preferences.LastColumnWidth; + var fontName = _parentLogTabWin.Preferences.FontName; + var fontSize = _parentLogTabWin.Preferences.FontSize; + + PreferencesChanged(fontName, fontSize, setLastColumnWidth, lastColumnWidth, true, SettingsFlags.All); //LoadPersistenceData(); } @@ -1092,21 +1122,18 @@ private void AutoResizeColumns (BufferedDataGridView gridView) } } - private void PaintCell (DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, bool noBackgroundFill, - HighlightEntry groundEntry) + private void PaintCell (DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, bool noBackgroundFill, HighlightEntry groundEntry) { PaintHighlightedCell(e, gridView, noBackgroundFill, groundEntry); } - private void PaintHighlightedCell (DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, - bool noBackgroundFill, - HighlightEntry groundEntry) + private void PaintHighlightedCell (DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, bool noBackgroundFill, HighlightEntry groundEntry) { var column = e.Value as IColumn; column ??= Column.EmptyColumn; - IList matchList = FindHighlightMatches(column); + IList matchList = FindHighlightMatches(column); // too many entries per line seem to cause problems with the GDI while (matchList.Count > 50) { @@ -1121,23 +1148,23 @@ private void PaintHighlightedCell (DataGridViewCellPaintingEventArgs e, Buffered IsWordMatch = true }; - HilightMatchEntry hme = new() + HighlightMatchEntry hme = new() { StartPos = 0, Length = column.DisplayValue.Length, - HilightEntry = he + HighlightEntry = he }; if (groundEntry != null) { - hme.HilightEntry.IsBold = groundEntry.IsBold; + hme.HighlightEntry.IsBold = groundEntry.IsBold; } matchList = MergeHighlightMatchEntries(matchList, hme); - var leftPad = e.CellStyle.Padding.Left; - RectangleF rect = new(e.CellBounds.Left + leftPad, e.CellBounds.Top, e.CellBounds.Width, - e.CellBounds.Height); + //var leftPad = e.CellStyle.Padding.Left; + //RectangleF rect = new(e.CellBounds.Left + leftPad, e.CellBounds.Top, e.CellBounds.Width, e.CellBounds.Height); + Rectangle borderWidths = PaintHelper.BorderWidths(e.AdvancedBorderStyle); Rectangle valBounds = e.CellBounds; valBounds.Offset(borderWidths.X, borderWidths.Y); @@ -1172,33 +1199,29 @@ private void PaintHighlightedCell (DataGridViewCellPaintingEventArgs e, Buffered Rectangle r = gridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); e.Graphics.SetClip(e.CellBounds); - foreach (HilightMatchEntry matchEntry in matchList) + foreach (HighlightMatchEntry matchEntry in matchList) { - Font font = matchEntry != null && matchEntry.HilightEntry.IsBold ? BoldFont : NormalFont; - Brush bgBrush = matchEntry.HilightEntry.BackgroundColor != Color.Empty - ? new SolidBrush(matchEntry.HilightEntry.BackgroundColor) + Font font = matchEntry != null && matchEntry.HighlightEntry.IsBold ? BoldFont : NormalFont; + + Brush bgBrush = matchEntry.HighlightEntry.BackgroundColor != Color.Empty + ? new SolidBrush(matchEntry.HighlightEntry.BackgroundColor) : null; + var matchWord = column.DisplayValue.Substring(matchEntry.StartPos, matchEntry.Length); Size wordSize = TextRenderer.MeasureText(e.Graphics, matchWord, font, proposedSize, flags); wordSize.Height = e.CellBounds.Height; Rectangle wordRect = new(wordPos, wordSize); - Color foreColor = matchEntry.HilightEntry.ForegroundColor; + Color foreColor = matchEntry.HighlightEntry.ForegroundColor; if ((e.State & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected) { - if (!noBackgroundFill && bgBrush != null && !matchEntry.HilightEntry.NoBackground) + if (!noBackgroundFill && bgBrush != null && !matchEntry.HighlightEntry.NoBackground) { e.Graphics.FillRectangle(bgBrush, wordRect); } } - if (foreColor == Color.Black) - { - foreColor = ColorMode.ForeColor; - } - - TextRenderer.DrawText(e.Graphics, matchWord, font, wordRect, - foreColor, flags); + TextRenderer.DrawText(e.Graphics, matchWord, font, wordRect, foreColor, flags); wordPos.Offset(wordSize.Width, 0); bgBrush?.Dispose(); @@ -1214,26 +1237,25 @@ private void PaintHighlightedCell (DataGridViewCellPaintingEventArgs e, Buffered /// List of all highlight matches for the current cell /// The entry that is used as the default. /// List of HilightMatchEntry objects. The list spans over the whole cell and contains color infos for every substring. - private IList MergeHighlightMatchEntries (IList matchList, - HilightMatchEntry groundEntry) + private IList MergeHighlightMatchEntries (IList matchList, HighlightMatchEntry groundEntry) { // Fill an area with lenth of whole text with a default hilight entry var entryArray = new HighlightEntry[groundEntry.Length]; for (var i = 0; i < entryArray.Length; ++i) { - entryArray[i] = groundEntry.HilightEntry; + entryArray[i] = groundEntry.HighlightEntry; } // "overpaint" with all matching word match enries // Non-word-mode matches will not overpaint because they use the groundEntry - foreach (HilightMatchEntry me in matchList) + foreach (HighlightMatchEntry me in matchList) { var endPos = me.StartPos + me.Length; for (var i = me.StartPos; i < endPos; ++i) { - if (me.HilightEntry.IsWordMatch) + if (me.HighlightEntry.IsWordMatch) { - entryArray[i] = me.HilightEntry; + entryArray[i] = me.HighlightEntry; } else { @@ -1243,7 +1265,7 @@ private IList MergeHighlightMatchEntries (IList mergedList = []; + IList mergedList = []; if (entryArray.Length > 0) { @@ -1255,11 +1277,11 @@ private IList MergeHighlightMatchEntries (IList MergeHighlightMatchEntries (IList FindMatchingHilightEntries (ITextValue line) return resultList; } - private void GetHighlightEntryMatches (ITextValue line, IList hilightEntryList, IList resultList) + private void GetHighlightEntryMatches (ITextValue line, IList hilightEntryList, IList resultList) { foreach (HighlightEntry entry in hilightEntryList) { @@ -1357,9 +1379,9 @@ private void GetHighlightEntryMatches (ITextValue line, IList hi MatchCollection matches = entry.Regex.Matches(line.Text); foreach (Match match in matches) { - HilightMatchEntry me = new() + HighlightMatchEntry me = new() { - HilightEntry = entry, + HighlightEntry = entry, StartPos = match.Index, Length = match.Length }; @@ -1371,9 +1393,9 @@ private void GetHighlightEntryMatches (ITextValue line, IList hi { if (CheckHighlightEntryMatch(entry, line)) { - HilightMatchEntry me = new() + HighlightMatchEntry me = new() { - HilightEntry = entry, + HighlightEntry = entry, StartPos = 0, Length = line.Text.Length }; @@ -1702,7 +1724,7 @@ private void SelectLine (int line, bool triggerSyncCall, bool shouldScroll) var wasCancelled = _shouldCancel; _shouldCancel = false; _isSearching = false; - StatusLineText(""); + StatusLineText(string.Empty); _guiStateArgs.MenuEnabled = true; if (wasCancelled) @@ -2934,13 +2956,13 @@ private void SetExplicitEncoding (Encoding encoding) } [SupportedOSPlatform("windows")] - private void ApplyDataGridViewPrefs (BufferedDataGridView dataGridView, Preferences prefs) + private void ApplyDataGridViewPrefs (BufferedDataGridView dataGridView, bool setLastColumnWidth, int lastColumnWidth) { if (dataGridView.Columns.GetColumnCount(DataGridViewElementStates.None) > 1) { - if (prefs.SetLastColumnWidth) + if (setLastColumnWidth) { - dataGridView.Columns[dataGridView.Columns.GetColumnCount(DataGridViewElementStates.None) - 1].MinimumWidth = prefs.LastColumnWidth; + dataGridView.Columns[dataGridView.Columns.GetColumnCount(DataGridViewElementStates.None) - 1].MinimumWidth = lastColumnWidth; } else { diff --git a/src/LogExpert.UI/Controls/LogWindow/LogWindowPublic.cs b/src/LogExpert.UI/Controls/LogWindow/LogWindowPublic.cs index 03c37a77..601f3064 100644 --- a/src/LogExpert.UI/Controls/LogWindow/LogWindowPublic.cs +++ b/src/LogExpert.UI/Controls/LogWindow/LogWindowPublic.cs @@ -523,6 +523,7 @@ public HighlightEntry FindHighlightEntry (ITextValue line, bool noWordMatches) { continue; } + if (CheckHighlightEntryMatch(entry, line)) { return entry; @@ -547,20 +548,23 @@ public HighlightEntry FindHighlightEntry (ITextValue line, bool noWordMatches) } } - public IList FindHighlightMatches (ITextValue column) + public IList FindHighlightMatches (ITextValue column) { - IList resultList = new List(); + IList resultList = []; + if (column != null) { lock (_currentHighlightGroupLock) { GetHighlightEntryMatches(column, _currentHighlightGroup.HighlightEntryList, resultList); } + lock (_tempHighlightEntryList) { GetHighlightEntryMatches(column, _tempHighlightEntryList, resultList); } } + return resultList; } @@ -703,6 +707,7 @@ public void SelectAndEnsureVisible (int line, bool triggerSyncCall) dataGridView.FirstDisplayedScrollingRowIndex += 1; } } + dataGridView.CurrentCell = dataGridView.Rows[line].Cells[0]; } catch (Exception e) @@ -839,6 +844,7 @@ public void AddBookmarkOverlays () break; } } + if (_bookmarkProvider.IsBookmarkAtLine(i)) { Bookmark bookmark = _bookmarkProvider.GetBookmarkForLine(i); @@ -866,6 +872,7 @@ public void AddBookmarkOverlays () //heightSum += rr.Height; heightSum += GetRowHeight(rn); } + r.Offset(0, r.Height + heightSum); } else @@ -876,14 +883,17 @@ public void AddBookmarkOverlays () //heightSum += rr.Height; heightSum += GetRowHeight(rn); } + r.Offset(0, -(r.Height + heightSum)); } //r.Offset(0, this.dataGridView.DisplayRectangle.Height); } + if (_logger.IsDebugEnabled) { - _logger.Debug("AddBookmarkOverlay() r.Location={0}, width={1}, scroll_offset={2}", r.Location.X, r.Width, dataGridView.HorizontalScrollingOffset); + _logger.Debug($"AddBookmarkOverlay() r.Location={r.Location.X}, width={r.Width}, scroll_offset={dataGridView.HorizontalScrollingOffset}"); } + overlay.Position = r.Location - new Size(dataGridView.HorizontalScrollingOffset, 0); overlay.Position += new Size(10, r.Height / 2); dataGridView.AddOverlay(overlay); @@ -1159,11 +1169,13 @@ public void LogWindowActivated () { OnTailFollowed(EventArgs.Empty); } + if (Preferences.TimestampControl) { SetTimestampLimits(); SyncTimestampDisplay(); } + dataGridView.Focus(); SendGuiStateUpdate(); @@ -1205,6 +1217,7 @@ public void CopyMarkedLinesToTab () lineNumList.Add(row.Index); } } + lineNumList.Sort(); // create dummy FilterPipe for connecting line numbers to original window // setting IsStopped to true prevents further filter processing @@ -1282,11 +1295,11 @@ public void Reload () //} } - public void PreferencesChanged (Preferences newPreferences, bool isLoadTime, SettingsFlags flags) + public void PreferencesChanged (string fontName, float fontSize, bool setLastColumnWidth, int lastColumnWidth, bool isLoadTime, SettingsFlags flags) { if ((flags & SettingsFlags.GuiOrColors) == SettingsFlags.GuiOrColors) { - NormalFont = new Font(new FontFamily(newPreferences.FontName), newPreferences.FontSize); + NormalFont = new Font(new FontFamily(fontName), fontSize); BoldFont = new Font(NormalFont, FontStyle.Bold); MonospacedFont = new Font("Courier New", Preferences.FontSize, FontStyle.Bold); @@ -1300,14 +1313,15 @@ public void PreferencesChanged (Preferences newPreferences, bool isLoadTime, Set ShowBookmarkBubbles = Preferences.ShowBubbles; - ApplyDataGridViewPrefs(dataGridView, newPreferences); - ApplyDataGridViewPrefs(filterGridView, newPreferences); + ApplyDataGridViewPrefs(dataGridView, setLastColumnWidth, lastColumnWidth); + ApplyDataGridViewPrefs(filterGridView, setLastColumnWidth, lastColumnWidth); if (Preferences.TimestampControl) { SetTimestampLimits(); SyncTimestampDisplay(); } + if (isLoadTime) { filterTailCheckBox.Checked = Preferences.FilterTail; @@ -1318,11 +1332,13 @@ public void PreferencesChanged (Preferences newPreferences, bool isLoadTime, Set _timeSpreadCalc.TimeMode = Preferences.TimeSpreadTimeMode; timeSpreadingControl.ForeColor = Preferences.TimeSpreadColor; timeSpreadingControl.ReverseAlpha = Preferences.ReverseAlpha; + if (CurrentColumnizer.IsTimeshiftImplemented()) { timeSpreadingControl.Invoke(new MethodInvoker(timeSpreadingControl.Refresh)); ShowTimeSpread(Preferences.ShowTimeSpread); } + ToggleColumnFinder(Preferences.ShowColumnFinder, false); } @@ -1399,6 +1415,7 @@ public int FindTimestampLine (int lineNum, DateTime timestamp, bool roundToSecon GetTimestampForLineForward(ref foundLine, roundToSeconds); // fwd to next valid timestamp return foundLine; } + return -foundLine; } @@ -1412,6 +1429,7 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd { return lineNum; } + if (timestamp < currentTimestamp) { //rangeStart = rangeStart; @@ -1428,7 +1446,7 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd return -lineNum; } - lineNum = (rangeEnd - rangeStart) / 2 + rangeStart; + lineNum = ((rangeEnd - rangeStart) / 2) + rangeStart; // prevent endless loop if (rangeEnd - rangeStart < 2) { @@ -1437,12 +1455,12 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd { return rangeStart; } + currentTimestamp = GetTimestampForLine(ref rangeEnd, roundToSeconds); - if (currentTimestamp.CompareTo(timestamp) == 0) - { - return rangeEnd; - } - return -lineNum; + + return currentTimestamp.CompareTo(timestamp) == 0 + ? rangeEnd + : -lineNum; } return FindTimestampLine_Internal(lineNum, rangeStart, rangeEnd, timestamp, roundToSeconds); @@ -1453,7 +1471,6 @@ public int FindTimestampLine_Internal (int lineNum, int rangeStart, int rangeEnd * has no timestamp, the previous line will be checked until a * timestamp is found. */ - public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds) { lock (_currentColumnizerLock) @@ -1462,7 +1479,8 @@ public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds) { return DateTime.MinValue; } - _logger.Debug("GetTimestampForLine({0}) enter", lineNum); + + _logger.Debug($"GetTimestampForLine({lineNum}) enter"); DateTime timeStamp = DateTime.MinValue; var lookBack = false; if (lineNum >= 0 && lineNum < dataGridView.RowCount) @@ -1473,25 +1491,30 @@ public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds) { return DateTime.MinValue; } + lookBack = true; ILogLine logLine = _logFileReader.GetLogLine(lineNum); if (logLine == null) { return DateTime.MinValue; } + ColumnizerCallbackObject.LineNum = lineNum; timeStamp = CurrentColumnizer.GetTimestamp(ColumnizerCallbackObject, logLine); if (roundToSeconds) { timeStamp = timeStamp.Subtract(TimeSpan.FromMilliseconds(timeStamp.Millisecond)); } + lineNum--; } } + if (lookBack) { lineNum++; } + _logger.Debug("GetTimestampForLine() leave with lineNum={0}", lineNum); return timeStamp; } @@ -1502,7 +1525,6 @@ public DateTime GetTimestampForLine (ref int lineNum, bool roundToSeconds) * has no timestamp, the next line will be checked until a * timestamp is found. */ - public DateTime GetTimestampForLineForward (ref int lineNum, bool roundToSeconds) { lock (_currentColumnizerLock) diff --git a/src/LogExpert.UI/Dialogs/BookmarkWindow.cs b/src/LogExpert.UI/Dialogs/BookmarkWindow.cs index c347a4c6..d471c587 100644 --- a/src/LogExpert.UI/Dialogs/BookmarkWindow.cs +++ b/src/LogExpert.UI/Dialogs/BookmarkWindow.cs @@ -38,7 +38,7 @@ public BookmarkWindow () AutoScaleMode = AutoScaleMode.Dpi; bookmarkDataGridView.CellValueNeeded += OnBoomarkDataGridViewCellValueNeeded; - bookmarkDataGridView.CellPainting += boomarkDataGridView_CellPainting; + bookmarkDataGridView.CellPainting += OnBoomarkDataGridViewCellPainting; ChangeTheme(Controls); } @@ -50,6 +50,7 @@ public BookmarkWindow () public void ChangeTheme (Control.ControlCollection container) { #region ApplyColorToAllControls + foreach (Control component in container) { if (component.Controls != null && component.Controls.Count > 0) @@ -65,6 +66,7 @@ public void ChangeTheme (Control.ControlCollection container) } } + #endregion #region DataGridView @@ -196,28 +198,20 @@ public void SetBookmarkData (IBookmarkData bookmarkData) HideIfNeeded(); } - //TODO: BAD DESIGN! FIX!!! - public void PreferencesChanged (Preferences newPreferences, bool isLoadTime, SettingsFlags flags, IConfigManager configManager) + public void PreferencesChanged (string fontName, float fontSize, bool setLastColumnWidth, int lastColumnWidth, SettingsFlags flags) { if ((flags & SettingsFlags.GuiOrColors) == SettingsFlags.GuiOrColors) { - SetFont(newPreferences.FontName, newPreferences.FontSize); - if (bookmarkDataGridView.Columns.Count > 1 && newPreferences.SetLastColumnWidth) + SetFont(fontName, fontSize); + if (bookmarkDataGridView.Columns.Count > 1 && setLastColumnWidth) { - bookmarkDataGridView.Columns[bookmarkDataGridView.Columns.Count - 1].MinimumWidth = - newPreferences.LastColumnWidth; + bookmarkDataGridView.Columns[bookmarkDataGridView.Columns.Count - 1].MinimumWidth = lastColumnWidth; } - PaintHelper.ApplyDataGridViewPrefs(bookmarkDataGridView, newPreferences, configManager); + PaintHelper.ApplyDataGridViewPrefs(bookmarkDataGridView, setLastColumnWidth, lastColumnWidth); } } - //TODO: BAD DESIGN! FIX!!! - public void PreferencesChanged (Preferences newPreferences, bool isLoadTime, SettingsFlags flags) - { - PreferencesChanged(newPreferences, isLoadTime, flags, null); - } - public void SetCurrentFile (IFileViewContext ctx) { if (ctx != null) @@ -260,10 +254,13 @@ protected override void OnPaint (PaintEventArgs e) { Rectangle r = ClientRectangle; e.Graphics.FillRectangle(SystemBrushes.FromSystemColor(ColorMode.BookmarksDefaultBackgroundColor), r); - RectangleF rect = r; - StringFormat sf = new(); - sf.Alignment = StringAlignment.Center; - sf.LineAlignment = StringAlignment.Center; + + StringFormat sf = new() + { + Alignment = StringAlignment.Center, + LineAlignment = StringAlignment.Center + }; + e.Graphics.DrawString("No bookmarks in current file", SystemFonts.DialogFont, SystemBrushes.WindowText, r, sf); } else @@ -369,7 +366,7 @@ private void HideIfNeeded () #region Events handler - private void boomarkDataGridView_CellPainting (object sender, DataGridViewCellPaintingEventArgs e) + private void OnBoomarkDataGridViewCellPainting (object sender, DataGridViewCellPaintingEventArgs e) { if (bookmarkData == null) { diff --git a/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPrivate.cs b/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPrivate.cs index 8ad87e27..3f91c8ca 100644 --- a/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPrivate.cs +++ b/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPrivate.cs @@ -73,7 +73,12 @@ private void InitBookmarkWindow () ShowHint = DockState.DockBottom }; - _bookmarkWindow.PreferencesChanged(ConfigManager.Settings.Preferences, false, SettingsFlags.All, ConfigManager.Instance); + var setLastColumnWidth = ConfigManager.Settings.Preferences.SetLastColumnWidth; + var lastColumnWidth = ConfigManager.Settings.Preferences.LastColumnWidth; + var fontName = ConfigManager.Settings.Preferences.FontName; + var fontSize = ConfigManager.Settings.Preferences.FontSize; + + _bookmarkWindow.PreferencesChanged(fontName, fontSize, setLastColumnWidth, lastColumnWidth, SettingsFlags.All); _bookmarkWindow.VisibleChanged += OnBookmarkWindowVisibleChanged; _firstBookmarkWindowShow = true; } @@ -966,15 +971,20 @@ private void NotifyWindowsForChangedPrefs (SettingsFlags flags) _logger.Info("The preferences have changed"); ApplySettings(ConfigManager.Settings, flags); + var setLastColumnWidth = ConfigManager.Settings.Preferences.SetLastColumnWidth; + var lastColumnWidth = ConfigManager.Settings.Preferences.LastColumnWidth; + var fontName = ConfigManager.Settings.Preferences.FontName; + var fontSize = ConfigManager.Settings.Preferences.FontSize; + lock (_logWindowList) { foreach (LogWindow.LogWindow logWindow in _logWindowList) { - logWindow.PreferencesChanged(ConfigManager.Settings.Preferences, false, flags); + logWindow.PreferencesChanged(fontName, fontSize, setLastColumnWidth, lastColumnWidth, false, flags); } } - _bookmarkWindow.PreferencesChanged(ConfigManager.Settings.Preferences, false, flags); + _bookmarkWindow.PreferencesChanged(fontName, fontSize, setLastColumnWidth, lastColumnWidth, flags); HighlightGroupList = ConfigManager.Settings.Preferences.HighlightGroupList; if ((flags & SettingsFlags.HighlightSettings) == SettingsFlags.HighlightSettings) diff --git a/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPublic.cs b/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPublic.cs index 25000414..56d639ce 100644 --- a/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPublic.cs +++ b/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindowPublic.cs @@ -72,9 +72,10 @@ public LogWindow.LogWindow AddFileTab (string givenFileName, bool isTempFile, st EncodingOptions encodingOptions = new(); FillDefaultEncodingFromSettings(encodingOptions); - LogWindow.LogWindow logWindow = new(this, logFileName, isTempFile, forcePersistenceLoading, ConfigManager); - - logWindow.GivenFileName = givenFileName; + LogWindow.LogWindow logWindow = new(this, logFileName, isTempFile, forcePersistenceLoading, ConfigManager) + { + GivenFileName = givenFileName + }; if (preProcessColumnizer != null) { diff --git a/src/LogExpert.UI/Entities/PaintHelper.cs b/src/LogExpert.UI/Entities/PaintHelper.cs index 4d760cde..c1f9c9e5 100644 --- a/src/LogExpert.UI/Entities/PaintHelper.cs +++ b/src/LogExpert.UI/Entities/PaintHelper.cs @@ -3,7 +3,6 @@ using LogExpert.Core.Classes.Highlight; using LogExpert.Core.Config; using LogExpert.Core.Entities; -using LogExpert.Core.Interface; using LogExpert.Dialogs; using LogExpert.UI.Controls; using LogExpert.UI.Interface; @@ -18,49 +17,46 @@ internal static class PaintHelper { #region Fields - private static readonly ILogger _logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); //TODO Make configurable private static Color _bookmarkColor = Color.FromArgb(165, 200, 225); #endregion - #region Properties - public static IConfigManager ConfigManager { get; set; } - - private static Preferences Preferences => ConfigManager.Settings.Preferences; - - #endregion - #region Public methods [SupportedOSPlatform("windows")] - public static void CellPainting (ILogPaintContextUI logPaintCtx, BufferedDataGridView gridView, int rowIndex, - DataGridViewCellPaintingEventArgs e) + public static void CellPainting (ILogPaintContextUI logPaintCtx, BufferedDataGridView gridView, int rowIndex, DataGridViewCellPaintingEventArgs e) { if (rowIndex < 0 || e.ColumnIndex < 0) { e.Handled = false; return; } + ILogLine line = logPaintCtx.GetLogLine(rowIndex); + if (line != null) { HighlightEntry entry = logPaintCtx.FindHighlightEntry(line, true); e.Graphics.SetClip(e.CellBounds); + if ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected) { Color backColor = e.CellStyle.SelectionBackColor; Brush brush; + if (gridView.Focused) { - brush = new SolidBrush(e.CellStyle.SelectionBackColor); + brush = new SolidBrush(backColor); } else { var color = Color.FromArgb(255, 170, 170, 170); brush = new SolidBrush(color); } + e.Graphics.FillRectangle(brush, e.CellBounds); brush.Dispose(); } @@ -81,6 +77,7 @@ public static void CellPainting (ILogPaintContextUI logPaintCtx, BufferedDataGri bgColor = entry.BackgroundColor; } } + e.CellStyle.BackColor = bgColor; e.PaintBackground(e.ClipBounds, false); } @@ -112,10 +109,10 @@ public static void CellPainting (ILogPaintContextUI logPaintCtx, BufferedDataGri LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }; + Brush brush2 = new SolidBrush(Color.FromArgb(255, 190, 100, 0)); Font font = logPaintCtx.MonospacedFont; - e.Graphics.DrawString("i", font, brush2, new RectangleF(r.Left, r.Top, r.Width, r.Height), - format); + e.Graphics.DrawString("i", font, brush2, new RectangleF(r.Left, r.Top, r.Width, r.Height), format); brush2.Dispose(); } } @@ -191,16 +188,17 @@ public static void SetColumnizer (ILogLineColumnizer columnizer, BufferedDataGri _logger.Error(ae); } - gridView.Columns.Add(CreateMarkerColumn()); + _ = gridView.Columns.Add(CreateMarkerColumn()); - gridView.Columns.Add(CreateLineNumberColumn()); + _ = gridView.Columns.Add(CreateLineNumberColumn()); foreach (var colName in columnizer.GetColumnNames()) { - gridView.Columns.Add(CreateTitleColumn(colName)); + _ = gridView.Columns.Add(CreateTitleColumn(colName)); } gridView.RowCount = rowCount; + if (currLine != -1) { gridView.CurrentCell = gridView.Rows[currLine].Cells[0]; @@ -210,25 +208,23 @@ public static void SetColumnizer (ILogLineColumnizer columnizer, BufferedDataGri { gridView.FirstDisplayedScrollingRowIndex = currFirstLine; } + //gridView.Refresh(); //AutoResizeColumns(gridView); } - //TODO: Original name is AutoResizeColumn. Where is this used? - //TODO: Rename ConfigManager to configManager [SupportedOSPlatform("windows")] - private static void AutoResizeColumns (BufferedDataGridView gridView, IConfigManager configManager) + private static void AutoResizeColumns (BufferedDataGridView gridView, bool setLastColumnWidth, int lastColumnWidth) { try { gridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); - if (gridView.Columns.Count > 1 && Preferences.SetLastColumnWidth && - gridView.Columns[gridView.Columns.Count - 1].Width < Preferences.LastColumnWidth + if (gridView.Columns.Count > 1 && setLastColumnWidth && gridView.Columns[gridView.Columns.Count - 1].Width < lastColumnWidth ) { // It seems that using 'MinimumWidth' instead of 'Width' prevents the DataGridView's NullReferenceExceptions //gridView.Columns[gridView.Columns.Count - 1].Width = this.Preferences.lastColumnWidth; - gridView.Columns[gridView.Columns.Count - 1].MinimumWidth = Preferences.LastColumnWidth; + gridView.Columns[gridView.Columns.Count - 1].MinimumWidth = lastColumnWidth; } } catch (NullReferenceException e) @@ -242,16 +238,13 @@ private static void AutoResizeColumns (BufferedDataGridView gridView, IConfigMan } [SupportedOSPlatform("windows")] - public static void ApplyDataGridViewPrefs (BufferedDataGridView dataGridView, Preferences prefs, IConfigManager configManager) + public static void ApplyDataGridViewPrefs (BufferedDataGridView dataGridView, bool setLastColumnWidht, int lastColumnWidth) { - //TODO: This is a very bad solution and should be solved ASAP - ConfigManager ??= configManager; - if (dataGridView.Columns.Count > 1) { - if (prefs.SetLastColumnWidth) + if (setLastColumnWidht) { - dataGridView.Columns[dataGridView.Columns.Count - 1].MinimumWidth = prefs.LastColumnWidth; + dataGridView.Columns[dataGridView.Columns.Count - 1].MinimumWidth = lastColumnWidth; } else { @@ -269,7 +262,7 @@ public static void ApplyDataGridViewPrefs (BufferedDataGridView dataGridView, Pr dataGridView.Invalidate(); dataGridView.Refresh(); - AutoResizeColumns(dataGridView, ConfigManager); + AutoResizeColumns(dataGridView, setLastColumnWidht, lastColumnWidth); } [SupportedOSPlatform("windows")] @@ -279,29 +272,26 @@ public static Rectangle BorderWidths (DataGridViewAdvancedBorderStyle advancedBo { X = advancedBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.None ? 0 : 1 }; - if (advancedBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.OutsetDouble || - advancedBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.InsetDouble) + if (advancedBorderStyle.Left is DataGridViewAdvancedCellBorderStyle.OutsetDouble or DataGridViewAdvancedCellBorderStyle.InsetDouble) { rect.X++; } rect.Y = advancedBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.None ? 0 : 1; - if (advancedBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.OutsetDouble || - advancedBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.InsetDouble) + if (advancedBorderStyle.Top is DataGridViewAdvancedCellBorderStyle.OutsetDouble or DataGridViewAdvancedCellBorderStyle.InsetDouble) { rect.Y++; } rect.Width = advancedBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.None ? 0 : 1; - if (advancedBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.OutsetDouble || - advancedBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.InsetDouble) + if (advancedBorderStyle.Right is DataGridViewAdvancedCellBorderStyle.OutsetDouble or DataGridViewAdvancedCellBorderStyle.InsetDouble) { rect.Width++; } rect.Height = advancedBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.None ? 0 : 1; - if (advancedBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.OutsetDouble || - advancedBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.InsetDouble) + if (advancedBorderStyle.Bottom is DataGridViewAdvancedCellBorderStyle.OutsetDouble or + DataGridViewAdvancedCellBorderStyle.InsetDouble) { rect.Height++; } @@ -327,7 +317,7 @@ private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGr { var value = e.Value ?? string.Empty; - IList matchList = logPaintCtx.FindHighlightMatches(value as ILogLine); + IList matchList = logPaintCtx.FindHighlightMatches(value as ILogLine); // too many entries per line seem to cause problems with the GDI while (matchList.Count > 50) { @@ -338,7 +328,7 @@ private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGr { if (!string.IsNullOrEmpty(column.FullValue)) { - HilightMatchEntry hme = new() + HighlightMatchEntry hme = new() { StartPos = 0, Length = column.FullValue.Length @@ -358,7 +348,7 @@ private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGr IsWordMatch = false }; - hme.HilightEntry = he; + hme.HighlightEntry = he; matchList = MergeHighlightMatchEntries(matchList, hme); } @@ -399,14 +389,14 @@ private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGr Rectangle r = gridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); e.Graphics.SetClip(e.CellBounds); - foreach (HilightMatchEntry matchEntry in matchList) + foreach (HighlightMatchEntry matchEntry in matchList) { - Font font = matchEntry != null && matchEntry.HilightEntry.IsBold + Font font = matchEntry != null && matchEntry.HighlightEntry.IsBold ? logPaintCtx.BoldFont : logPaintCtx.NormalFont; - Brush bgBrush = matchEntry.HilightEntry.BackgroundColor != Color.Empty - ? new SolidBrush(matchEntry.HilightEntry.BackgroundColor) + Brush bgBrush = matchEntry.HighlightEntry.BackgroundColor != Color.Empty + ? new SolidBrush(matchEntry.HighlightEntry.BackgroundColor) : null; var matchWord = string.Empty; @@ -422,10 +412,10 @@ private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGr wordSize.Height = e.CellBounds.Height; Rectangle wordRect = new(wordPos, wordSize); - Color foreColor = matchEntry.HilightEntry.ForegroundColor; + Color foreColor = matchEntry.HighlightEntry.ForegroundColor; if ((e.State & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected) { - if (!noBackgroundFill && bgBrush != null && !matchEntry.HilightEntry.NoBackground) + if (!noBackgroundFill && bgBrush != null && !matchEntry.HighlightEntry.NoBackground) { e.Graphics.FillRectangle(bgBrush, wordRect); } @@ -455,25 +445,25 @@ private static void PaintHighlightedCell (ILogPaintContextUI logPaintCtx, DataGr /// List of all highlight matches for the current cell /// The entry that is used as the default. /// List of HilightMatchEntry objects. The list spans over the whole cell and contains color infos for every substring. - private static IList MergeHighlightMatchEntries (IList matchList, HilightMatchEntry groundEntry) + private static IList MergeHighlightMatchEntries (IList matchList, HighlightMatchEntry groundEntry) { // Fill an area with lenth of whole text with a default hilight entry var entryArray = new HighlightEntry[groundEntry.Length]; for (var i = 0; i < entryArray.Length; ++i) { - entryArray[i] = groundEntry.HilightEntry; + entryArray[i] = groundEntry.HighlightEntry; } // "overpaint" with all matching word match enries // Non-word-mode matches will not overpaint because they use the groundEntry - foreach (HilightMatchEntry me in matchList) + foreach (HighlightMatchEntry me in matchList) { var endPos = me.StartPos + me.Length; for (var i = me.StartPos; i < endPos; ++i) { - if (me.HilightEntry.IsWordMatch) + if (me.HighlightEntry.IsWordMatch) { - entryArray[i] = me.HilightEntry; + entryArray[i] = me.HighlightEntry; } //else //{ @@ -483,7 +473,7 @@ private static IList MergeHighlightMatchEntries (IList mergedList = []; + IList mergedList = []; if (entryArray.Length > 0) { HighlightEntry currentEntry = entryArray[0]; @@ -493,22 +483,22 @@ private static IList MergeHighlightMatchEntries (IList FindHighlightMatches(ITextValue line); + IList FindHighlightMatches(ITextValue line); #endregion } \ No newline at end of file diff --git a/src/LogExpert/Program.cs b/src/LogExpert/Program.cs index 0bd88b9b..cbfda99b 100644 --- a/src/LogExpert/Program.cs +++ b/src/LogExpert/Program.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using System.Diagnostics; using System.IO.Pipes; using System.Reflection; using System.Security; @@ -39,7 +39,7 @@ internal static class Program /// The main entry point for the application. /// [STAThread] - private static void Main(string[] args) + private static void Main (string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ThreadException += Application_ThreadException; @@ -49,7 +49,7 @@ private static void Main(string[] args) Application.EnableVisualStyles(); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); - _logger.Info("\r\n============================================================================\r\nLogExpert {0} started.\r\n============================================================================", Assembly.GetExecutingAssembly().GetName().Version.ToString(3)); + _logger.Info($"\r\n============================================================================\r\nLogExpert {Assembly.GetExecutingAssembly().GetName().Version.ToString(3)} started.\r\n============================================================================"); CancellationTokenSource cts = new(); try @@ -70,6 +70,7 @@ private static void Main(string[] args) MessageBox.Show(@"Config file not found", @"LogExpert"); } } + PluginRegistry.PluginRegistry.Instance.Create(ConfigManager.Instance.ConfigDir, ConfigManager.Instance.Settings.Preferences.PollingInterval); var pId = Process.GetCurrentProcess().SessionId; @@ -155,7 +156,7 @@ private static void Main(string[] args) } } - private static string SerializeCommandIntoNonFormattedJSON(string[] fileNames, bool allowOnlyOneInstance) + private static string SerializeCommandIntoNonFormattedJSON (string[] fileNames, bool allowOnlyOneInstance) { var message = new IpcMessage() { @@ -169,7 +170,7 @@ private static string SerializeCommandIntoNonFormattedJSON(string[] fileNames, b // This loop tries to convert relative file names into absolute file names (assuming that platform file names are given). // It tolerates errors, to give file system plugins (e.g. sftp) a change later. // TODO: possibly should be moved to LocalFileSystem plugin - private static string[] GenerateAbsoluteFilePaths(string[] remainingArgs) + private static string[] GenerateAbsoluteFilePaths (string[] remainingArgs) { List argsList = []; @@ -189,37 +190,40 @@ private static string[] GenerateAbsoluteFilePaths(string[] remainingArgs) return [.. argsList]; } - private static void SendMessageToProxy(IpcMessage message, LogExpertProxy proxy) + private static void SendMessageToProxy (IpcMessage message, LogExpertProxy proxy) { switch (message.Type) { case IpcMessageType.Load: { - var payLoad = message.Payload.ToObject(); + LoadPayload payLoad = message.Payload.ToObject(); if (CheckPayload(payLoad)) { proxy.LoadFiles([.. payLoad.Files]); } } + break; case IpcMessageType.NewWindow: { - var payLoad = message.Payload.ToObject(); + LoadPayload payLoad = message.Payload.ToObject(); if (CheckPayload(payLoad)) { proxy.NewWindow([.. payLoad.Files]); } } + break; case IpcMessageType.NewWindowOrLockedWindow: { - var payLoad = message.Payload.ToObject(); + LoadPayload payLoad = message.Payload.ToObject(); if (CheckPayload(payLoad)) { proxy.NewWindowOrLockedWindow([.. payLoad.Files]); } } + break; default: _logger.Error($"Unknown IPC Message Type {message.Type}"); @@ -227,7 +231,7 @@ private static void SendMessageToProxy(IpcMessage message, LogExpertProxy proxy) } } - private static bool CheckPayload(LoadPayload payLoad) + private static bool CheckPayload (LoadPayload payLoad) { if (payLoad == null) { @@ -238,7 +242,7 @@ private static bool CheckPayload(LoadPayload payLoad) return true; } - private static void SendCommandToServer(string command) + private static void SendCommandToServer (string command) { using var client = new NamedPipeClientStream(".", PIPE_SERVER_NAME, PipeDirection.Out); @@ -266,7 +270,7 @@ private static void SendCommandToServer(string command) writer.WriteLine(command); } - private static async Task RunServerLoopAsync(Action onCommand, LogExpertProxy proxy, CancellationToken cancellationToken) + private static async Task RunServerLoopAsync (Action onCommand, LogExpertProxy proxy, CancellationToken cancellationToken) { while (cancellationToken.IsCancellationRequested == false) { @@ -301,7 +305,7 @@ private static async Task RunServerLoopAsync(Action } [STAThread] - private static void ShowUnhandledException(object exceptionObject) + private static void ShowUnhandledException (object exceptionObject) { var errorText = string.Empty; string stackTrace; @@ -330,7 +334,7 @@ private static void ShowUnhandledException(object exceptionObject) #region Events handler - private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) + private static void Application_ThreadException (object sender, ThreadExceptionEventArgs e) { _logger.Fatal(e); @@ -344,7 +348,7 @@ private static void Application_ThreadException(object sender, ThreadExceptionEv thread.Join(); } - private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + private static void CurrentDomain_UnhandledException (object sender, UnhandledExceptionEventArgs e) { _logger.Fatal(e);