Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/OpenProjectFileDialog/OpenProjectFileDialogVM.vb
T
2021-03-05 13:14:27 +01:00

190 lines
5.4 KiB
VB.net

Imports System.IO
Imports EgtUILib
Public Class OpenProjectFileDialogVM
Inherits VMBase
Friend Event m_CloseWindow(bDialogResult As Boolean)
Private m_ProjectType As ProjectType
Private m_FileNameTxBl As TextBlock
Private m_sDirectory As String
Public Property Directory As String
Get
Return m_sDirectory
End Get
Set(value As String)
m_sDirectory = value
End Set
End Property
Private m_sFilter As String
Public Property Filter As String
Get
Return m_sFilter
End Get
Set(value As String)
m_sFilter = value
End Set
End Property
Private m_sFileNameFilter As Predicate(Of String)
Public Property FileNameFilter As Predicate(Of String)
Get
Return m_sFileNameFilter
End Get
Set(value As Predicate(Of String))
m_sFileNameFilter = value
End Set
End Property
Private m_sExtensions As New List(Of String)
Public ReadOnly Property Extensions As List(Of String)
Get
Return m_sExtensions
End Get
End Property
Private m_ProjectList As New List(Of ProjectFile)
Public ReadOnly Property ProjectList As List(Of ProjectFile)
Get
Return m_ProjectList
End Get
'Set(value As List(Of ProjFile))
' m_ProjList = value
' NotifyPropertyChanged("ProjList")
'End Set
End Property
Private m_SelProject As ProjectFile
Public Property SelProject As ProjectFile
Get
Return m_SelProject
End Get
Set(value As ProjectFile)
m_SelProject = value
End Set
End Property
Private m_FileName As String
Public Property FileName As String
Get
Return m_FileName
End Get
Set(value As String)
m_FileName = value
End Set
End Property
#Region "Messages"
Public ReadOnly Property OpenMsg As String
Get
Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 6)
End Get
End Property
Public ReadOnly Property CancelMsg As String
Get
Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 2)
End Get
End Property
#End Region
' Definizione comandi
Private m_cmdProjectDoubleClick As ICommand
Public Function Init(ProjectType As ProjectType, Optional ProjectList As List(Of ProjectFile) = Nothing) As Boolean?
m_ProjectType = ProjectType
If IsNothing(ProjectList) OrElse ProjectList.Count = 0 Then
' cartella da cui leggere i programmi
Dim sFolderPath As String
If m_ProjectType = ProjectType.PROJ Then
sFolderPath = Map.refMainWindowVM.MainWindowM.sProjsDir
Else
sFolderPath = Map.refMainWindowVM.MainWindowM.sProdsDir
End If
' leggo i file che contiene
Dim AllDirsInDir As IEnumerable(Of String) = IO.Directory.EnumerateDirectories(sFolderPath)
For Each CurrDirectory In AllDirsInDir
VerifyFiles(CurrDirectory)
Next
Else
m_ProjectList = ProjectList
End If
End Function
Private Sub VerifyFiles(CurrDirectory As String)
Dim AllFilesInDir As IEnumerable(Of String) = IO.Directory.EnumerateFiles(CurrDirectory)
For Each File In AllFilesInDir
If Path.GetExtension(File).ToLower() = ".nge" Then
Dim nProjId As Integer = 0
Dim nProdId As Integer = 0
Dim sBTLFileName As String = ""
If ProjectFile.VerifyProjectFile(m_ProjectType, Path.GetFileNameWithoutExtension(File), nProjId, nProdId, sBTLFileName) Then
m_ProjectList.Add(New ProjectFile(m_ProjectType, nProjId, nProdId, sBTLFileName))
End If
End If
Next
End Sub
Friend Function VerifySelected() As Boolean
Return Not IsNothing(SelProject)
End Function
'Private Sub m_FileNameTxBl_MouseDown(sender As Object, e As Windows.Input.MouseButtonEventArgs) Handles FileNameList.MouseDoubleClick
' Dim src As DependencyObject = VisualTreeHelper.GetParent(DirectCast(e.OriginalSource, DependencyObject))
' ' verifico che venga clickato un item, non lo spazio vuoto o la scrollbar
' If Not TypeOf src Is ListBoxItem Then
' src = Utility.FindAncestor(Of ListBoxItem)(src)
' End If
' If IsNothing(src) OrElse src.[GetType]() <> GetType(ListBoxItem) Then
' e.Handled = True
' Else
' If Not IsNothing(m_SelectedFile) Then
' m_FileName = SelectedFile
' DialogResult = True
' End If
' End If
'End Sub
'Private Sub OpenBtn_Click(sender As Object, e As RoutedEventArgs) Handles OpenBtn.Click
' If Not IsNothing(m_SelectedFile) Then
' m_FileName = SelectedFile
' DialogResult = True
' End If
'End Sub
#Region "COMMANDS"
#Region "ProjectDoubleClick"
''' <summary>
''' Returns a command that do New.
''' </summary>
Public ReadOnly Property ProjectDoubleClick_Command As ICommand
Get
If m_cmdProjectDoubleClick Is Nothing Then
m_cmdProjectDoubleClick = New Command(AddressOf ProjDoubleClick)
End If
Return m_cmdProjectDoubleClick
End Get
End Property
''' <summary>
''' Execute the New. This method is invoked by the NewCommand.
''' </summary>
Friend Sub ProjDoubleClick(ByVal param As Object)
If VerifySelected() Then
RaiseEvent m_CloseWindow(True)
End If
End Sub
#End Region ' ProjectDoubleClick
#End Region ' Commands
End Class