Merge
This commit is contained in:
@@ -55,6 +55,7 @@ Public Class DocumentViewer
|
||||
|
||||
Private _hide_file_info_from_user As Boolean = False
|
||||
|
||||
|
||||
Private _FileStream As Stream
|
||||
Private _FilePath As String
|
||||
Private _FileInfo As FileInfo
|
||||
@@ -65,6 +66,8 @@ Public Class DocumentViewer
|
||||
Private _TempFiles As New List(Of String)
|
||||
|
||||
Private Sub DocumentViewer_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
' Ensure search is initialized once the control (and GdViewer) exists
|
||||
EnsureSearchInitialized()
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
'hallo
|
||||
@@ -109,7 +112,8 @@ Public Class DocumentViewer
|
||||
_licenseKey = pLicenseKey
|
||||
_licenseManager.RegisterKEY(_licenseKey)
|
||||
_Annotations = New Annotations(pLogConfig)
|
||||
_Search = New Search(pLogConfig, GdViewer)
|
||||
' Defer creating Search until GdViewer is ready
|
||||
EnsureSearchInitialized()
|
||||
_ToolbarSettings = pToolbarSettings
|
||||
|
||||
Dim oConfigPath = ConfigPath()
|
||||
@@ -121,6 +125,17 @@ Public Class DocumentViewer
|
||||
End Try
|
||||
End Function
|
||||
|
||||
' Create the Search helper only when both the log config and the GdViewer control exist
|
||||
Private Sub EnsureSearchInitialized()
|
||||
Try
|
||||
If _Search Is Nothing AndAlso _logConfig IsNot Nothing AndAlso GdViewer IsNot Nothing Then
|
||||
_Search = New Search(_logConfig, GdViewer)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_logger?.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Load a file from a path and display it
|
||||
''' </summary>
|
||||
@@ -141,9 +156,8 @@ Public Class DocumentViewer
|
||||
_FileInfo = New FileInfo(FilePath)
|
||||
|
||||
_logger.Info("Loading file [{0}] from Filesystem", FilePath)
|
||||
FileLoaded = DoLoadFile(FilePath)
|
||||
|
||||
SetViewerMode(_FileInfo.Extension)
|
||||
FileLoaded = DoLoadFile(FilePath)
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
|
||||
@@ -223,7 +237,17 @@ Public Class DocumentViewer
|
||||
|
||||
Public Sub CloseDocument()
|
||||
Try
|
||||
GdViewer.CloseDocument()
|
||||
' Null-sicher schließen
|
||||
If GdViewer IsNot Nothing Then
|
||||
Try
|
||||
GdViewer.CloseDocument()
|
||||
Catch exInner As Exception
|
||||
_logger?.Warn("Fehler beim Schließen von GdViewer")
|
||||
_logger?.Error(exInner)
|
||||
End Try
|
||||
Else
|
||||
_logger?.Debug("CloseDocument: GdViewer ist Nothing – nichts zu schließen")
|
||||
End If
|
||||
|
||||
_FileInfo = Nothing
|
||||
_FilePath = Nothing
|
||||
@@ -299,25 +323,23 @@ Public Class DocumentViewer
|
||||
GdViewer.Focus()
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
Private Sub btnFirstPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonFirstPage.ItemClick
|
||||
Private Sub BtnFirstPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonFirstPage.ItemClick
|
||||
GdViewer.DisplayFirstPage()
|
||||
End Sub
|
||||
|
||||
Private Sub btnPreviousPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonPrevPage.ItemClick
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
Private Sub BtnPreviousPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonPrevPage.ItemClick
|
||||
GdViewer.DisplayPreviousPage()
|
||||
End Sub
|
||||
|
||||
Private Sub btnNextPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonNextPage.ItemClick
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
Private Sub BtnNextPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonNextPage.ItemClick
|
||||
GdViewer.DisplayNextPage()
|
||||
End Sub
|
||||
|
||||
Private Sub btnLastPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonLastPage.ItemClick
|
||||
Private Sub BtnLastPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonLastPage.ItemClick
|
||||
GdViewer.DisplayLastPage()
|
||||
End Sub
|
||||
|
||||
Private Sub tbCurrentPage_Leave(ByVal sender As System.Object, ByVal e As EventArgs) Handles txtCurrentPage.EditValueChanged
|
||||
Private Sub TbCurrentPage_Leave(ByVal sender As System.Object, ByVal e As EventArgs) Handles txtCurrentPage.EditValueChanged
|
||||
Dim page As Integer = 0
|
||||
If Integer.TryParse(txtCurrentPage.EditValue, page) Then
|
||||
If page > 0 And page <= GdViewer.PageCount Then
|
||||
@@ -339,12 +361,10 @@ Public Class DocumentViewer
|
||||
End Sub
|
||||
|
||||
Private Sub btnZoomOut_Click(sender As Object, e As EventArgs) Handles buttonZoomOut.ItemClick
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.ZoomOUT()
|
||||
End Sub
|
||||
|
||||
Private Sub btnZoomIn_Click(sender As Object, e As EventArgs) Handles buttonZoomIn.ItemClick
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.ZoomIN()
|
||||
End Sub
|
||||
|
||||
@@ -356,11 +376,11 @@ Public Class DocumentViewer
|
||||
GdViewer.PrintDialog()
|
||||
End Sub
|
||||
|
||||
Private Sub btnRotateLeft_Click(sender As Object, e As EventArgs) Handles buttonRotateLeft.ItemClick
|
||||
Private Sub BtnRotateLeft_Click(sender As Object, e As EventArgs) Handles buttonRotateLeft.ItemClick
|
||||
GdViewer.Rotate(RotateFlipType.Rotate270FlipNone)
|
||||
End Sub
|
||||
|
||||
Private Sub btnRotateRight_Click(sender As Object, e As EventArgs) Handles buttonRotateRight.ItemClick
|
||||
Private Sub BtnRotateRight_Click(sender As Object, e As EventArgs) Handles buttonRotateRight.ItemClick
|
||||
GdViewer.Rotate(RotateFlipType.Rotate90FlipNone)
|
||||
End Sub
|
||||
|
||||
@@ -385,7 +405,7 @@ Public Class DocumentViewer
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub btnSettings_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonSettings.ItemClick
|
||||
Private Sub BtnSettings_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonSettings.ItemClick
|
||||
Using frmSettings As New frmViewerSettings(GdViewer)
|
||||
frmSettings.ShowDialog(Me)
|
||||
End Using
|
||||
@@ -439,14 +459,18 @@ Public Class DocumentViewer
|
||||
End Sub
|
||||
|
||||
Private Sub SetViewerMode(Extension As String)
|
||||
Select Case Extension.ToUpper
|
||||
Case "CSV"
|
||||
_ViewerMode = ViewerMode.Excel
|
||||
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
_ViewerMode = ViewerMode.RichText
|
||||
Case Else
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
End Select
|
||||
If _ViewOverride = "Richtext" Then
|
||||
_ViewerMode = ViewerMode.Richtext
|
||||
Else
|
||||
Select Case Extension.ToUpper
|
||||
Case "CSV"
|
||||
_ViewerMode = ViewerMode.Excel
|
||||
'Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
' _ViewerMode = ViewerMode.RichText
|
||||
Case Else
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
End Select
|
||||
End If
|
||||
End Sub
|
||||
Private Sub FreeFile()
|
||||
Try
|
||||
@@ -574,6 +598,12 @@ Public Class DocumentViewer
|
||||
End Function
|
||||
Private Function DoLoadFile(FilePath As String) As Boolean
|
||||
Try
|
||||
' Ensure the embedded GdViewer control exists before using it
|
||||
If Not EnsureViewerReady() Then
|
||||
_logger?.Warn("GdViewer control is not initialized yet. Delaying load.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
lblInfo.Visible = False
|
||||
Dim oFileInfo = New FileInfo(FilePath)
|
||||
Dim oExtension As String = oFileInfo.Extension.ToUpper
|
||||
@@ -599,46 +629,54 @@ Public Class DocumentViewer
|
||||
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||
oRange.AutoFitColumns()
|
||||
|
||||
SpreadsheetControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||
Else
|
||||
Select Case oExtension.ToUpper
|
||||
Case ".CSV"
|
||||
Dim oFormat = GetSpreadsheetFormat(oExtension)
|
||||
SpreadsheetControl1.LoadDocument(FilePath, oFormat)
|
||||
If ViewOverride = "Richtext" Then
|
||||
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
RichEditControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
_ViewOverride = "Richtext"
|
||||
_ViewerMode = ViewerMode.Richtext
|
||||
lblInfo.Visible = True
|
||||
lblInfo.Text = "This docx-file contains a generic error and will be displayed in a reduced viewer. Please try to open the file in WORD"
|
||||
Else
|
||||
_ViewOverride = ""
|
||||
Select Case oExtension.ToUpper
|
||||
Case ".CSV"
|
||||
Dim oFormat = GetSpreadsheetFormat(oExtension)
|
||||
SpreadsheetControl1.LoadDocument(FilePath, oFormat)
|
||||
|
||||
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||
oRange.AutoFitColumns()
|
||||
|
||||
SpreadsheetControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
|
||||
RichEditControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
Case Else
|
||||
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
|
||||
RichEditControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
Case Else
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||
If Viewer_ForceTemporaryMode = True Then
|
||||
GdViewer.ForceTemporaryMode = True
|
||||
End If
|
||||
GdViewer.ForceTemporaryMode = True
|
||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||
If Viewer_ForceTemporaryMode = True Then
|
||||
GdViewer.ForceTemporaryMode = True
|
||||
End If
|
||||
|
||||
GdViewer.AnnotationDropShadow = True
|
||||
GdViewer.BackColor = Color.White
|
||||
GdViewer.AnnotationDropShadow = True
|
||||
GdViewer.BackColor = Color.White
|
||||
|
||||
Dim oGDPState As GdPicture14.GdPictureStatus = GdViewer.DisplayFromFile(FilePath)
|
||||
If oGDPState <> GdPictureStatus.OK Then
|
||||
_logger.Warn($"GdPictureStatus is [{oGDPState}]")
|
||||
If oExtension.ToUpper = ".DOCX" And oGDPState = GdPictureStatus.GenericError Then
|
||||
DoLoadFile(FilePath, "Richtext")
|
||||
Else
|
||||
Dim oFileName = IO.Path.GetFileName(FilePath)
|
||||
lbFileNotLoaded.Text = String.Format("Datei konnte nicht geladen werden:{0}{1}", vbCrLf, oFileName)
|
||||
Dim oGDPState As GdPicture14.GdPictureStatus = GdViewer.DisplayFromFile(FilePath)
|
||||
If oGDPState <> GdPictureStatus.OK Then
|
||||
_logger.Warn($"GdPictureStatus is [{oGDPState}]")
|
||||
If oExtension.ToUpper = ".DOCX" And oGDPState = GdPictureStatus.GenericError Then
|
||||
DoLoadFile(FilePath, "Richtext")
|
||||
Else
|
||||
Dim oFileName = IO.Path.GetFileName(FilePath)
|
||||
lbFileNotLoaded.Text = String.Format("Datei konnte nicht geladen werden:{0}{1}", vbCrLf, oFileName)
|
||||
lbFileNotLoaded.Visible = True
|
||||
End If
|
||||
|
||||
@@ -649,29 +687,60 @@ Public Class DocumentViewer
|
||||
End If
|
||||
|
||||
End Select
|
||||
End If
|
||||
|
||||
|
||||
UpdateMainUi()
|
||||
|
||||
Return True
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
' Ensures the embedded GdViewer control exists and is added to the visual tree
|
||||
Private Function EnsureViewerReady() As Boolean
|
||||
Try
|
||||
' If the control field is Nothing (e.g., designer not yet created), try to lazy-create and add it
|
||||
If GdViewer Is Nothing Then
|
||||
Private Function EnsureViewerReady() As Boolean
|
||||
Try
|
||||
' If the control field is Nothing (e.g., designer not yet created), try to lazy-create and add it
|
||||
If GdViewer Is Nothing Then
|
||||
' Attempt to find an existing instance by name in Controls collection
|
||||
Dim existing = Me.Controls.OfType(Of GdPicture14.GdViewer)().FirstOrDefault()
|
||||
If existing IsNot Nothing Then
|
||||
' Assign the designer field via reflection if needed, otherwise use it directly
|
||||
GdViewer = existing
|
||||
Else
|
||||
' Last resort: create a new viewer and add it
|
||||
Dim viewer = New GdPicture14.GdViewer()
|
||||
viewer.Dock = DockStyle.Fill
|
||||
Me.Controls.Add(viewer)
|
||||
GdViewer = viewer
|
||||
End If
|
||||
End If
|
||||
|
||||
Return GdViewer IsNot Nothing
|
||||
Catch ex As Exception
|
||||
_logger?.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Sub FitToPage()
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeFitToViewer
|
||||
If Not GdViewer Is Nothing Then
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeFitToViewer
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub FitToWidth()
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
If Not GdViewer Is Nothing Then
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Private Function DoLoadFile(Stream As Stream, Extension As String) As Boolean
|
||||
|
||||
Try
|
||||
|
||||
SpreadsheetControl1.Visible = False
|
||||
@@ -691,7 +760,9 @@ Public Class DocumentViewer
|
||||
Case Else
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||
GdViewer.ForceTemporaryMode = True
|
||||
If Viewer_ForceTemporaryMode = True Then
|
||||
GdViewer.ForceTemporaryMode = True
|
||||
End If
|
||||
GdViewer.AnnotationDropShadow = True
|
||||
|
||||
GdViewer.DisplayFromStream(Stream)
|
||||
@@ -838,25 +909,27 @@ Public Class DocumentViewer
|
||||
btnSearch2.Visibility = ToVisibility(False)
|
||||
btnNextHighlight.Visibility = ToVisibility(False)
|
||||
btnPrevHighlight.Visibility = ToVisibility(False)
|
||||
|
||||
|
||||
|
||||
Case Else
|
||||
ToolbarDocumentViewer.Visible = False
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub btnSearch2_ItemClick(sender As Object, e As XtraBars.ItemClickEventArgs) Handles btnSearch2.ItemClick
|
||||
If Not String.IsNullOrEmpty(txtSearch.EditValue) Then
|
||||
EnsureSearchInitialized()
|
||||
If _Search IsNot Nothing AndAlso Not String.IsNullOrEmpty(txtSearch.EditValue) Then
|
||||
_Search.SearchAll(txtSearch.EditValue?.ToString)
|
||||
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub btnPrevHighlight_ItemClick(sender As Object, e As XtraBars.ItemClickEventArgs) Handles btnPrevHighlight.ItemClick
|
||||
_Search.PrevHighlight()
|
||||
EnsureSearchInitialized()
|
||||
_Search?.PrevHighlight()
|
||||
End Sub
|
||||
|
||||
Private Sub btnNextHighlight_ItemClick(sender As Object, e As XtraBars.ItemClickEventArgs) Handles btnNextHighlight.ItemClick
|
||||
_Search.NextHighlight()
|
||||
EnsureSearchInitialized()
|
||||
_Search?.NextHighlight()
|
||||
End Sub
|
||||
|
||||
Private Sub txtSearch_EditValueChanged(sender As Object, e As EventArgs) Handles txtSearch.EditValueChanged
|
||||
|
||||
Reference in New Issue
Block a user