Monorepo/GUIs.Common/DocumentPropertyMenu/DocumentPropertyMenu.vb

70 lines
2.6 KiB
VB.net

Imports System.Windows.Forms
Imports DevExpress.Utils.Menu
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.ZooFlow
Public Class DocumentPropertyMenu
Private ReadOnly _Logger As Logger
Private ReadOnly _LogConfig As LogConfig
Private ReadOnly _Environment As Environment
Private ReadOnly _FilePath As String
Private ReadOnly _ObjectId As Long
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
End Sub
Public Function GetMenuItems() As List(Of DXMenuItem)
Dim oOpenFile = New DXMenuItem("Datei öffnen", AddressOf OpenFile_Click)
Dim oOpenFolder = New DXMenuItem("Ordner öffnen", AddressOf OpenFolder_Click)
Dim oCopyPath = New DXMenuItem("Pfad kopieren", AddressOf CopyPath_Click)
Dim oProperties = New DXMenuItem("Eigenschaften", AddressOf Properties_Click)
Return New List(Of DXMenuItem) From {
oOpenFile,
oOpenFolder,
oCopyPath,
oProperties
}
End Function
Public Sub Properties_Click(sender As Object, e As EventArgs)
If _ObjectId = 0 Then
Exit Sub
End If
Dim oPropertyDialog As New frmObjectPropertyDialog(_LogConfig, _Environment, _ObjectId)
oPropertyDialog.Show()
End Sub
Public Sub CopyPath_Click(sender As Object, e As EventArgs)
If IO.File.Exists(_FilePath) Then
Clipboard.SetText(_FilePath)
Else
MessageBox.Show($"Datei {_FilePath} existiert nicht oder wurde verschoben!", "Dateipfad kopieren", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
Public Sub OpenFile_Click(sender As Object, e As EventArgs)
If IO.File.Exists(_FilePath) Then
Process.Start(_FilePath)
Else
MessageBox.Show($"Datei {_FilePath} existiert nicht oder wurde verschoben!", "Datei öffnen", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
Public Sub OpenFolder_Click(sender As Object, e As EventArgs)
If IO.File.Exists(_FilePath) Then
Dim oDirectory = IO.Path.GetDirectoryName(_FilePath)
Process.Start(oDirectory)
Else
MessageBox.Show($"Datei {_FilePath} existiert nicht oder wurde verschoben!", "Ordner öffnen", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
End Class