-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathLogTabWindow.cs
More file actions
3057 lines (2597 loc) · 93.5 KB
/
LogTabWindow.cs
File metadata and controls
3057 lines (2597 loc) · 93.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.Versioning;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
using LogExpert.Core.Classes;
using LogExpert.Core.Classes.Columnizer;
using LogExpert.Core.Classes.Filter;
using LogExpert.Core.Classes.Persister;
using LogExpert.Core.Config;
using LogExpert.Core.Entities;
using LogExpert.Core.Enums;
using LogExpert.Core.EventArguments;
using LogExpert.Core.Interface;
using LogExpert.Dialogs;
using LogExpert.Entities;
using LogExpert.PluginRegistry.FileSystem;
using LogExpert.UI.Dialogs;
using LogExpert.UI.Entities;
using LogExpert.UI.Extensions;
using LogExpert.UI.Extensions.LogWindow;
using NLog;
using WeifenLuo.WinFormsUI.Docking;
namespace LogExpert.UI.Controls.LogTabWindow;
// Data shared over all LogTabWindow instances
//TODO: Can we get rid of this class?
[SupportedOSPlatform("windows")]
internal partial class LogTabWindow : Form, ILogTabWindow
{
#region Fields
private const int MAX_COLUMNIZER_HISTORY = 40;
private const int MAX_COLOR_HISTORY = 40;
private const int DIFF_MAX = 100;
private const int MAX_FILE_HISTORY = 10;
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly Icon _deadIcon;
private readonly Color _defaultTabColor = Color.FromArgb(255, 192, 192, 192);
private readonly Brush _dirtyLedBrush;
private readonly int _instanceNumber;
private readonly Brush[] _ledBrushes = new Brush[5];
private readonly Icon[,,,] _ledIcons = new Icon[6, 2, 4, 2];
private readonly Rectangle[] _leds = new Rectangle[5];
private readonly IList<LogWindow.LogWindow> _logWindowList = [];
private readonly Brush _offLedBrush;
private readonly bool _showInstanceNumbers;
private readonly string[] _startupFileNames;
private readonly EventWaitHandle _statusLineEventHandle = new AutoResetEvent(false);
private readonly EventWaitHandle _statusLineEventWakeupHandle = new ManualResetEvent(false);
private readonly Brush _syncLedBrush;
[SupportedOSPlatform("windows")]
private readonly StringFormat _tabStringFormat = new();
private readonly Brush[] _tailLedBrush = new Brush[3];
private BookmarkWindow _bookmarkWindow;
private LogWindow.LogWindow _currentLogWindow;
private bool _firstBookmarkWindowShow = true;
private Thread _ledThread;
//Settings settings;
private bool _shouldStop;
private bool _skipEvents;
private bool _wasMaximized;
#endregion
#region cTor
[SupportedOSPlatform("windows")]
public LogTabWindow (string[] fileNames, int instanceNumber, bool showInstanceNumbers, IConfigManager configManager)
{
AutoScaleDimensions = new SizeF(96F, 96F);
AutoScaleMode = AutoScaleMode.Dpi;
InitializeComponent();
ConfigManager = configManager;
//Fix MainMenu and externalToolsToolStrip.Location, if the location has unintentionally been changed in the designer
mainMenuStrip.Location = new Point(0, 0);
externalToolsToolStrip.Location = new Point(0, 54);
_startupFileNames = fileNames;
_instanceNumber = instanceNumber;
_showInstanceNumbers = showInstanceNumbers;
Load += OnLogTabWindowLoad;
configManager.Instance.ConfigChanged += OnConfigChanged;
HighlightGroupList = configManager.Settings.Preferences.HighlightGroupList;
Rectangle led = new(0, 0, 8, 2);
for (var i = 0; i < _leds.Length; ++i)
{
_leds[i] = led;
led.Offset(0, led.Height + 0);
}
var grayAlpha = 50;
_ledBrushes[0] = new SolidBrush(Color.FromArgb(255, 220, 0, 0));
_ledBrushes[1] = new SolidBrush(Color.FromArgb(255, 220, 220, 0));
_ledBrushes[2] = new SolidBrush(Color.FromArgb(255, 0, 220, 0));
_ledBrushes[3] = new SolidBrush(Color.FromArgb(255, 0, 220, 0));
_ledBrushes[4] = new SolidBrush(Color.FromArgb(255, 0, 220, 0));
_offLedBrush = new SolidBrush(Color.FromArgb(grayAlpha, 160, 160, 160));
_dirtyLedBrush = new SolidBrush(Color.FromArgb(255, 220, 0, 00));
_tailLedBrush[0] = new SolidBrush(Color.FromArgb(255, 50, 100, 250)); // Follow tail: blue-ish
_tailLedBrush[1] = new SolidBrush(Color.FromArgb(grayAlpha, 160, 160, 160)); // Don't follow tail: gray
_tailLedBrush[2] = new SolidBrush(Color.FromArgb(255, 220, 220, 0)); // Stop follow tail (trigger): yellow-ish
_syncLedBrush = new SolidBrush(Color.FromArgb(255, 250, 145, 30));
CreateIcons();
_tabStringFormat.LineAlignment = StringAlignment.Center;
_tabStringFormat.Alignment = StringAlignment.Near;
ToolStripControlHost host = new(checkBoxFollowTail);
host.Padding = new Padding(20, 0, 0, 0);
host.BackColor = Color.FromKnownColor(KnownColor.Transparent);
var index = buttonToolStrip.Items.IndexOfKey("toolStripButtonTail");
toolStripEncodingASCIIItem.Text = Encoding.ASCII.HeaderName;
toolStripEncodingANSIItem.Text = Encoding.Default.HeaderName;
toolStripEncodingISO88591Item.Text = Encoding.GetEncoding("iso-8859-1").HeaderName;
toolStripEncodingUTF8Item.Text = Encoding.UTF8.HeaderName;
toolStripEncodingUTF16Item.Text = Encoding.Unicode.HeaderName;
if (index != -1)
{
buttonToolStrip.Items.RemoveAt(index);
buttonToolStrip.Items.Insert(index, host);
}
dragControlDateTime.Visible = false;
loadProgessBar.Visible = false;
// get a reference to the current assembly
var a = Assembly.GetExecutingAssembly();
// get a list of resource names from the manifest
var resNames = a.GetManifestResourceNames();
var bmp = Resources.Deceased;
_deadIcon = Icon.FromHandle(bmp.GetHicon());
bmp.Dispose();
Closing += OnLogTabWindowClosing;
InitToolWindows();
}
#endregion
#region Delegates
private delegate void AddFileTabsDelegate (string[] fileNames);
private delegate void ExceptionFx ();
private delegate void FileNotFoundDelegate (LogWindow.LogWindow logWin);
private delegate void FileRespawnedDelegate (LogWindow.LogWindow logWin);
public delegate void HighlightSettingsChangedEventHandler (object sender, EventArgs e);
private delegate void LoadMultiFilesDelegate (string[] fileName, EncodingOptions encodingOptions);
private delegate void SetColumnizerFx (ILogLineColumnizer columnizer);
private delegate void SetTabIconDelegate (LogWindow.LogWindow logWindow, Icon icon);
#endregion
#region Events
public event HighlightSettingsChangedEventHandler HighlightSettingsChanged;
#endregion
#region Properties
[SupportedOSPlatform("windows")]
public LogWindow.LogWindow CurrentLogWindow
{
get => _currentLogWindow;
set => ChangeCurrentLogWindow(value);
}
public SearchParams SearchParams { get; private set; } = new SearchParams();
public Preferences Preferences => ConfigManager.Settings.Preferences;
public List<HighlightGroup> HighlightGroupList { get; private set; } = [];
//public Settings Settings
//{
// get { return ConfigManager.Settings; }
//}
public ILogExpertProxy LogExpertProxy { get; set; }
public IConfigManager ConfigManager { get; }
#endregion
#region Internals
internal HighlightGroup FindHighlightGroup (string groupName)
{
lock (HighlightGroupList)
{
foreach (var group in HighlightGroupList)
{
if (group.GroupName.Equals(groupName, StringComparison.Ordinal))
{
return group;
}
}
return null;
}
}
#endregion
private class LogWindowData
{
#region Fields
// public MdiTabControl.TabPage tabPage;
public Color Color { get; set; } = Color.FromKnownColor(KnownColor.Gray);
public int DiffSum { get; set; }
public bool Dirty { get; set; }
// tailState:
/// <summary>
/// 0 = on<br></br>
/// 1 = off<br></br>
/// 2 = off by Trigger<br></br>
/// </summary>
public int TailState { get; set; }
public ToolTip ToolTip { get; set; }
/// <summary>
/// 0 = off<br></br>
/// 1 = timeSynced
/// </summary>
public int SyncMode { get; set; }
#endregion
}
#region Public methods
[SupportedOSPlatform("windows")]
public LogWindow.LogWindow AddTempFileTab (string fileName, string title)
{
return AddFileTab(fileName, true, title, false, null);
}
[SupportedOSPlatform("windows")]
public LogWindow.LogWindow AddFilterTab (FilterPipe pipe, string title, ILogLineColumnizer preProcessColumnizer)
{
var logWin = AddFileTab(pipe.FileName, true, title, false, preProcessColumnizer);
if (pipe.FilterParams.SearchText.Length > 0)
{
ToolTip tip = new(components);
tip.SetToolTip(logWin,
"Filter: \"" + pipe.FilterParams.SearchText + "\"" +
(pipe.FilterParams.IsInvert ? " (Invert match)" : "") +
(pipe.FilterParams.ColumnRestrict ? "\nColumn restrict" : "")
);
tip.AutomaticDelay = 10;
tip.AutoPopDelay = 5000;
var data = logWin.Tag as LogWindowData;
data.ToolTip = tip;
}
return logWin;
}
[SupportedOSPlatform("windows")]
public LogWindow.LogWindow AddFileTabDeferred (string givenFileName, bool isTempFile, string title, bool forcePersistenceLoading, ILogLineColumnizer preProcessColumnizer)
{
return AddFileTab(givenFileName, isTempFile, title, forcePersistenceLoading, preProcessColumnizer, true);
}
[SupportedOSPlatform("windows")]
public LogWindow.LogWindow AddFileTab (string givenFileName, bool isTempFile, string title, bool forcePersistenceLoading, ILogLineColumnizer preProcessColumnizer, bool doNotAddToDockPanel = false)
{
var logFileName = FindFilenameForSettings(givenFileName);
var win = FindWindowForFile(logFileName);
if (win != null)
{
if (!isTempFile)
{
AddToFileHistory(givenFileName);
}
SelectTab(win);
return win;
}
EncodingOptions encodingOptions = new();
FillDefaultEncodingFromSettings(encodingOptions);
LogWindow.LogWindow logWindow = new(this, logFileName, isTempFile, forcePersistenceLoading, ConfigManager)
{
GivenFileName = givenFileName
};
if (preProcessColumnizer != null)
{
logWindow.ForceColumnizerForLoading(preProcessColumnizer);
}
if (isTempFile)
{
logWindow.TempTitleName = title;
encodingOptions.Encoding = new UnicodeEncoding(false, false);
}
AddLogWindow(logWindow, title, doNotAddToDockPanel);
if (!isTempFile)
{
AddToFileHistory(givenFileName);
}
var data = logWindow.Tag as LogWindowData;
data.Color = _defaultTabColor;
SetTabColor(logWindow, _defaultTabColor);
//data.tabPage.BorderColor = this.defaultTabBorderColor;
if (!isTempFile)
{
foreach (var colorEntry in ConfigManager.Settings.FileColors)
{
if (colorEntry.FileName.ToUpperInvariant().Equals(logFileName.ToUpperInvariant(), StringComparison.Ordinal))
{
data.Color = colorEntry.Color;
SetTabColor(logWindow, colorEntry.Color);
break;
}
}
}
if (!isTempFile)
{
SetTooltipText(logWindow, logFileName);
}
if (givenFileName.EndsWith(".lxp", StringComparison.Ordinal))
{
logWindow.ForcedPersistenceFileName = givenFileName;
}
// this.BeginInvoke(new LoadFileDelegate(logWindow.LoadFile), new object[] { logFileName, encoding });
Task.Run(() => logWindow.LoadFile(logFileName, encodingOptions));
return logWindow;
}
[SupportedOSPlatform("windows")]
public LogWindow.LogWindow AddMultiFileTab (string[] fileNames)
{
if (fileNames.Length < 1)
{
return null;
}
LogWindow.LogWindow logWindow = new(this, fileNames[^1], false, false, ConfigManager);
AddLogWindow(logWindow, fileNames[^1], false);
multiFileToolStripMenuItem.Checked = true;
multiFileEnabledStripMenuItem.Checked = true;
EncodingOptions encodingOptions = new();
FillDefaultEncodingFromSettings(encodingOptions);
BeginInvoke(new LoadMultiFilesDelegate(logWindow.LoadFilesAsMulti), fileNames, encodingOptions);
AddToFileHistory(fileNames[0]);
return logWindow;
}
[SupportedOSPlatform("windows")]
public void LoadFiles (string[] fileNames)
{
Invoke(new AddFileTabsDelegate(AddFileTabs), [fileNames]);
}
[SupportedOSPlatform("windows")]
public void OpenSearchDialog ()
{
if (CurrentLogWindow == null)
{
return;
}
SearchDialog dlg = new();
AddOwnedForm(dlg);
dlg.TopMost = TopMost;
SearchParams.HistoryList = ConfigManager.Settings.SearchHistoryList;
dlg.SearchParams = SearchParams;
var res = dlg.ShowDialog();
if (res == DialogResult.OK && dlg.SearchParams != null && !string.IsNullOrWhiteSpace(dlg.SearchParams.SearchText))
{
SearchParams = dlg.SearchParams;
SearchParams.IsFindNext = false;
CurrentLogWindow.StartSearch();
}
}
public ILogLineColumnizer GetColumnizerHistoryEntry (string fileName)
{
var entry = FindColumnizerHistoryEntry(fileName);
if (entry != null)
{
foreach (var columnizer in PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers)
{
if (columnizer.GetName().Equals(entry.ColumnizerName, StringComparison.Ordinal))
{
return columnizer;
}
}
ConfigManager.Settings.ColumnizerHistoryList.Remove(entry); // no valid name -> remove entry
}
return null;
}
public void SwitchTab (bool shiftPressed)
{
var index = dockPanel.Contents.IndexOf(dockPanel.ActiveContent);
if (shiftPressed)
{
index--;
if (index < 0)
{
index = dockPanel.Contents.Count - 1;
}
if (index < 0)
{
return;
}
}
else
{
index++;
if (index >= dockPanel.Contents.Count)
{
index = 0;
}
}
if (index < dockPanel.Contents.Count)
{
(dockPanel.Contents[index] as DockContent).Activate();
}
}
public void ScrollAllTabsToTimestamp (DateTime timestamp, LogWindow.LogWindow senderWindow)
{
lock (_logWindowList)
{
foreach (var logWindow in _logWindowList)
{
if (logWindow != senderWindow)
{
if (logWindow.ScrollToTimestamp(timestamp, false, false))
{
ShowLedPeak(logWindow);
}
}
}
}
}
public ILogLineColumnizer FindColumnizerByFileMask (string fileName)
{
foreach (var entry in ConfigManager.Settings.Preferences.ColumnizerMaskList)
{
if (entry.Mask != null)
{
try
{
if (Regex.IsMatch(fileName, entry.Mask))
{
var columnizer = ColumnizerPicker.FindColumnizerByName(entry.ColumnizerName, PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers);
return columnizer;
}
}
catch (ArgumentException e)
{
_logger.Error(e, "RegEx-error while finding columnizer: ");
// occurs on invalid regex patterns
}
}
}
return null;
}
public HighlightGroup FindHighlightGroupByFileMask (string fileName)
{
foreach (var entry in ConfigManager.Settings.Preferences.HighlightMaskList)
{
if (entry.Mask != null)
{
try
{
if (Regex.IsMatch(fileName, entry.Mask))
{
var group = FindHighlightGroup(entry.HighlightGroupName);
return group;
}
}
catch (ArgumentException e)
{
_logger.Error(e, "RegEx-error while finding columnizer: ");
// occurs on invalid regex patterns
}
}
}
return null;
}
public void SelectTab (ILogWindow logWindow)
{
logWindow.Activate();
}
[SupportedOSPlatform("windows")]
public void SetForeground ()
{
NativeMethods.SetForegroundWindow(Handle);
if (WindowState == FormWindowState.Minimized)
{
if (_wasMaximized)
{
WindowState = FormWindowState.Maximized;
}
else
{
WindowState = FormWindowState.Normal;
}
}
}
// called from LogWindow when follow tail was changed
[SupportedOSPlatform("windows")]
public void FollowTailChanged (LogWindow.LogWindow logWindow, bool isEnabled, bool offByTrigger)
{
if (logWindow.Tag is not LogWindowData data)
{
return;
}
if (isEnabled)
{
data.TailState = 0;
}
else
{
data.TailState = offByTrigger ? 2 : 1;
}
if (Preferences.ShowTailState)
{
var icon = GetIcon(data.DiffSum, data);
BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWindow, icon);
}
}
[SupportedOSPlatform("windows")]
public void NotifySettingsChanged (object sender, SettingsFlags flags)
{
if (sender != this)
{
NotifyWindowsForChangedPrefs(flags);
}
}
public IList<WindowFileEntry> GetListOfOpenFiles ()
{
IList<WindowFileEntry> list = [];
lock (_logWindowList)
{
foreach (var logWindow in _logWindowList)
{
list.Add(new WindowFileEntry(logWindow));
}
}
return list;
}
#endregion
#region Private Methods
/// <summary>
/// Creates a temp file with the text content of the clipboard and opens the temp file in a new tab.
/// </summary>
[SupportedOSPlatform("windows")]
private void PasteFromClipboard ()
{
if (Clipboard.ContainsText())
{
var text = Clipboard.GetText();
var fileName = Path.GetTempFileName();
using (FileStream fStream = new(fileName, FileMode.Append, FileAccess.Write, FileShare.Read))
using (StreamWriter writer = new(fStream, Encoding.Unicode))
{
writer.Write(text);
writer.Close();
}
var title = "Clipboard";
var logWindow = AddTempFileTab(fileName, title);
if (logWindow.Tag is LogWindowData data)
{
SetTooltipText(logWindow, "Pasted on " + DateTime.Now);
}
}
}
[SupportedOSPlatform("windows")]
private void InitToolWindows ()
{
InitBookmarkWindow();
}
[SupportedOSPlatform("windows")]
private void DestroyToolWindows ()
{
DestroyBookmarkWindow();
}
[SupportedOSPlatform("windows")]
private void InitBookmarkWindow ()
{
_bookmarkWindow = new BookmarkWindow
{
HideOnClose = true,
ShowHint = DockState.DockBottom
};
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;
}
[SupportedOSPlatform("windows")]
private void DestroyBookmarkWindow ()
{
_bookmarkWindow.HideOnClose = false;
_bookmarkWindow.Close();
}
private void SaveLastOpenFilesList ()
{
ConfigManager.Settings.LastOpenFilesList.Clear();
foreach (DockContent content in dockPanel.Contents)
{
if (content is LogWindow.LogWindow logWin)
{
if (!logWin.IsTempFile)
{
ConfigManager.Settings.LastOpenFilesList.Add(logWin.GivenFileName);
}
}
}
}
[SupportedOSPlatform("windows")]
private void SaveWindowPosition ()
{
SuspendLayout();
if (WindowState == FormWindowState.Normal)
{
ConfigManager.Settings.AppBounds = Bounds;
ConfigManager.Settings.IsMaximized = false;
}
else
{
ConfigManager.Settings.AppBoundsFullscreen = Bounds;
ConfigManager.Settings.IsMaximized = true;
WindowState = FormWindowState.Normal;
ConfigManager.Settings.AppBounds = Bounds;
}
ResumeLayout();
}
private void SetTooltipText (LogWindow.LogWindow logWindow, string logFileName)
{
logWindow.ToolTipText = logFileName;
}
private void FillDefaultEncodingFromSettings (EncodingOptions encodingOptions)
{
if (ConfigManager.Settings.Preferences.DefaultEncoding != null)
{
try
{
encodingOptions.DefaultEncoding = Encoding.GetEncoding(ConfigManager.Settings.Preferences.DefaultEncoding);
}
catch (ArgumentException)
{
_logger.Warn(CultureInfo.InvariantCulture, "Encoding " + ConfigManager.Settings.Preferences.DefaultEncoding + " is not a valid encoding");
encodingOptions.DefaultEncoding = null;
}
}
}
[SupportedOSPlatform("windows")]
private void AddFileTabs (string[] fileNames)
{
foreach (var fileName in fileNames)
{
if (!string.IsNullOrEmpty(fileName))
{
if (fileName.EndsWith(".lxj"))
{
LoadProject(fileName, false);
}
else
{
AddFileTab(fileName, false, null, false, null);
}
}
}
Activate();
}
[SupportedOSPlatform("windows")]
private void AddLogWindow (LogWindow.LogWindow logWindow, string title, bool doNotAddToPanel)
{
logWindow.CloseButton = true;
logWindow.TabPageContextMenuStrip = tabContextMenuStrip;
SetTooltipText(logWindow, title);
logWindow.DockAreas = DockAreas.Document | DockAreas.Float;
if (!doNotAddToPanel)
{
logWindow.Show(dockPanel);
}
LogWindowData data = new()
{
DiffSum = 0
};
logWindow.Tag = data;
lock (_logWindowList)
{
_logWindowList.Add(logWindow);
}
logWindow.FileSizeChanged += OnFileSizeChanged;
logWindow.TailFollowed += OnTailFollowed;
logWindow.Disposed += OnLogWindowDisposed;
logWindow.FileNotFound += OnLogWindowFileNotFound;
logWindow.FileRespawned += OnLogWindowFileRespawned;
logWindow.FilterListChanged += OnLogWindowFilterListChanged;
logWindow.CurrentHighlightGroupChanged += OnLogWindowCurrentHighlightGroupChanged;
logWindow.SyncModeChanged += OnLogWindowSyncModeChanged;
logWindow.Visible = true;
}
[SupportedOSPlatform("windows")]
private void DisconnectEventHandlers (LogWindow.LogWindow logWindow)
{
logWindow.FileSizeChanged -= OnFileSizeChanged;
logWindow.TailFollowed -= OnTailFollowed;
logWindow.Disposed -= OnLogWindowDisposed;
logWindow.FileNotFound -= OnLogWindowFileNotFound;
logWindow.FileRespawned -= OnLogWindowFileRespawned;
logWindow.FilterListChanged -= OnLogWindowFilterListChanged;
logWindow.CurrentHighlightGroupChanged -= OnLogWindowCurrentHighlightGroupChanged;
logWindow.SyncModeChanged -= OnLogWindowSyncModeChanged;
var data = logWindow.Tag as LogWindowData;
//data.tabPage.MouseClick -= tabPage_MouseClick;
//data.tabPage.TabDoubleClick -= tabPage_TabDoubleClick;
//data.tabPage.ContextMenuStrip = null;
//data.tabPage = null;
}
[SupportedOSPlatform("windows")]
private void AddToFileHistory (string fileName)
{
bool FindName (string s) => s.ToUpperInvariant().Equals(fileName.ToUpperInvariant(), StringComparison.Ordinal);
var index = ConfigManager.Settings.FileHistoryList.FindIndex(FindName);
if (index != -1)
{
ConfigManager.Settings.FileHistoryList.RemoveAt(index);
}
ConfigManager.Settings.FileHistoryList.Insert(0, fileName);
while (ConfigManager.Settings.FileHistoryList.Count > MAX_FILE_HISTORY)
{
ConfigManager.Settings.FileHistoryList.RemoveAt(ConfigManager.Settings.FileHistoryList.Count - 1);
}
ConfigManager.Save(SettingsFlags.FileHistory);
FillHistoryMenu();
}
[SupportedOSPlatform("windows")]
private LogWindow.LogWindow FindWindowForFile (string fileName)
{
lock (_logWindowList)
{
foreach (var logWindow in _logWindowList)
{
if (logWindow.FileName.ToUpperInvariant().Equals(fileName.ToUpperInvariant(), StringComparison.Ordinal))
{
return logWindow;
}
}
}
return null;
}
/// <summary>
/// Checks if the file name is a settings file. If so, the contained logfile name
/// is returned. If not, the given file name is returned unchanged.
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
private string FindFilenameForSettings (string fileName)
{
if (fileName.EndsWith(".lxp", StringComparison.InvariantCulture))
{
var persistenceData = Persister.Load(fileName);
if (persistenceData == null)
{
return fileName;
}
if (!string.IsNullOrEmpty(persistenceData.FileName))
{
var fs = PluginRegistry.PluginRegistry.Instance.FindFileSystemForUri(persistenceData.FileName);
if (fs != null && !fs.GetType().Equals(typeof(LocalFileSystem)))
{
return persistenceData.FileName;
}
// On relative paths the URI check (and therefore the file system plugin check) will fail.
// So fs == null and fs == LocalFileSystem are handled here like normal files.
if (Path.IsPathRooted(persistenceData.FileName))
{
return persistenceData.FileName;
}
// handle relative paths in .lxp files
var dir = Path.GetDirectoryName(fileName);
return Path.Combine(dir, persistenceData.FileName);
}
}
return fileName;
}
[SupportedOSPlatform("windows")]
private void FillHistoryMenu ()
{
ToolStripDropDown strip = new ToolStripDropDownMenu();
foreach (var file in ConfigManager.Settings.FileHistoryList)
{
ToolStripItem item = new ToolStripMenuItem(file);
strip.Items.Add(item);
}
strip.ItemClicked += OnHistoryItemClicked;
strip.MouseUp += OnStripMouseUp;
lastUsedToolStripMenuItem.DropDown = strip;
}
[SupportedOSPlatform("windows")]
private void RemoveLogWindow (LogWindow.LogWindow logWindow)
{
lock (_logWindowList)
{
_logWindowList.Remove(logWindow);
}
DisconnectEventHandlers(logWindow);
}
[SupportedOSPlatform("windows")]
private void RemoveAndDisposeLogWindow (LogWindow.LogWindow logWindow, bool dontAsk)
{
if (CurrentLogWindow == logWindow)
{
ChangeCurrentLogWindow(null);
}
lock (_logWindowList)
{
_logWindowList.Remove(logWindow);
}
logWindow.Close(dontAsk);
}
[SupportedOSPlatform("windows")]
private void ShowHighlightSettingsDialog ()
{
HighlightDialog dlg = new(ConfigManager)
{
KeywordActionList = PluginRegistry.PluginRegistry.Instance.RegisteredKeywordActions,
Owner = this,
TopMost = TopMost,
HighlightGroupList = HighlightGroupList,
PreSelectedGroupName = groupsComboBoxHighlightGroups.Text
};
var res = dlg.ShowDialog();
if (res == DialogResult.OK)
{
HighlightGroupList = dlg.HighlightGroupList;
FillHighlightComboBox();
ConfigManager.Settings.Preferences.HighlightGroupList = HighlightGroupList;
ConfigManager.Save(SettingsFlags.HighlightSettings);
OnHighlightSettingsChanged();
}
}
[SupportedOSPlatform("windows")]
private void FillHighlightComboBox ()
{
var currentGroupName = groupsComboBoxHighlightGroups.Text;
groupsComboBoxHighlightGroups.Items.Clear();
foreach (var group in HighlightGroupList)
{
groupsComboBoxHighlightGroups.Items.Add(group.GroupName);
if (group.GroupName.Equals(currentGroupName, StringComparison.Ordinal))
{
groupsComboBoxHighlightGroups.Text = group.GroupName;
}
}
}
[SupportedOSPlatform("windows")]
private void OpenFileDialog ()
{
OpenFileDialog openFileDialog = new();
if (CurrentLogWindow != null)
{
FileInfo info = new(CurrentLogWindow.FileName);
openFileDialog.InitialDirectory = info.DirectoryName;