Monorepo/GUIs.Common/DocumentPropertyMenu/DocumentPropertyMenu.vb

124 lines
4.2 KiB
VB.net

Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports DevExpress.Utils.Menu
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windows.NativeMethods
Imports DigitalData.Modules.Windows.File
Imports DigitalData.Modules.ZooFlow
Public Class DocumentPropertyMenu
Private ReadOnly _Logger As Logger
Private ReadOnly _LogConfig As LogConfig
Private ReadOnly _Environment As Environment
Private ReadOnly _File As Modules.Windows.File
Private ReadOnly _FilePath As String
Private ReadOnly _ObjectId As Long
Public Const OPEN_FILE As String = "Datei öffnen"
Public Const OPEN_DIRECTORY As String = "Ordner öffnen"
Public Const COPY_PATH As String = "Dateipfad kopieren"
Public Const OPEN_PROPERTIES As String = "Eigenschaften"
Public Sub New(LogConfig As LogConfig, Environment As Environment, FilePath As String, Optional ObjectId As Long = 0)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_Environment = Environment
_FilePath = FilePath
_ObjectId = ObjectId
_File = New Modules.Windows.File(LogConfig)
End Sub
Public Function GetMenuItems(IsLegacy As Boolean) As List(Of DXMenuItem)
If IsLegacy Then
Return GetLegacyMenuItems()
Else
Return GetIDBMenuItems()
End If
End Function
Public Function GetIDBMenuItems() As List(Of DXMenuItem)
Dim oOpenFile = New DXMenuItem(OPEN_FILE, AddressOf OpenFile_Click)
Dim oOpenFolder = New DXMenuItem(OPEN_DIRECTORY, AddressOf OpenFolder_Click)
Dim oCopyPath = New DXMenuItem(COPY_PATH, AddressOf CopyPath_Click)
Dim oProperties = New DXMenuItem(OPEN_PROPERTIES, AddressOf Properties_Click)
Return New List(Of DXMenuItem) From {
oOpenFile,
oOpenFolder,
oCopyPath,
oProperties
}
End Function
Public Function GetLegacyMenuItems() As List(Of DXMenuItem)
Dim oOpenFile = New DXMenuItem(OPEN_FILE, AddressOf OpenFile_Click)
Dim oOpenFolder = New DXMenuItem(OPEN_DIRECTORY, AddressOf OpenFolder_Click)
Dim oCopyPath = New DXMenuItem(COPY_PATH, AddressOf CopyPath_Click)
Dim oProperties = New DXMenuItem(OPEN_PROPERTIES, AddressOf Properties_Click_Legacy)
Return New List(Of DXMenuItem) From {
oOpenFile,
oOpenFolder,
oCopyPath,
oProperties
}
End Function
Public Sub Properties_Click(sender As Object, e As EventArgs)
If TestObjectIdExists(OPEN_PROPERTIES) Then
Exit Sub
End If
Dim oPropertyDialog As New frmObjectPropertyDialog(_LogConfig, _Environment, _ObjectId)
oPropertyDialog.Show()
End Sub
Public Sub Properties_Click_Legacy(sender As Object, e As EventArgs)
If TestPathExists(OPEN_PROPERTIES) = False Then
Exit Sub
End If
_File.OpenFileProperties(_FilePath)
End Sub
Public Sub CopyPath_Click(sender As Object, e As EventArgs)
Clipboard.SetText(_FilePath)
End Sub
Public Sub OpenFile_Click(sender As Object, e As EventArgs)
If TestPathExists(OPEN_FILE) = False Then
Exit Sub
End If
Process.Start(_FilePath)
End Sub
Public Sub OpenFolder_Click(sender As Object, e As EventArgs)
If TestPathExists(OPEN_DIRECTORY) = False Then
Exit Sub
End If
Dim oDirectory = IO.Path.GetDirectoryName(_FilePath)
Process.Start(oDirectory)
End Sub
Private Function TestPathExists(Title As String) As Boolean
If IO.File.Exists(_FilePath) = False Then
MessageBox.Show($"Datei {_FilePath} existiert nicht oder wurde verschoben!", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
Else
Return True
End If
End Function
Private Function TestObjectIdExists(Title As String) As Boolean
If _ObjectId = 0 Then
MessageBox.Show($"Objekt {_ObjectId} existiert nicht oder wurde verschoben!", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
Else
Return True
End If
End Function
End Class