diff --git a/src/LogExpert.Core/Interface/ILogTabWindow.cs b/src/LogExpert.Core/Interface/ILogTabWindow.cs index 822d464d..a1c35694 100644 --- a/src/LogExpert.Core/Interface/ILogTabWindow.cs +++ b/src/LogExpert.Core/Interface/ILogTabWindow.cs @@ -3,12 +3,38 @@ namespace LogExpert.Core.Interface; //TODO: Add documentation public interface ILogTabWindow { + /// + /// + /// ILogExpertProxy LogExpertProxy { get; set; } + + /// + /// + /// bool IsDisposed { get; } void Activate (); + object Invoke (Delegate method, params object?[]? objects); + + /// + /// Load given files into a new or current Logwindow + /// + /// void LoadFiles (string[] fileNames); + + /// + /// Show an error message, if this is the only allowed instance, and the error message should be displayed + /// + void ShowOnlyOneInstanceError (); + + /// + /// Set the current Logwindow to be first in line + /// void SetForeground (); + + /// + /// Show the current logwindow + /// void Show (); } \ No newline at end of file diff --git a/src/LogExpert.UI/Dialogs/AboutBox.cs b/src/LogExpert.UI/Dialogs/AboutBox.cs index 37afa730..f4edc80e 100644 --- a/src/LogExpert.UI/Dialogs/AboutBox.cs +++ b/src/LogExpert.UI/Dialogs/AboutBox.cs @@ -23,6 +23,11 @@ public AboutBox () { InitializeComponent(); + SuspendLayout(); + + AutoScaleDimensions = new SizeF(96F, 96F); + AutoScaleMode = AutoScaleMode.Dpi; + LoadResources(); usedComponentsDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; _assembly = Assembly.GetExecutingAssembly(); @@ -33,7 +38,10 @@ public AboutBox () labelCopyright.Text = AssemblyCopyright; var link = "https://github.com/LogExperts/LogExpert"; _ = linkLabelURL.Links.Add(new LinkLabel.Link(0, link.Length, link)); + LoadUsedComponents(); + + ResumeLayout(); } //Name, Version, License, Download, Source diff --git a/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.Designer.cs b/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.Designer.cs index 6a07b9df..3057e1a2 100644 --- a/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.Designer.cs +++ b/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.Designer.cs @@ -1,4 +1,4 @@ -namespace LogExpert.Dialogs; +namespace LogExpert.Dialogs; partial class AllowOnlyOneInstanceErrorDialog { @@ -26,67 +26,63 @@ protected override void Dispose(bool disposing) /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() + private void InitializeComponent () { - this.checkBoxIgnoreMessage = new System.Windows.Forms.CheckBox(); - this.buttonOk = new System.Windows.Forms.Button(); - this.labelErrorText = new System.Windows.Forms.Label(); - this.SuspendLayout(); + checkBoxIgnoreMessage = new CheckBox(); + buttonOk = new Button(); + labelErrorText = new Label(); + SuspendLayout(); // // checkBoxIgnoreMessage // - this.checkBoxIgnoreMessage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.checkBoxIgnoreMessage.AutoSize = true; - this.checkBoxIgnoreMessage.Location = new System.Drawing.Point(9, 56); - this.checkBoxIgnoreMessage.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); - this.checkBoxIgnoreMessage.Name = "checkBoxIgnoreMessage"; - this.checkBoxIgnoreMessage.Size = new System.Drawing.Size(177, 17); - this.checkBoxIgnoreMessage.TabIndex = 0; - this.checkBoxIgnoreMessage.Text = "Show this message only once\\?"; - this.checkBoxIgnoreMessage.UseVisualStyleBackColor = true; + checkBoxIgnoreMessage.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + checkBoxIgnoreMessage.AutoSize = true; + checkBoxIgnoreMessage.Location = new Point(9, 72); + checkBoxIgnoreMessage.Margin = new Padding(2); + checkBoxIgnoreMessage.Name = "checkBoxIgnoreMessage"; + checkBoxIgnoreMessage.Size = new Size(186, 19); + checkBoxIgnoreMessage.TabIndex = 0; + checkBoxIgnoreMessage.Text = "Show this message only once?"; + checkBoxIgnoreMessage.UseVisualStyleBackColor = true; // // buttonOk // - this.buttonOk.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK; - this.buttonOk.Location = new System.Drawing.Point(209, 53); - this.buttonOk.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); - this.buttonOk.Name = "buttonOk"; - this.buttonOk.Size = new System.Drawing.Size(74, 23); - this.buttonOk.TabIndex = 1; - this.buttonOk.Text = "Ok"; - this.buttonOk.UseVisualStyleBackColor = true; - this.buttonOk.Click += new System.EventHandler(this.OnButtonOkClick); + buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonOk.DialogResult = DialogResult.OK; + buttonOk.Location = new Point(209, 71); + buttonOk.Margin = new Padding(2); + buttonOk.Name = "buttonOk"; + buttonOk.Size = new Size(104, 23); + buttonOk.TabIndex = 1; + buttonOk.Text = "Ok"; + buttonOk.UseVisualStyleBackColor = true; + buttonOk.Click += OnButtonOkClick; // // labelErrorText // - this.labelErrorText.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.labelErrorText.AutoEllipsis = true; - this.labelErrorText.Location = new System.Drawing.Point(9, 8); - this.labelErrorText.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.labelErrorText.Name = "labelErrorText"; - this.labelErrorText.Size = new System.Drawing.Size(273, 43); - this.labelErrorText.TabIndex = 2; - this.labelErrorText.Text = "Only one instance allowed, uncheck \\\"View Settings => Allow only 1 Instances\\\" to" + -" start multiple instances!"; + labelErrorText.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + labelErrorText.AutoEllipsis = true; + labelErrorText.Location = new Point(9, 8); + labelErrorText.Margin = new Padding(2, 0, 2, 0); + labelErrorText.Name = "labelErrorText"; + labelErrorText.Size = new Size(303, 43); + labelErrorText.TabIndex = 2; + labelErrorText.Text = "Only one instance allowed, uncheck \"View Settings => Allow only 1 Instances\" to start multiple instances!"; // // AllowOnlyOneInstanceErrorDialog // - this.ClientSize = new System.Drawing.Size(293, 84); - this.Controls.Add(this.labelErrorText); - this.Controls.Add(this.buttonOk); - this.Controls.Add(this.checkBoxIgnoreMessage); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); - this.MaximizeBox = false; - this.Name = "AllowOnlyOneInstanceErrorDialog"; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.Text = "AllowOnlyOneInstanceErrorDialog"; - this.ResumeLayout(false); - this.PerformLayout(); + ClientSize = new Size(323, 102); + Controls.Add(labelErrorText); + Controls.Add(buttonOk); + Controls.Add(checkBoxIgnoreMessage); + FormBorderStyle = FormBorderStyle.FixedToolWindow; + Margin = new Padding(2); + MaximizeBox = false; + Name = "AllowOnlyOneInstanceErrorDialog"; + SizeGripStyle = SizeGripStyle.Hide; + Text = "Allow only one instance error dialog"; + ResumeLayout(false); + PerformLayout(); } diff --git a/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.cs b/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.cs index 3c046848..617d671e 100644 --- a/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.cs +++ b/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.cs @@ -10,7 +10,15 @@ public partial class AllowOnlyOneInstanceErrorDialog : Form public AllowOnlyOneInstanceErrorDialog () { InitializeComponent(); + + SuspendLayout(); + + AutoScaleDimensions = new SizeF(96F, 96F); + AutoScaleMode = AutoScaleMode.Dpi; + SetText(); + + ResumeLayout(); } private void SetText () @@ -18,7 +26,7 @@ private void SetText () labelErrorText.Text = @"Only one instance allowed, uncheck ""View Settings => Allow only 1 Instances"" to start multiple instances!"; } - private void OnButtonOkClick (object sender, System.EventArgs e) + private void OnButtonOkClick (object sender, EventArgs e) { DoNotShowThisMessageAgain = checkBoxIgnoreMessage.Checked; } diff --git a/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.resx b/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.resx new file mode 100644 index 00000000..8b2ff64a --- /dev/null +++ b/src/LogExpert.UI/Dialogs/AllowOnlyOneInstanceErrorDialog.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindow.cs b/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindow.cs index b75a674c..16f9d865 100644 --- a/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindow.cs +++ b/src/LogExpert.UI/Dialogs/LogTabWindow/LogTabWindow.cs @@ -141,10 +141,11 @@ public LogTabWindow (string[] fileNames, int instanceNumber, bool showInstanceNu _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); + ToolStripControlHost host = new(checkBoxFollowTail) + { + Padding = new Padding(20, 0, 0, 0), + BackColor = Color.FromKnownColor(KnownColor.Transparent) + }; var index = buttonToolStrip.Items.IndexOfKey("toolStripButtonTail"); @@ -169,7 +170,7 @@ public LogTabWindow (string[] fileNames, int instanceNumber, bool showInstanceNu // get a list of resource names from the manifest var resNames = a.GetManifestResourceNames(); - Bitmap bmp = Resources.Deceased; + var bmp = Resources.Deceased; _deadIcon = Icon.FromHandle(bmp.GetHicon()); bmp.Dispose(); Closing += OnLogTabWindowClosing; @@ -189,8 +190,6 @@ public LogTabWindow (string[] fileNames, int instanceNumber, bool showInstanceNu 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); @@ -201,7 +200,7 @@ public LogTabWindow (string[] fileNames, int instanceNumber, bool showInstanceNu #region Events - public event HighlightSettingsChangedEventHandler HighlightSettingsChanged; + public event EventHandler HighlightSettingsChanged; #endregion @@ -226,6 +225,7 @@ public LogWindow.LogWindow CurrentLogWindow //} public ILogExpertProxy LogExpertProxy { get; set; } + public IConfigManager ConfigManager { get; } #endregion @@ -236,7 +236,7 @@ internal HighlightGroup FindHighlightGroup (string groupName) { lock (HighlightGroupList) { - foreach (HighlightGroup group in HighlightGroupList) + foreach (var group in HighlightGroupList) { if (group.GroupName.Equals(groupName, StringComparison.Ordinal)) { @@ -386,7 +386,7 @@ public LogWindow.LogWindow AddFileTab (string givenFileName, bool isTempFile, st } // this.BeginInvoke(new LoadFileDelegate(logWindow.LoadFile), new object[] { logFileName, encoding }); - Task.Run(() => logWindow.LoadFile(logFileName, encodingOptions)); + _ = Task.Run(() => logWindow.LoadFile(logFileName, encodingOptions)); return logWindow; } @@ -404,7 +404,7 @@ public LogWindow.LogWindow AddMultiFileTab (string[] fileNames) multiFileEnabledStripMenuItem.Checked = true; EncodingOptions encodingOptions = new(); FillDefaultEncodingFromSettings(encodingOptions); - BeginInvoke(new LoadMultiFilesDelegate(logWindow.LoadFilesAsMulti), fileNames, encodingOptions); + _ = BeginInvoke(new LoadMultiFilesDelegate(logWindow.LoadFilesAsMulti), fileNames, encodingOptions); AddToFileHistory(fileNames[0]); return logWindow; } @@ -412,7 +412,20 @@ public LogWindow.LogWindow AddMultiFileTab (string[] fileNames) [SupportedOSPlatform("windows")] public void LoadFiles (string[] fileNames) { - Invoke(new AddFileTabsDelegate(AddFileTabs), [fileNames]); + _ = Invoke(new AddFileTabsDelegate(AddFileTabs), [fileNames]); + } + + public void ShowOnlyOneInstanceError () + { + if (lockInstanceToolStripMenuItem.Checked && ConfigManager.Instance.Settings.Preferences.ShowErrorMessageAllowOnlyOneInstances) + { + using AllowOnlyOneInstanceErrorDialog a = new(); + if (a.ShowDialog() == DialogResult.OK) + { + ConfigManager.Instance.Settings.Preferences.ShowErrorMessageAllowOnlyOneInstances = !a.DoNotShowThisMessageAgain; + ConfigManager.Instance.Save(SettingsFlags.All); + } + } } [SupportedOSPlatform("windows")] @@ -450,7 +463,7 @@ public ILogLineColumnizer GetColumnizerHistoryEntry (string fileName) } } - ConfigManager.Settings.ColumnizerHistoryList.Remove(entry); // no valid name -> remove entry + _ = ConfigManager.Settings.ColumnizerHistoryList.Remove(entry); // no valid name -> remove entry } return null; @@ -562,7 +575,7 @@ public void SelectTab (ILogWindow logWindow) [SupportedOSPlatform("windows")] public void SetForeground () { - NativeMethods.SetForegroundWindow(Handle); + _ = NativeMethods.SetForegroundWindow(Handle); if (WindowState == FormWindowState.Minimized) { if (_wasMaximized) @@ -597,7 +610,7 @@ public void FollowTailChanged (LogWindow.LogWindow logWindow, bool isEnabled, bo if (Preferences.ShowTailState) { var icon = GetIcon(data.DiffSum, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWindow, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWindow, icon); } } @@ -762,7 +775,7 @@ private void AddFileTabs (string[] fileNames) } else { - AddFileTab(fileName, false, null, false, null); + _ = AddFileTab(fileName, false, null, false, null); } } } @@ -915,7 +928,7 @@ private void FillHistoryMenu () foreach (var file in ConfigManager.Settings.FileHistoryList) { ToolStripItem item = new ToolStripMenuItem(file); - strip.Items.Add(item); + _ = strip.Items.Add(item); } strip.ItemClicked += OnHistoryItemClicked; @@ -928,7 +941,7 @@ private void RemoveLogWindow (LogWindow.LogWindow logWindow) { lock (_logWindowList) { - _logWindowList.Remove(logWindow); + _ = _logWindowList.Remove(logWindow); } DisconnectEventHandlers(logWindow); @@ -944,7 +957,7 @@ private void RemoveAndDisposeLogWindow (LogWindow.LogWindow logWindow, bool dont lock (_logWindowList) { - _logWindowList.Remove(logWindow); + _ = _logWindowList.Remove(logWindow); } logWindow.Close(dontAsk); @@ -981,7 +994,7 @@ private void FillHighlightComboBox () groupsComboBoxHighlightGroups.Items.Clear(); foreach (var group in HighlightGroupList) { - groupsComboBoxHighlightGroups.Items.Add(group.GroupName); + _ = groupsComboBoxHighlightGroups.Items.Add(group.GroupName); if (group.GroupName.Equals(currentGroupName, StringComparison.Ordinal)) { groupsComboBoxHighlightGroups.Text = group.GroupName; @@ -1050,7 +1063,7 @@ private void LoadFiles (string[] names, bool invertLogic) return; } - AddFileTab(names[0], false, null, false, null); + _ = AddFileTab(names[0], false, null, false, null); return; } @@ -1089,7 +1102,7 @@ private void LoadFiles (string[] names, bool invertLogic) } else { - AddMultiFileTab(names); + _ = AddMultiFileTab(names); } } @@ -1283,7 +1296,7 @@ private void ProgressBarUpdateWorker (ProgressEventArgs e) _logger.Error(ex, "Error during ProgressBarUpdateWorker value {0}, min {1}, max {2}, visible {3}", e.Value, e.MinValue, e.MaxValue, e.Visible); } - Invoke(new System.Windows.Forms.MethodInvoker(statusStrip.Refresh)); + _ = Invoke(new System.Windows.Forms.MethodInvoker(statusStrip.Refresh)); } } @@ -1304,7 +1317,7 @@ private void StatusLineEventWorker (StatusLineEventArgs e) labelCurrentLine.Size = TextRenderer.MeasureText(labelCurrentLine.Text, labelCurrentLine.Font); if (statusStrip.InvokeRequired) { - statusStrip.BeginInvoke(new System.Windows.Forms.MethodInvoker(statusStrip.Refresh)); + _ = statusStrip.BeginInvoke(new System.Windows.Forms.MethodInvoker(statusStrip.Refresh)); } else { @@ -1383,7 +1396,7 @@ private Icon CreateLedIcon (int level, bool dirty, int tailState, int syncMode) // a managed copy of icon. then the unmanaged win32 handle is destroyed var iconHandle = bmp.GetHicon(); var icon = Icon.FromHandle(iconHandle).Clone() as Icon; - NativeMethods.DestroyIcon(iconHandle); + _ = NativeMethods.DestroyIcon(iconHandle); gfx.Dispose(); bmp.Dispose(); @@ -1414,7 +1427,7 @@ private void CreateIcons () private void FileNotFound (LogWindow.LogWindow logWin) { var data = logWin.Tag as LogWindowData; - BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWin, _deadIcon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWin, _deadIcon); dragControlDateTime.Visible = false; } @@ -1423,7 +1436,7 @@ private void FileRespawned (LogWindow.LogWindow logWin) { var data = logWin.Tag as LogWindowData; var icon = GetIcon(0, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWin, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWin, icon); } [SupportedOSPlatform("windows")] @@ -1436,7 +1449,7 @@ private void ShowLedPeak (LogWindow.LogWindow logWin) } var icon = GetIcon(data.DiffSum, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWin, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWin, icon); } private int GetLevelFromDiff (int diff) @@ -1488,7 +1501,7 @@ private void LedThreadProc () } var icon = GetIcon(data.DiffSum, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWindow, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWindow, icon); } } } @@ -1507,11 +1520,15 @@ private void SetTabIcon (LogWindow.LogWindow logWindow, Icon icon) private Icon GetIcon (int diff, LogWindowData data) { - var icon = - _ledIcons[ - GetLevelFromDiff(diff), data.Dirty ? 1 : 0, Preferences.ShowTailState ? data.TailState : 3, - data.SyncMode - ]; + var icon = _ledIcons[GetLevelFromDiff(diff), + data.Dirty + ? 1 + : 0, + Preferences.ShowTailState + ? data.TailState + : 3, + data.SyncMode + ]; return icon; } @@ -1639,7 +1656,7 @@ private void SetTabIcons (Preferences preferences) { var data = logWindow.Tag as LogWindowData; var icon = GetIcon(data.DiffSum, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWindow, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), logWindow, icon); } } } @@ -1657,7 +1674,7 @@ private void SetToolIcon (ToolEntry entry, ToolStripItem item) ? ToolStripItemDisplayStyle.ImageAndText : ToolStripItemDisplayStyle.Image; - NativeMethods.DestroyIcon(icon.Handle); + _ = NativeMethods.DestroyIcon(icon.Handle); icon.Dispose(); } @@ -1726,7 +1743,7 @@ private void StartTool (string cmd, string args, bool sysoutPipe, string columni catch (Win32Exception e) { _logger.Error(e); - MessageBox.Show(e.Message); + _ = MessageBox.Show(e.Message); return; } @@ -1753,7 +1770,7 @@ private void StartTool (string cmd, string args, bool sysoutPipe, string columni catch (Exception e) { _logger.Error(e); - MessageBox.Show(e.Message); + _ = MessageBox.Show(e.Message); } } } @@ -1822,11 +1839,11 @@ private void LoadProject (string projectFileName, bool restoreLayout) { if (hasLayoutData) { - AddFileTabDeferred(fileName, false, null, true, null); + _ = AddFileTabDeferred(fileName, false, null, true, null); } else { - AddFileTab(fileName, false, null, true, null); + _ = AddFileTab(fileName, false, null, true, null); } } @@ -1856,8 +1873,8 @@ private void FillToolLauncherBar () 'U', 'V', 'W', 'X', 'Y', 'Z' ]; toolsToolStripMenuItem.DropDownItems.Clear(); - toolsToolStripMenuItem.DropDownItems.Add(configureToolStripMenuItem); - toolsToolStripMenuItem.DropDownItems.Add(configureToolStripSeparator); + _ = toolsToolStripMenuItem.DropDownItems.Add(configureToolStripMenuItem); + _ = toolsToolStripMenuItem.DropDownItems.Add(configureToolStripSeparator); externalToolsToolStrip.Items.Clear(); var num = 0; externalToolsToolStrip.SuspendLayout(); @@ -1872,7 +1889,7 @@ private void FillToolLauncherBar () }; SetToolIcon(tool, button); - externalToolsToolStrip.Items.Add(button); + _ = externalToolsToolStrip.Items.Add(button); } num++; @@ -1882,7 +1899,7 @@ private void FillToolLauncherBar () }; SetToolIcon(tool, menuItem); - toolsToolStripMenuItem.DropDownItems.Add(menuItem); + _ = toolsToolStripMenuItem.DropDownItems.Add(menuItem); } externalToolsToolStrip.ResumeLayout(); @@ -1924,7 +1941,7 @@ private string SaveLayout () using StreamReader r = new(memStream); dockPanel.SaveAsXml(memStream, Encoding.UTF8, true); - memStream.Seek(0, SeekOrigin.Begin); + _ = memStream.Seek(0, SeekOrigin.Begin); var resultXml = r.ReadToEnd(); r.Close(); @@ -1940,7 +1957,7 @@ private void RestoreLayout (string layoutXml) w.Write(layoutXml); w.Flush(); - memStream.Seek(0, SeekOrigin.Begin); + _ = memStream.Seek(0, SeekOrigin.Begin); dockPanel.LoadFromXml(memStream, DeserializeDockContent, true); } @@ -2070,7 +2087,7 @@ private void OnStripMouseUp (object sender, MouseEventArgs e) { if (sender is ToolStripDropDown dropDown) { - AddFileTab(dropDown.Text, false, null, false, null); + _ = AddFileTab(dropDown.Text, false, null, false, null); } } @@ -2078,7 +2095,7 @@ private void OnHistoryItemClicked (object sender, ToolStripItemClickedEventArgs { if (string.IsNullOrEmpty(e.ClickedItem.Text) == false) { - AddFileTab(e.ClickedItem.Text, false, null, false, null); + _ = AddFileTab(e.ClickedItem.Text, false, null, false, null); } } @@ -2128,7 +2145,7 @@ private void OnSelectFilterToolStripMenuItemClick (object sender, EventArgs e) { //logWindow.SetColumnizer(form.SelectedColumnizer); SetColumnizerFx fx = logWindow.ForceColumnizer; - logWindow.Invoke(fx, form.SelectedColumnizer); + _ = logWindow.Invoke(fx, form.SelectedColumnizer); SetColumnizerHistoryEntry(logWindow.FileName, form.SelectedColumnizer); } else @@ -2146,7 +2163,7 @@ private void OnSelectFilterToolStripMenuItemClick (object sender, EventArgs e) if (CurrentLogWindow.CurrentColumnizer.GetType() != form.SelectedColumnizer.GetType()) { SetColumnizerFx fx = CurrentLogWindow.ForceColumnizer; - CurrentLogWindow.Invoke(fx, form.SelectedColumnizer); + _ = CurrentLogWindow.Invoke(fx, form.SelectedColumnizer); SetColumnizerHistoryEntry(CurrentLogWindow.FileName, form.SelectedColumnizer); } @@ -2276,7 +2293,7 @@ private void OnAboutToolStripMenuItemClick (object sender, EventArgs e) TopMost = TopMost }; - aboutBox.ShowDialog(); + _ = aboutBox.ShowDialog(); } private void OnFilterToolStripMenuItemClick (object sender, EventArgs e) @@ -2294,7 +2311,7 @@ private void OnMultiFileToolStripMenuItemClick (object sender, EventArgs e) [SupportedOSPlatform("windows")] private void OnGuiStateUpdate (object sender, GuiStateArgs e) { - BeginInvoke(GuiStateUpdateWorker, e); + _ = BeginInvoke(GuiStateUpdateWorker, e); } private void OnColumnizerChanged (object sender, ColumnizerEventArgs e) @@ -2319,7 +2336,7 @@ private void OnBookmarkRemoved (object sender, EventArgs e) private void OnProgressBarUpdate (object sender, ProgressEventArgs e) { - Invoke(ProgressBarUpdateWorker, e); + _ = Invoke(ProgressBarUpdateWorker, e); } private void OnStatusLineEvent (object sender, StatusLineEventArgs e) @@ -2413,19 +2430,19 @@ private void OnFileSizeChanged (object sender, LogEventArgs e) data.Dirty = true; } var icon = GetIcon(diff, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), (LogWindow.LogWindow)sender, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), (LogWindow.LogWindow)sender, icon); } } } private void OnLogWindowFileNotFound (object sender, EventArgs e) { - Invoke(new FileNotFoundDelegate(FileNotFound), sender); + _ = Invoke(new FileNotFoundDelegate(FileNotFound), sender); } private void OnLogWindowFileRespawned (object sender, EventArgs e) { - Invoke(new FileRespawnedDelegate(FileRespawned), sender); + _ = Invoke(new FileRespawnedDelegate(FileRespawned), sender); } private void OnLogWindowFilterListChanged (object sender, FilterListChangedEventArgs e) @@ -2463,7 +2480,7 @@ private void OnTailFollowed (object sender, EventArgs e) var data = ((LogWindow.LogWindow)sender).Tag as LogWindowData; data.Dirty = false; var icon = GetIcon(data.DiffSum, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), (LogWindow.LogWindow)sender, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), (LogWindow.LogWindow)sender, icon); } } } @@ -2476,7 +2493,7 @@ private void OnLogWindowSyncModeChanged (object sender, SyncModeEventArgs e) var data = ((LogWindow.LogWindow)sender).Tag as LogWindowData; data.SyncMode = e.IsTimeSynced ? 1 : 0; var icon = GetIcon(data.DiffSum, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), (LogWindow.LogWindow)sender, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), (LogWindow.LogWindow)sender, icon); } else { @@ -2539,7 +2556,7 @@ private void OnReloadToolStripMenuItemClick (object sender, EventArgs e) { var data = CurrentLogWindow.Tag as LogWindowData; var icon = GetIcon(0, data); - BeginInvoke(new SetTabIconDelegate(SetTabIcon), CurrentLogWindow, icon); + _ = BeginInvoke(new SetTabIconDelegate(SetTabIcon), CurrentLogWindow, icon); CurrentLogWindow.Reload(); } } @@ -2562,7 +2579,7 @@ private void OnDateTimeDragControlValueDragged (object sender, EventArgs e) [SupportedOSPlatform("windows")] private void OnDateTimeDragControlValueChanged (object sender, EventArgs e) { - CurrentLogWindow?.ScrollToTimestamp(dragControlDateTime.DateTime, true, true); + _ = (CurrentLogWindow?.ScrollToTimestamp(dragControlDateTime.DateTime, true, true)); } [SupportedOSPlatform("windows")] @@ -2810,7 +2827,7 @@ private void OnFindInExplorerToolStripMenuItemClick (object sender, EventArgs e) explorer.StartInfo.FileName = "explorer.exe"; explorer.StartInfo.Arguments = "/e,/select," + logWindow.Title; explorer.StartInfo.UseShellExecute = false; - explorer.Start(); + _ = explorer.Start(); } private void TruncateFileToolStripMenuItem_Click (object sender, EventArgs e) @@ -2908,7 +2925,7 @@ private void OnThrowExceptionGUIThreadToolStripMenuItemClick (object sender, Eve private void OnThrowExceptionBackgroundThToolStripMenuItemClick (object sender, EventArgs e) { ExceptionFx fx = ThrowExceptionFx; - fx.BeginInvoke(null, null); + _ = fx.BeginInvoke(null, null); } private void OnThrowExceptionBackgroundThreadToolStripMenuItemClick (object sender, EventArgs e) @@ -2975,7 +2992,6 @@ private void OnLockInstanceToolStripMenuItemClick (object sender, EventArgs e) [SupportedOSPlatform("windows")] private void OnOptionToolStripMenuItemDropDownOpening (object sender, EventArgs e) { - lockInstanceToolStripMenuItem.Enabled = !ConfigManager.Settings.Preferences.AllowOnlyOneInstance; lockInstanceToolStripMenuItem.Checked = AbstractLogTabWindow.StaticData.CurrentLockedMainWindow == this; } diff --git a/src/LogExpert.UI/Dialogs/SettingsDialog.cs b/src/LogExpert.UI/Dialogs/SettingsDialog.cs index bdf5df26..f3976371 100644 --- a/src/LogExpert.UI/Dialogs/SettingsDialog.cs +++ b/src/LogExpert.UI/Dialogs/SettingsDialog.cs @@ -119,22 +119,28 @@ private void FillDialog () { radioButtonSessionSaveOwn.Checked = true; } + break; case SessionSaveLocation.SameDir: { radioButtonSessionSameDir.Checked = true; } + break; case SessionSaveLocation.DocumentsDir: { radioButtonsessionSaveDocuments.Checked = true; - break; + } + + break; case SessionSaveLocation.ApplicationStartupDir: { radioButtonSessionApplicationStartupDir.Checked = true; - break; + } + + break; } //overwrite preferences save location in portable mode to always be application startup directory @@ -210,10 +216,12 @@ private void SaveMultifileData () private void OnBtnToolClickInternal (TextBox textBox) { - OpenFileDialog dlg = new(); - dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); + OpenFileDialog dlg = new() + { + InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + }; - if (string.IsNullOrEmpty(textBox.Text) == false) + if (!string.IsNullOrEmpty(textBox.Text)) { FileInfo info = new(textBox.Text); if (info.Directory != null && info.Directory.Exists) @@ -277,9 +285,9 @@ private void FillColumnizerForToolsList (ComboBox comboBox, string columnizerNam { var selIndex = 0; comboBox.Items.Clear(); - IList columnizers = PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers; + var columnizers = PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers; - foreach (ILogLineColumnizer columnizer in columnizers) + foreach (var columnizer in columnizers) { var index = comboBox.Items.Add(columnizer.GetName()); if (columnizer.GetName().Equals(columnizerName, StringComparison.Ordinal)) @@ -301,35 +309,33 @@ private void FillColumnizerList () var comboColumn = (DataGridViewComboBoxColumn)dataGridViewColumnizer.Columns[1]; comboColumn.Items.Clear(); - var textColumn = (DataGridViewTextBoxColumn)dataGridViewColumnizer.Columns[0]; - - IList columnizers = PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers; + var columnizers = PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers; - foreach (ILogLineColumnizer columnizer in columnizers) + foreach (var columnizer in columnizers) { - comboColumn.Items.Add(columnizer.GetName()); + _ = comboColumn.Items.Add(columnizer.GetName()); } //comboColumn.DisplayMember = "Name"; //comboColumn.ValueMember = "Columnizer"; - foreach (ColumnizerMaskEntry maskEntry in Preferences.ColumnizerMaskList) + foreach (var maskEntry in Preferences.ColumnizerMaskList) { DataGridViewRow row = new(); - row.Cells.Add(new DataGridViewTextBoxCell()); + _ = row.Cells.Add(new DataGridViewTextBoxCell()); DataGridViewComboBoxCell cell = new(); - foreach (ILogLineColumnizer logColumnizer in columnizers) + foreach (var logColumnizer in columnizers) { - cell.Items.Add(logColumnizer.GetName()); + _ = cell.Items.Add(logColumnizer.GetName()); } - row.Cells.Add(cell); + _ = row.Cells.Add(cell); row.Cells[0].Value = maskEntry.Mask; - ILogLineColumnizer columnizer = ColumnizerPicker.DecideColumnizerByName(maskEntry.ColumnizerName, + var columnizer = ColumnizerPicker.DecideColumnizerByName(maskEntry.ColumnizerName, PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers); row.Cells[1].Value = columnizer.GetName(); - dataGridViewColumnizer.Rows.Add(row); + _ = dataGridViewColumnizer.Rows.Add(row); } var count = dataGridViewColumnizer.RowCount; @@ -348,34 +354,31 @@ private void FillHighlightMaskList () var comboColumn = (DataGridViewComboBoxColumn)dataGridViewHighlightMask.Columns[1]; comboColumn.Items.Clear(); - //TODO Remove if not necessary - var textColumn = (DataGridViewTextBoxColumn)dataGridViewHighlightMask.Columns[0]; - - foreach (HighlightGroup group in (IList)_logTabWin.HighlightGroupList) + foreach (var group in (IList)_logTabWin.HighlightGroupList) { - comboColumn.Items.Add(group.GroupName); + _ = comboColumn.Items.Add(group.GroupName); } - foreach (HighlightMaskEntry maskEntry in Preferences.HighlightMaskList) + foreach (var maskEntry in Preferences.HighlightMaskList) { DataGridViewRow row = new(); - row.Cells.Add(new DataGridViewTextBoxCell()); + _ = row.Cells.Add(new DataGridViewTextBoxCell()); DataGridViewComboBoxCell cell = new(); - foreach (HighlightGroup group in (IList)_logTabWin.HighlightGroupList) + foreach (var group in (IList)_logTabWin.HighlightGroupList) { - cell.Items.Add(group.GroupName); + _ = cell.Items.Add(group.GroupName); } - row.Cells.Add(cell); + _ = row.Cells.Add(cell); row.Cells[0].Value = maskEntry.Mask; - HighlightGroup currentGroup = _logTabWin.FindHighlightGroup(maskEntry.HighlightGroupName); + var currentGroup = _logTabWin.FindHighlightGroup(maskEntry.HighlightGroupName); var highlightGroupList = _logTabWin.HighlightGroupList; currentGroup ??= highlightGroupList.Count > 0 ? highlightGroupList[0] : new HighlightGroup(); row.Cells[1].Value = currentGroup.GroupName; - dataGridViewHighlightMask.Rows.Add(row); + _ = dataGridViewHighlightMask.Rows.Add(row); } var count = dataGridViewHighlightMask.RowCount; @@ -424,27 +427,27 @@ private void FillPluginList () { listBoxPlugin.Items.Clear(); - foreach (IContextMenuEntry entry in PluginRegistry.PluginRegistry.Instance.RegisteredContextMenuPlugins) + foreach (var entry in PluginRegistry.PluginRegistry.Instance.RegisteredContextMenuPlugins) { - listBoxPlugin.Items.Add(entry); + _ = listBoxPlugin.Items.Add(entry); if (entry is ILogExpertPluginConfigurator configurator) { configurator.StartConfig(); } } - foreach (IKeywordAction entry in PluginRegistry.PluginRegistry.Instance.RegisteredKeywordActions) + foreach (var entry in PluginRegistry.PluginRegistry.Instance.RegisteredKeywordActions) { - listBoxPlugin.Items.Add(entry); + _ = listBoxPlugin.Items.Add(entry); if (entry is ILogExpertPluginConfigurator configurator) { configurator.StartConfig(); } } - foreach (IFileSystemPlugin entry in PluginRegistry.PluginRegistry.Instance.RegisteredFileSystemPlugins) + foreach (var entry in PluginRegistry.PluginRegistry.Instance.RegisteredFileSystemPlugins) { - listBoxPlugin.Items.Add(entry); + _ = listBoxPlugin.Items.Add(entry); if (entry is ILogExpertPluginConfigurator configurator) { configurator.StartConfig(); @@ -458,7 +461,7 @@ private void SavePluginSettings () { _selectedPlugin?.HideConfigForm(); - foreach (IContextMenuEntry entry in PluginRegistry.PluginRegistry.Instance.RegisteredContextMenuPlugins) + foreach (var entry in PluginRegistry.PluginRegistry.Instance.RegisteredContextMenuPlugins) { if (entry is ILogExpertPluginConfigurator configurator) { @@ -466,7 +469,7 @@ private void SavePluginSettings () } } - foreach (IKeywordAction entry in PluginRegistry.PluginRegistry.Instance.RegisteredKeywordActions) + foreach (var entry in PluginRegistry.PluginRegistry.Instance.RegisteredKeywordActions) { if (entry is ILogExpertPluginConfigurator configurator) { @@ -479,9 +482,9 @@ private void FillToolListbox () { listBoxTools.Items.Clear(); - foreach (ToolEntry tool in Preferences.ToolEntries) + foreach (var tool in Preferences.ToolEntries) { - listBoxTools.Items.Add(tool.Clone(), tool.IsFavourite); + _ = listBoxTools.Items.Add(tool.Clone(), tool.IsFavourite); } if (listBoxTools.Items.Count > 0) @@ -558,12 +561,12 @@ private void DisplayCurrentIcon () { if (_selectedTool != null) { - Icon icon = NativeMethods.LoadIconFromExe(_selectedTool.IconFile, _selectedTool.IconIndex); + var icon = NativeMethods.LoadIconFromExe(_selectedTool.IconFile, _selectedTool.IconIndex); if (icon != null) { Image image = icon.ToBitmap(); buttonIcon.Image = image; - NativeMethods.DestroyIcon(icon.Handle); + _ = NativeMethods.DestroyIcon(icon.Handle); icon.Dispose(); } else @@ -577,12 +580,12 @@ private void FillEncodingList () { comboBoxEncoding.Items.Clear(); - comboBoxEncoding.Items.Add(Encoding.ASCII); - comboBoxEncoding.Items.Add(Encoding.Default); - comboBoxEncoding.Items.Add(Encoding.GetEncoding("iso-8859-1")); - comboBoxEncoding.Items.Add(Encoding.UTF8); - comboBoxEncoding.Items.Add(Encoding.Unicode); - comboBoxEncoding.Items.Add(CodePagesEncodingProvider.Instance.GetEncoding(1252)); + _ = comboBoxEncoding.Items.Add(Encoding.ASCII); + _ = comboBoxEncoding.Items.Add(Encoding.Default); + _ = comboBoxEncoding.Items.Add(Encoding.GetEncoding("iso-8859-1")); + _ = comboBoxEncoding.Items.Add(Encoding.UTF8); + _ = comboBoxEncoding.Items.Add(Encoding.Unicode); + _ = comboBoxEncoding.Items.Add(CodePagesEncodingProvider.Instance.GetEncoding(1252)); comboBoxEncoding.ValueMember = "HeaderName"; } @@ -622,18 +625,11 @@ private void OnBtnOkClick (object sender, EventArgs e) Preferences.FilterTail = checkBoxFilterTail.Checked; Preferences.FollowTail = checkBoxFollowTail.Checked; - if (radioButtonVerticalMouseDrag.Checked) - { - Preferences.TimestampControlDragOrientation = DragOrientationsEnum.Vertical; - } - else if (radioButtonVerticalMouseDragInverted.Checked) - { - Preferences.TimestampControlDragOrientation = DragOrientationsEnum.InvertedVertical; - } - else - { - Preferences.TimestampControlDragOrientation = DragOrientationsEnum.Horizontal; - } + Preferences.TimestampControlDragOrientation = radioButtonVerticalMouseDrag.Checked + ? DragOrientationsEnum.Vertical + : radioButtonVerticalMouseDragInverted.Checked + ? DragOrientationsEnum.InvertedVertical + : DragOrientationsEnum.Horizontal; SaveColumnizerList(); @@ -652,22 +648,13 @@ private void OnBtnOkClick (object sender, EventArgs e) Preferences.SaveSessions = checkBoxSaveSessions.Checked; Preferences.SessionSaveDirectory = labelSessionSaveOwnDir.Text; - if (radioButtonsessionSaveDocuments.Checked) - { - Preferences.SaveLocation = SessionSaveLocation.DocumentsDir; - } - else if (radioButtonSessionSaveOwn.Checked) - { - Preferences.SaveLocation = SessionSaveLocation.OwnDir; - } - else if (radioButtonSessionApplicationStartupDir.Checked) - { - Preferences.SaveLocation = SessionSaveLocation.ApplicationStartupDir; - } - else - { - Preferences.SaveLocation = SessionSaveLocation.SameDir; - } + Preferences.SaveLocation = radioButtonsessionSaveDocuments.Checked + ? SessionSaveLocation.DocumentsDir + : radioButtonSessionSaveOwn.Checked + ? SessionSaveLocation.OwnDir + : radioButtonSessionApplicationStartupDir.Checked + ? SessionSaveLocation.ApplicationStartupDir + : SessionSaveLocation.SameDir; Preferences.SaveFilters = checkBoxSaveFilter.Checked; Preferences.BufferCount = (int)upDownBlockCount.Value; @@ -715,7 +702,7 @@ private void OnBtnDeleteClick (object sender, EventArgs e) if (dataGridViewColumnizer.CurrentRow != null && !dataGridViewColumnizer.CurrentRow.IsNewRow) { var index = dataGridViewColumnizer.CurrentRow.Index; - dataGridViewColumnizer.EndEdit(); + _ = dataGridViewColumnizer.EndEdit(); dataGridViewColumnizer.Rows.RemoveAt(index); } } @@ -819,9 +806,9 @@ private void OnPortableModeCheckedChanged (object sender, EventArgs e) { case CheckState.Checked when !File.Exists(ConfigManager.PortableModeDir + Path.DirectorySeparatorChar + ConfigManager.PortableModeSettingsFileName): { - if (Directory.Exists(ConfigManager.PortableModeDir) == false) + if (!Directory.Exists(ConfigManager.PortableModeDir)) { - Directory.CreateDirectory(ConfigManager.PortableModeDir); + _ = Directory.CreateDirectory(ConfigManager.PortableModeDir); } using (File.Create(ConfigManager.PortableModeDir + Path.DirectorySeparatorChar + ConfigManager.PortableModeSettingsFileName)) @@ -855,7 +842,7 @@ private void OnPortableModeCheckedChanged (object sender, EventArgs e) } catch (Exception exception) { - MessageBox.Show($@"Could not create / delete marker for Portable Mode: {exception}", @"Error", MessageBoxButtons.OK); + _ = MessageBox.Show($@"Could not create / delete marker for Portable Mode: {exception}", @"Error", MessageBoxButtons.OK); } } @@ -918,7 +905,7 @@ private void OnBtnToolDownClick (object sender, EventArgs e) [SupportedOSPlatform("windows")] private void OnBtnToolAddClick (object sender, EventArgs e) { - listBoxTools.Items.Add(new ToolEntry()); + _ = listBoxTools.Items.Add(new ToolEntry()); listBoxTools.SelectedIndex = listBoxTools.Items.Count - 1; } @@ -981,7 +968,7 @@ private void OnBtnWorkingDirClick (object sender, EventArgs e) private void OnMultiFilePatternTextChanged (object sender, EventArgs e) { var pattern = textBoxMultifilePattern.Text; - upDownMultifileDays.Enabled = pattern.Contains("$D", System.StringComparison.Ordinal); + upDownMultifileDays.Enabled = pattern.Contains("$D", StringComparison.Ordinal); } [SupportedOSPlatform("windows")] @@ -995,7 +982,7 @@ private void OnBtnExportClick (object sender, EventArgs e) Filter = @"Settings (*.json)|*.json|All files (*.*)|*.*" }; - DialogResult result = dlg.ShowDialog(); + var result = dlg.ShowDialog(); if (result == DialogResult.OK) { @@ -1027,14 +1014,14 @@ private void OnBtnImportClick (object sender, EventArgs e) } catch (Exception ex) { - MessageBox.Show(this, $@"Settings could not be imported: {ex}", @"LogExpert"); + _ = MessageBox.Show(this, $@"Settings could not be imported: {ex}", @"LogExpert"); return; } ConfigManager.Import(fileInfo, dlg.ImportFlags); Preferences = ConfigManager.Settings.Preferences; FillDialog(); - MessageBox.Show(this, @"Settings imported", @"LogExpert"); + _ = MessageBox.Show(this, @"Settings imported", @"LogExpert"); } } diff --git a/src/LogExpert/Classes/LogExpertProxy.cs b/src/LogExpert/Classes/LogExpertProxy.cs index 558899ab..e3fd0017 100644 --- a/src/LogExpert/Classes/LogExpertProxy.cs +++ b/src/LogExpert/Classes/LogExpertProxy.cs @@ -1,15 +1,12 @@ +using System.Globalization; +using System.Windows.Forms; + using LogExpert.Config; using LogExpert.Core.Interface; -using LogExpert.UI.Controls.LogWindow; using LogExpert.UI.Extensions.LogWindow; using NLog; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Windows.Forms; - namespace LogExpert.Classes; internal class LogExpertProxy : ILogExpertProxy @@ -28,7 +25,7 @@ internal class LogExpertProxy : ILogExpertProxy #region cTor - public LogExpertProxy(ILogTabWindow logTabWindow) + public LogExpertProxy (ILogTabWindow logTabWindow) { AddWindow(logTabWindow); logTabWindow.LogExpertProxy = this; @@ -60,15 +57,15 @@ public LogExpertProxy(ILogTabWindow logTabWindow) #region Public methods - public void LoadFiles(string[] fileNames) + public void LoadFiles (string[] fileNames) { _logger.Info(CultureInfo.InvariantCulture, "Loading files into existing LogTabWindow"); - ILogTabWindow logWin = _windowList[^1]; + var logWin = _windowList[^1]; _ = logWin.Invoke(new MethodInvoker(logWin.SetForeground)); logWin.LoadFiles(fileNames); } - public void NewWindow(string[] fileNames) + public void NewWindow (string[] fileNames) { if (_firstLogTabWindow.IsDisposed) { @@ -93,7 +90,7 @@ public void NewWindow(string[] fileNames) } } - public void NewWindowOrLockedWindow(string[] fileNames) + public void NewWindowOrLockedWindow (string[] fileNames) { foreach (var logWin in _windowList) { @@ -101,6 +98,7 @@ public void NewWindowOrLockedWindow(string[] fileNames) { _ = logWin.Invoke(new MethodInvoker(logWin.SetForeground)); logWin.LoadFiles(fileNames); + logWin.ShowOnlyOneInstanceError(); return; } } @@ -109,11 +107,11 @@ public void NewWindowOrLockedWindow(string[] fileNames) } - public void NewWindowWorker(string[] fileNames) + public void NewWindowWorker (string[] fileNames) { _logger.Info(CultureInfo.InvariantCulture, "Creating new LogTabWindow"); IConfigManager configManager = ConfigManager.Instance; - ILogTabWindow logWin = AbstractLogTabWindow.Create(fileNames.Length > 0 ? fileNames : null, _logWindowIndex++, true, configManager); + var logWin = AbstractLogTabWindow.Create(fileNames.Length > 0 ? fileNames : null, _logWindowIndex++, true, configManager); logWin.LogExpertProxy = this; AddWindow(logWin); logWin.Show(); @@ -121,7 +119,7 @@ public void NewWindowWorker(string[] fileNames) } - public void WindowClosed(ILogTabWindow logWin) + public void WindowClosed (ILogTabWindow logWin) { RemoveWindow(logWin); if (_windowList.Count == 0) @@ -140,7 +138,7 @@ public void WindowClosed(ILogTabWindow logWin) } } - public int GetLogWindowCount() + public int GetLogWindowCount () { return _windowList.Count; } @@ -154,13 +152,13 @@ public int GetLogWindowCount() #region Private Methods - private void AddWindow(ILogTabWindow window) + private void AddWindow (ILogTabWindow window) { _logger.Info(CultureInfo.InvariantCulture, "Adding window to list"); _windowList.Add(window); } - private void RemoveWindow(ILogTabWindow window) + private void RemoveWindow (ILogTabWindow window) { _logger.Info(CultureInfo.InvariantCulture, "Removing window from list"); _ = _windowList.Remove(window); @@ -168,10 +166,10 @@ private void RemoveWindow(ILogTabWindow window) #endregion - protected void OnLastWindowClosed() + protected void OnLastWindowClosed () { LastWindowClosed?.Invoke(this, new EventArgs()); } - private delegate void NewWindowFx(string[] fileNames); + private delegate void NewWindowFx (string[] fileNames); } \ No newline at end of file diff --git a/src/LogExpert/Program.cs b/src/LogExpert/Program.cs index 53d6678a..36dfebf9 100644 --- a/src/LogExpert/Program.cs +++ b/src/LogExpert/Program.cs @@ -1,11 +1,17 @@ +using System.Diagnostics; +using System.Globalization; +using System.IO.Pipes; +using System.Reflection; +using System.Security; +using System.Security.Principal; +using System.Text; +using System.Windows.Forms; + using LogExpert.Classes; using LogExpert.Classes.CommandLine; using LogExpert.Config; using LogExpert.Core.Classes.IPC; using LogExpert.Core.Config; -using LogExpert.Core.Interface; -using LogExpert.Dialogs; -using LogExpert.UI.Controls.LogWindow; using LogExpert.UI.Dialogs; using LogExpert.UI.Extensions.LogWindow; @@ -14,15 +20,6 @@ using NLog; -using System.Diagnostics; -using System.Globalization; -using System.IO.Pipes; -using System.Reflection; -using System.Security; -using System.Security.Principal; -using System.Text; -using System.Windows.Forms; - namespace LogExpert; internal static class Program @@ -41,7 +38,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; @@ -128,17 +125,6 @@ private static void Main(string[] args) _logger.Error(errMsg, "IpcClientChannel error, giving up: "); MessageBox.Show($"Cannot open connection to first instance ({errMsg})", "LogExpert"); } - - //TODO: Remove this from here? Why is it called from the Main project and not from the main window? - if (settings.Preferences.AllowOnlyOneInstance && settings.Preferences.ShowErrorMessageAllowOnlyOneInstances) - { - AllowOnlyOneInstanceErrorDialog a = new(); - if (a.ShowDialog() == DialogResult.OK) - { - settings.Preferences.ShowErrorMessageAllowOnlyOneInstances = !a.DoNotShowThisMessageAgain; - ConfigManager.Instance.Save(SettingsFlags.All); - } - } } mutex.Close(); @@ -158,7 +144,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() { @@ -172,7 +158,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 = []; @@ -192,7 +178,7 @@ private static string[] GenerateAbsoluteFilePaths(string[] remainingArgs) return [.. argsList]; } - private static void SendMessageToProxy(IpcMessage message, LogExpertProxy proxy) + private static void SendMessageToProxy (IpcMessage message, LogExpertProxy proxy) { var payLoad = message.Payload.ToObject(); @@ -227,7 +213,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); @@ -255,7 +241,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) { @@ -290,7 +276,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; @@ -319,7 +305,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); @@ -333,7 +319,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);