From 9e4791a5984e669b061e694dcff9d70b6816436b Mon Sep 17 00:00:00 2001
From: jamaa <90166+jamaa@users.noreply.github.com>
Date: Thu, 18 Jan 2024 22:08:24 +0100
Subject: [PATCH] separate log window from Log in order to allow use of the API
without requiring a reference to System.Windows.Forms as long as no Wave.App
is instantiated
---
source/CHANGELOG.md | 5 ++++
source/Controllers/WaveController.vb | 38 ++++++++++++++++++----------
source/Dialogs/LogWindow.vb | 19 +++++++++++---
source/Log.vb | 36 +++++---------------------
4 files changed, 51 insertions(+), 47 deletions(-)
diff --git a/source/CHANGELOG.md b/source/CHANGELOG.md
index d0753164..3d266580 100644
--- a/source/CHANGELOG.md
+++ b/source/CHANGELOG.md
@@ -1,6 +1,11 @@
BlueM.Wave Release Notes
========================
+Development
+-------------
+API-CHANGES:
+* Allow using the API for reading time series files without requiring a reference to System.Windows.Forms
+
Version 2.7.0
-------------
NEW:
diff --git a/source/Controllers/WaveController.vb b/source/Controllers/WaveController.vb
index 6d005ea0..0946a606 100644
--- a/source/Controllers/WaveController.vb
+++ b/source/Controllers/WaveController.vb
@@ -72,6 +72,8 @@ Friend Class WaveController
Private WithEvents _axisDialog As AxisDialog
+ Private _logWindow As LogWindow
+
'Events handled by the AppInstance
Friend Event Properties_Clicked()
Friend Event TimeseriesValues_Clicked()
@@ -88,6 +90,8 @@ Friend Class WaveController
_axisDialog = New AxisDialog()
+ _logWindow = New LogWindow()
+
'Subscribe to view events
AddHandler Me.View.Load, AddressOf View_Load
@@ -173,9 +177,9 @@ Friend Class WaveController
AddHandler Me.View.Button_NavEnd.Click, AddressOf navigationStartEnd_Click
'status strip events
- AddHandler Me.View.ToolStripStatusLabel_Log.Click, AddressOf ShowLog_Click
- AddHandler Me.View.ToolStripStatusLabel_Errors.Click, AddressOf ShowLog_Click
- AddHandler Me.View.ToolStripStatusLabel_Warnings.Click, AddressOf ShowLog_Click
+ AddHandler Me.View.ToolStripStatusLabel_Log.Click, AddressOf LogShowWindow
+ AddHandler Me.View.ToolStripStatusLabel_Errors.Click, AddressOf LogShowWindow
+ AddHandler Me.View.ToolStripStatusLabel_Warnings.Click, AddressOf LogShowWindow
'axis dialog events
AddHandler _axisDialog.AxisDeleted, AddressOf axisDeleted
@@ -325,7 +329,7 @@ Friend Class WaveController
'Log zurücksetzen
Call Log.ClearLog()
- Call Log.HideLogWindow()
+ Call LogHideWindow()
'Reset counters
View.ToolStripStatusLabel_Errors.Text = 0
@@ -886,7 +890,7 @@ Friend Class WaveController
'Ergebnistext in Log schreiben und anzeigen
If (oAnalysis.hasResultText) Then
Call Log.AddLogEntry(Log.levels.info, oAnalysis.getResultText)
- Call Log.ShowLogWindow()
+ Call LogShowWindow()
End If
'Ergebniswerte in Log schreiben
@@ -895,7 +899,7 @@ Friend Class WaveController
For Each kvp As KeyValuePair(Of String, Double) In oAnalysis.getResultValues
Call Log.AddLogEntry(Log.levels.info, kvp.Key + ": " + Str(kvp.Value))
Next
- Call Log.ShowLogWindow()
+ Call LogShowWindow()
End If
'Display result series in main diagram
@@ -1518,13 +1522,6 @@ Friend Class WaveController
End Sub
- 'Log anzeigen
- '************
- Private Sub ShowLog_Click(sender As System.Object, e As System.EventArgs)
- 'LogWindow anzeigen
- Call Log.ShowLogWindow()
- End Sub
-
'''
''' Handles KeyDown events
''' Initiates clipboard import if Ctrl+V was pressed
@@ -2535,6 +2532,21 @@ Friend Class WaveController
End Sub
+ Private Sub LogShowWindow()
+ If IsNothing(_logWindow) Then
+ _logWindow = New LogWindow()
+ End If
+ _logWindow.Show()
+ _logWindow.WindowState = FormWindowState.Normal
+ _logWindow.BringToFront()
+ End Sub
+
+ Public Sub LogHideWindow()
+ If Not IsNothing(_logWindow) Then
+ _logWindow.Hide()
+ End If
+ End Sub
+
'''
''' Wenn sich der Log verändert hat, Statustext aktualisieren
'''
diff --git a/source/Dialogs/LogWindow.vb b/source/Dialogs/LogWindow.vb
index b003ced1..476d83b6 100644
--- a/source/Dialogs/LogWindow.vb
+++ b/source/Dialogs/LogWindow.vb
@@ -24,11 +24,22 @@ Friend Class LogWindow
' This call is required by the Windows Form Designer.
InitializeComponent()
+ AddHandler Log.LogMsgAdded, AddressOf AddLogEntry
+ AddHandler Log.LogCleared, AddressOf ClearLog
+
' Add any initialization after the InitializeComponent() call.
Me.AddLogEntry(Log.levels.info, "Logging level is set to " & Log.level.ToString())
+
+ 'add any already existing messages
+ If Not IsNothing(Log.logMessages) Then
+ For Each msg As KeyValuePair(Of levels, String) In Log.logMessages
+ Me.AddLogEntry(msg.Key, msg.Value)
+ Next
+ End If
+
End Sub
- Friend Sub AddLogEntry(level As Log.levels, msg As String)
+ Private Sub AddLogEntry(level As Log.levels, msg As String)
Dim start, length As Integer
@@ -76,16 +87,16 @@ Friend Class LogWindow
Call Application.DoEvents()
End Sub
- Friend Sub ClearLog()
+ Private Sub ClearLog()
Me.TextBox_Log.Text = ""
Call Application.DoEvents()
End Sub
- 'Form schließen
+ 'Form schließen
'**************
Private Sub LogWindow_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
- 'verhindern, dass das Formular komplett gelöscht wird
+ 'verhindern, dass das Formular komplett gelöscht wird
e.Cancel = True
'Formular verstecken
diff --git a/source/Log.vb b/source/Log.vb
index 7063a818..c38688f1 100644
--- a/source/Log.vb
+++ b/source/Log.vb
@@ -20,8 +20,6 @@
'''
Public Module Log
- Private logWindow As LogWindow
-
Public logMessages As List(Of KeyValuePair(Of levels, String))
'''
@@ -44,6 +42,11 @@ Public Module Log
'''
Public Event LogMsgAdded(level As Log.levels, msg As String)
+ '''
+ ''' Is triggered when the log was cleared
+ '''
+ Public Event LogCleared()
+
Sub New()
'attempt to read loggingLevel from application settings
Try
@@ -69,10 +72,6 @@ Public Module Log
msg = Constants.eol & " " & msg.Replace(Constants.eol, Constants.eol & " ")
End If
- If Not IsNothing(logWindow) Then
- Log.logWindow.AddLogEntry(level, msg)
- End If
-
RaiseEvent LogMsgAdded(level, msg)
End If
@@ -85,31 +84,8 @@ Public Module Log
Log.logMessages.Clear()
- If Not IsNothing(Log.logWindow) Then
- Log.logWindow.ClearLog()
- End If
-
- RaiseEvent LogMsgAdded(Log.levels.info, "")
- End Sub
+ RaiseEvent LogCleared()
- Public Sub HideLogWindow()
- If Not IsNothing(Log.logWindow) Then
- Log.logWindow.Hide()
- End If
- End Sub
-
- Public Sub ShowLogWindow()
-
- If IsNothing(logWindow) Then
- logWindow = New LogWindow()
- 'if this is the first time the window is shown, add any already existing messages
- For Each msg As KeyValuePair(Of levels, String) In logMessages
- logWindow.AddLogEntry(msg.Key, msg.Value)
- Next
- End If
- logWindow.Show()
- logWindow.WindowState = FormWindowState.Normal
- logWindow.BringToFront()
End Sub
End Module
\ No newline at end of file