Files
EgtWPFLib5/EgtManageFileDialog/EgtManageFileDialogVM.vb
T
Demetrio Cassarino 2bf78159c8 EgtWPFLib5 3.1c1:
-cambio versione
-aggiunto piccolo controllo su EgtManageDialog
2026-03-03 09:38:20 +01:00

979 lines
31 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports System.Data
Public Class EgtManageFileDialogVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Public Enum VisualizationContainerType As Integer
LISTBOX = 0
DATAGRID = 1
End Enum
Public Enum VisualizationType As Integer
LISTTEMPLATE = 0
TILESTEMPLATE = 1
CONTENTTEMPLATE = 2
DETAILSTEMPLATE = 3
End Enum
Public Enum ModeTypes As Integer
FILE = 1
FOLDER = 2
End Enum
Private m_sTitle As String
Public Property sTitle As String
Get
Return m_sTitle
End Get
Set(value As String)
m_sTitle = value
End Set
End Property
' Scelta della modalità di salvataggio 1 = file 2 = folder
Private m_nMode As Integer
Public Property nMode As Integer
Get
Return m_nMode
End Get
Set(value As Integer)
m_nMode = value
End Set
End Property
Private m_bCheckFileExists As Boolean
Public Property bCheckFileExists As Boolean
Get
Return m_bCheckFileExists
End Get
Set(value As Boolean)
m_bCheckFileExists = value
End Set
End Property
Private m_bValidateNames As Boolean
Public Property bValidateNames As Boolean
Get
Return m_bValidateNames
End Get
Set(value As Boolean)
m_bValidateNames = value
End Set
End Property
Private m_bOverwritePrompt As Boolean
Public Property bOverwritePrompt As Boolean
Get
Return m_bOverwritePrompt
End Get
Set(value As Boolean)
m_bOverwritePrompt = value
End Set
End Property
Private m_RootList As New ObservableCollection(Of EgtDirectory)
Public Property RootList As ObservableCollection(Of EgtDirectory)
Get
Return m_RootList
End Get
Set(value As ObservableCollection(Of EgtDirectory))
m_RootList = value
End Set
End Property
Public m_SelTreeItem As EgtDirectory
Public Property SelTreeItem As EgtDirectory
Get
Return m_SelTreeItem
End Get
Set(value As EgtDirectory)
m_SelTreeItem = value
NotifyPropertyChanged(NameOf(SelTreeItem))
End Set
End Property
Friend Sub UpdateSelTreeItem(Item As EgtDirectory)
m_SelTreeItem = Item
NotifyPropertyChanged(NameOf(SelTreeItem))
End Sub
Public m_ItemSelected As EgtDirectory
Public Property ItemSelected As EgtDirectory
Get
Return m_ItemSelected
End Get
Set(value As EgtDirectory)
m_ItemSelected = value
Dim Item As EgtItem = TryCast(m_ItemSelected, EgtItem)
If Not IsNothing(Item) Then
sSaveFileName = Item.sName
Else
Dim Folder As EgtFolder = TryCast(m_ItemSelected, EgtFolder)
If Not IsNothing(Folder) Then
sSaveFileName = Folder.sName
End If
End If
End Set
End Property
Friend Sub SetItemSelected(value As EgtDirectory)
m_ItemSelected = value
NotifyPropertyChanged(NameOf(ItemSelected))
End Sub
' Percorso del file o della cartella
Private m_sSelPath As String
Public Overloads Property sSelPath As String
Get
Return m_sSelPath
End Get
Set(value As String)
m_sSelPath = value
NotifyPropertyChanged(NameOf(sSelPath))
End Set
End Property
' Textbox per visualizzare il file o la folder selezionata
Private m_sSaveFileName As String
Public Property sSaveFileName As String
Get
Return m_sSaveFileName
End Get
Set(value As String)
m_sSaveFileName = value
NotifyPropertyChanged(NameOf(sSaveFileName))
End Set
End Property
' Lista filtri estensione
Private m_FilterList As ObservableCollection(Of EgtExstension)
Public Property FilterList As ObservableCollection(Of EgtExstension)
Get
Return m_FilterList
End Get
Set(value As ObservableCollection(Of EgtExstension))
m_FilterList = value
End Set
End Property
' Scelta filtro estensione per visualizzazione
Public m_SelFilter As EgtExstension
Public Property SelFilter As EgtExstension
Get
Return m_SelFilter
End Get
Set(value As EgtExstension)
m_SelFilter = value
Dim CurrItem As EgtFolder = TryCast(m_SelTreeItem, EgtFolder)
If Not IsNothing(CurrItem) Then
CollectionViewSource.GetDefaultView(CurrItem.FolderList).Refresh()
End If
End Set
End Property
' Lista modalita' di visualizzazione
Private m_ViewModeList As ObservableCollection(Of IdNameStruct)
Public Property ViewModeList As ObservableCollection(Of IdNameStruct)
Get
Return m_ViewModeList
End Get
Set(value As ObservableCollection(Of IdNameStruct))
m_ViewModeList = value
End Set
End Property
' Scelta modalita' di visualizzazione
Private m_SelViewMode As IdNameStruct
Public Property SelViewMode As IdNameStruct
Get
Return m_SelViewMode
End Get
Set(value As IdNameStruct)
m_SelViewMode = value
Select Case m_SelViewMode.Id
Case VisualizationType.LISTTEMPLATE
m_nSelTab = VisualizationContainerType.LISTBOX
nSelTempleteListView = 0
WriteMainPrivateProfileString(S_TEMPLETESEL, K_CURRTEMPLETESEL, VisualizationType.LISTTEMPLATE)
Case VisualizationType.TILESTEMPLATE
m_nSelTab = VisualizationContainerType.LISTBOX
nSelTempleteListView = 1
WriteMainPrivateProfileString(S_TEMPLETESEL, K_CURRTEMPLETESEL, VisualizationType.TILESTEMPLATE)
Case VisualizationType.CONTENTTEMPLATE
m_nSelTab = VisualizationContainerType.LISTBOX
nSelTempleteListView = 2
WriteMainPrivateProfileString(S_TEMPLETESEL, K_CURRTEMPLETESEL, VisualizationType.CONTENTTEMPLATE)
Case VisualizationType.DETAILSTEMPLATE
m_nSelTab = VisualizationContainerType.DATAGRID
WriteMainPrivateProfileString(S_TEMPLETESEL, K_CURRTEMPLETESEL, VisualizationType.DETAILSTEMPLATE)
End Select
NotifyPropertyChanged(NameOf(nSelTab))
End Set
End Property
' Indice modalita' di visualizzazione
Private m_nSelViewModeIndex As Integer
Public Property nSelViewModeIndex As Integer
Get
Return m_nSelViewModeIndex
End Get
Set(value As Integer)
m_nSelViewModeIndex = value
End Set
End Property
' Indice di selezione del TabControl che cambia la ListBox/DataGrid
Private m_nSelTab As Integer
Public Property nSelTab As Integer
Get
Return m_nSelTab
End Get
Set(value As Integer)
m_nSelTab = value
End Set
End Property
#Region "Initial data from window opening"
' Indice del filtro estensione impostato durante creazione finestra
Private m_nFilterIndex As Integer
Public Property nFilterIndex As Integer
Get
Return m_nFilterIndex
End Get
Set(value As Integer)
m_nFilterIndex = value
m_SelFilter = m_FilterList.FirstOrDefault(Function(x) x.nIndexExstension = m_nFilterIndex)
sFileName = Path.GetFileNameWithoutExtension(sFileName) & m_SelFilter.sExstension.Trim("*"c)
End Set
End Property
' lista delle estensioni impostata durante creazione finestra
Private m_sFilter As String
Public Property sFilter As String
Get
Return m_sFilter
End Get
Set(value As String)
m_sFilter = value
Dim nIndex As Integer = 1
If Not IsNothing(sFilter) Then
Dim FilterListSplit As String() = sFilter.Split("|"c)
For i As Integer = 0 To FilterListSplit.Count - 1
If i Mod 2 = 0 Then
Dim strExstension As New EgtExstension() With {.m_nIndexExstension = nIndex, .m_sNameExstension = FilterListSplit(i), .m_sExstension = FilterListSplit(i + 1)}
m_FilterList.Add(strExstension)
nIndex += 1
End If
Next
End If
End Set
End Property
' Path della cartella iniziale impostata durante creazione finestra
Private m_sInitialDirectory As String
Public Property sInitialDirectory As String
Get
Return m_sInitialDirectory
End Get
Set(value As String)
m_sInitialDirectory = value
If m_sFileName = String.Empty Then m_sSaveFileName = "New.nge"
m_sSelPath = m_sInitialDirectory
Dim DirectoryStart As String() = m_sInitialDirectory.Split("\"c)
Dim m_RootListTmp As New ObservableCollection(Of EgtDirectory)
Dim dir As EgtDirectory
Dim count As Integer = 1
Dim currItem As EgtFolder
m_RootListTmp = m_RootList
For Each directory As String In DirectoryStart
dir = m_RootListTmp.FirstOrDefault(Function(x) x.sName.Trim("\"c) = directory)
If Not IsNothing(dir) Then
dir.IsExpanded = True
currItem = TryCast(dir, EgtFolder)
m_RootListTmp = currItem.FolderList
If count = DirectoryStart.Count Then
dir.IsSelected = True
Else
count += 1
End If
End If
Next
End Set
End Property
' Nome del file iniziale impostato durante creazione finestra
Private m_sFileName As String
Public Property sFileName As String
Get
Return m_sFileName
End Get
Set(value As String)
m_sFileName = value
m_sSaveFileName = m_sFileName
End Set
End Property
#End Region ' Initial data from window opening
' Scelta per la visualizzazione del templete della lista
Private m_nSelTempleteListView As Integer
Public Property nSelTempleteListView As Integer
Get
Return m_nSelTempleteListView
End Get
Set(value As Integer)
m_nSelTempleteListView = value
NotifyPropertyChanged(NameOf(nSelTempleteListView))
End Set
End Property
#Region "Messages"
Public ReadOnly Property Name_Msg As String
Get
Return EgtMsg(15060) ' Nome
End Get
End Property
Public ReadOnly Property LastModify_Msg As String
Get
Return EgtMsg(15061) ' Ultima Modifica
End Get
End Property
Public ReadOnly Property Type_Msg As String
Get
Return EgtMsg(15062) ' Tipo
End Get
End Property
Public ReadOnly Property Dimension_Msg As String
Get
Return EgtMsg(15063) ' Dimensione
End Get
End Property
Public ReadOnly Property FileName_Msg As String
Get
' Nome File Nome Cartella
Return If(m_nMode = ModeTypes.FILE, EgtMsg(15065), EgtMsg(15066))
End Get
End Property
#End Region
' Comandi
Private m_cmdCancel As ICommand
Private m_cmdOk As ICommand
Private m_cmdGoBack As ICommand
Private m_cmdDoubleClick As ICommand
Public Event OnCloseWindow(bDialogResult As Boolean)
#End Region ' Fields & Properties
#Region "CONTRUCTORS"
Sub New()
m_RootList.Clear()
EgtDirectory.refUpdateSelTreeItem = AddressOf UpdateSelTreeItem
Dim drives As DriveInfo() = DriveInfo.GetDrives().Where(Function(d) d.IsReady).ToArray()
m_FilterList = New ObservableCollection(Of EgtExstension)
EgtFolder.SetEgtManageFileDialogVM(Me)
' Aggiungo cartella di sistema
Dim directoryFolder As EgtFolder = Nothing
For Each driver As DriveInfo In drives
Select Case driver.Name
Case "C:\"
directoryFolder = New EgtFolder(driver.RootDirectory, Nothing, "\Resources\EgtDialog\Windows.png")
Case "I:\"
directoryFolder = New EgtFolder(driver.RootDirectory, Nothing, "\Resources\EgtDialog\HardDrive.png")
Case "R:\"
directoryFolder = New EgtFolder(driver.RootDirectory, Nothing, "\Resources\EgtDialog\HardDrive.png")
Case "S:\"
directoryFolder = New EgtFolder(driver.RootDirectory, Nothing, "\Resources\EgtDialog\HardDrive.png")
Case Else
directoryFolder = New EgtFolder(driver.RootDirectory, Nothing, "\Resources\EgtDialog\Root.png")
End Select
m_RootList.Add(directoryFolder)
Next
' Aggiungo Desktop
Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim desktopFolder As New EgtFolder(New DirectoryInfo(desktopPath), Nothing, "\Resources\EgtDialog\Desktop.png")
m_RootList.Add(desktopFolder)
' Aggiungo Download
Dim downloadsPath As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) & "\Downloads"
If Directory.Exists(downloadsPath) Then
Dim downloadsFolder As New EgtFolder(New DirectoryInfo(downloadsPath), Nothing, "\Resources\EgtDialog\Download.png")
m_RootList.Add(downloadsFolder)
End If
' Aggiungo ultima cartella
Dim lastPath As String = String.Empty
GetPrivateProfileString(S_GENERAL, "LastImpDir", "", lastPath, IniFile.m_sIniFile)
If Directory.Exists(lastPath) Then
Dim lastFolder As New EgtFolder(New DirectoryInfo(lastPath), Nothing, "\Resources\EgtDialog\Folder.png")
m_RootList.Add(lastFolder)
End If
m_SelFilter = New EgtExstension()
SetVisualizzationList()
Dim IndexTemplete As Integer = GetMainPrivateProfileInt(S_TEMPLETESEL, K_CURRTEMPLETESEL, VisualizationContainerType.DATAGRID)
SelViewMode = m_ViewModeList.FirstOrDefault(Function(x) x.Id = IndexTemplete)
NotifyPropertyChanged(NameOf(RootList))
NotifyPropertyChanged(NameOf(FilterList))
NotifyPropertyChanged(NameOf(ViewModeList))
NotifyPropertyChanged(NameOf(FileName_Msg))
NotifyPropertyChanged(NameOf(SelViewMode))
End Sub
#End Region ' Constructors
#Region "METHODS"
''' <summary>
''' Inizializza la ComboBox per la scelta dei template
''' </summary>
Private Sub SetVisualizzationList()
m_ViewModeList = New ObservableCollection(Of IdNameStruct)
Dim ItemVisualization As New IdNameStruct With {
.Id = 0,
.Name = EgtMsg(15067), ' Elenco
.Image = "\Resources\EgtDialog\List.png"
}
m_ViewModeList.Add(ItemVisualization)
ItemVisualization.Id = 3
ItemVisualization.Name = EgtMsg(15068) ' Dettagli
ItemVisualization.Image = "\Resources\EgtDialog\Details.png"
m_ViewModeList.Add(ItemVisualization)
ItemVisualization.Id = 1
ItemVisualization.Name = EgtMsg(15069) ' Riquadri
ItemVisualization.Image = "\Resources\EgtDialog\Tiles.png"
m_ViewModeList.Add(ItemVisualization)
ItemVisualization.Id = 2
ItemVisualization.Name = EgtMsg(15070) ' Contenuto
ItemVisualization.Image = "\Resources\EgtDialog\Content.png"
m_ViewModeList.Add(ItemVisualization)
End Sub
#End Region ' Methods
#Region "COMMANDS"
#Region "Ok"
Public ReadOnly Property Ok_Command As ICommand
Get
If m_cmdOk Is Nothing Then
m_cmdOk = New Command(AddressOf Ok)
End If
Return m_cmdOk
End Get
End Property
Public Sub Ok()
Dim CurrItem As EgtItem = TryCast(m_ItemSelected, EgtItem)
Dim simbolsCharacter As String() = {"<"c, ">"c, ":"c, "'"c, "/"c, "\"c, "|"c, "?"c, "*"c,
"CON", "PRN", "AUX", "NUL", "COM0", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT0", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"}
If nMode = ModeTypes.FILE Then
If Not IsNothing(CurrItem) And m_bCheckFileExists And m_bValidateNames Then
For Each simbol As String In simbolsCharacter
If m_sSaveFileName.Contains(simbol) Then
' Errore file contiene simboli non conformi
If EgtMessageBoxV.Show(System.Windows.Application.Current.MainWindow, EgtMsg(15072), sTitle, MessageBoxButton.OKCancel, MessageBoxImage.Error) = MessageBoxResult.Cancel Then
sSaveFileName = CurrItem.sName
Return
End If
Else
m_sFileName = m_SelTreeItem.sFullName & "\" & m_sSaveFileName
End If
Next
ElseIf m_bValidateNames = False And m_bOverwritePrompt Then
If Not IsNothing(CurrItem) Then
If m_sFileName.Equals(m_sSaveFileName) OrElse m_sSaveFileName.Equals(CurrItem.sName) Then
' File già esistente. Vuoi sovrascrivere?
If EgtMessageBoxV.Show(System.Windows.Application.Current.MainWindow, EgtMsg(15073), sTitle, MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.No Then
Return
End If
End If
Else
m_sFileName = m_SelTreeItem.sFullName & "\" & m_sSaveFileName
End If
Else
m_sFileName = m_SelTreeItem.sFullName & "\" & m_sSaveFileName
End If
ElseIf nMode = ModeTypes.FOLDER Then
For Each simbol As String In simbolsCharacter
If m_sSaveFileName.Contains(simbol) Then
' Errore file contiene simboli non conformi
If EgtMessageBoxV.Show(System.Windows.Application.Current.MainWindow, EgtMsg(15072), sTitle, MessageBoxButton.OKCancel, MessageBoxImage.Error) = MessageBoxResult.Cancel Then
Return
End If
Else
m_sFileName = m_SelTreeItem.sFullName
End If
Next
End If
RaiseEvent OnCloseWindow(True)
End Sub
#End Region 'Ok
#Region "GoBack"
Public ReadOnly Property GoBack_Command As ICommand
Get
If m_cmdGoBack Is Nothing Then
m_cmdGoBack = New Command(AddressOf GoBack)
End If
Return m_cmdGoBack
End Get
End Property
Public Sub GoBack()
If Not IsNothing(m_SelTreeItem) AndAlso Not IsNothing(m_SelTreeItem.m_ParentFolder) Then
If TypeOf m_SelTreeItem.m_ParentFolder Is EgtFolder Then
Dim CurrParentFolder As EgtFolder = DirectCast(m_SelTreeItem.m_ParentFolder, EgtFolder)
CurrParentFolder.SetIsSelected(True, False)
End If
m_sSelPath = DirectCast(m_SelTreeItem, EgtFolder).sFullName
NotifyPropertyChanged(NameOf(sSelPath))
End If
End Sub
#End Region 'GoBack
#Region "Cancel"
Public ReadOnly Property Cancel_Command As ICommand
Get
If m_cmdCancel Is Nothing Then
m_cmdCancel = New Command(AddressOf Cancel)
End If
Return m_cmdCancel
End Get
End Property
Public Sub Cancel()
RaiseEvent OnCloseWindow(False)
End Sub
#End Region 'Cancel
#Region "DoubleClick"
Public ReadOnly Property DoubleClick_Command As ICommand
Get
If m_cmdDoubleClick Is Nothing Then
m_cmdDoubleClick = New Command(AddressOf MouseDoubleClick)
End If
Return m_cmdDoubleClick
End Get
End Property
Public Sub MouseDoubleClick()
m_ItemSelected.IsExpanded = True
If TypeOf m_ItemSelected Is EgtFolder Then
Dim CurrItemSelected As EgtFolder = DirectCast(m_ItemSelected, EgtFolder)
CurrItemSelected.SetIsSelected(True, True)
m_sSelPath = CurrItemSelected.sFullName
ElseIf TypeOf m_ItemSelected Is EgtItem Then
Dim CurrItemSelected As EgtItem = DirectCast(m_ItemSelected, EgtItem)
m_ItemSelected.IsExpanded = False
If File.Exists(CurrItemSelected.sFullName) Then
m_sFileName = CurrItemSelected.sFullName
RaiseEvent OnCloseWindow(True)
Else
EgtOutLog("File Inesistente")
End If
End If
NotifyPropertyChanged(NameOf(sSelPath))
End Sub
#End Region 'DoubleClick
#End Region ' Commands
End Class
Public Class EgtExstension
Inherits VMBase
#Region "FIELDS & PROPERTIES"
' Indice estensione
Public m_nIndexExstension As Integer
Public Property nIndexExstension As Integer
Get
Return m_nIndexExstension
End Get
Set(value As Integer)
m_nIndexExstension = value
NotifyPropertyChanged(NameOf(nIndexExstension))
End Set
End Property
' Nome della stringa Filter Splittata m_sNameExstension = EgtStone3D project
Public m_sNameExstension As String
Public Property sNameExstension As String
Get
Return m_sNameExstension
End Get
Set(value As String)
m_sNameExstension = value
NotifyPropertyChanged(NameOf(sNameExstension))
End Set
End Property
' Estensione della stringa Filter Splittata m_sExstension = *.wme
Public m_sExstension As String
Public Property sExstension As String
Get
Return m_sExstension
End Get
Set(value As String)
m_sExstension = value
NotifyPropertyChanged(NameOf(sExstension))
End Set
End Property
#End Region ' Fields & Properties
End Class
Public MustInherit Class EgtDirectory
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Friend Shared refUpdateSelTreeItem As Action(Of EgtDirectory)
Friend Shared m_refEgtManageFileDialogVM As EgtManageFileDialogVM
Friend Shared Sub SetEgtManageFileDialogVM(EgtManageFileDialogVM As EgtManageFileDialogVM)
m_refEgtManageFileDialogVM = EgtManageFileDialogVM
End Sub
Protected m_bIsSelected As Boolean
Public MustOverride Property IsSelected As Boolean
Protected m_bIsExpanded As Boolean
Public Overridable Property IsExpanded As Boolean
Public MustOverride ReadOnly Property sFullName As String
Protected m_sName As String
Public MustOverride ReadOnly Property sName As String
Protected m_sIconSource As String
Public Overridable ReadOnly Property sIconSource As String
Get
Return m_sIconSource
End Get
End Property
Protected m_sTypeItem As String
Public MustOverride ReadOnly Property sTypeItem As String
Protected m_ghTypeItem As String
Public Overridable ReadOnly Property ghTypeItem As String
Protected m_dtLastModifyDate As Date
Public MustOverride ReadOnly Property sLastModifyDate As String
Public m_ParentFolder As EgtFolder
Public Property ParentFolder As EgtFolder
Get
Return m_ParentFolder
End Get
Set(value As EgtFolder)
m_ParentFolder = value
End Set
End Property
#End Region ' Fields & Properties
End Class
Public Class EgtFolder
Inherits EgtDirectory
#Region "FIELDS & PROPERTIES"
Private m_ItemList_View As CollectionView = Nothing
Private m_TreeItemList_ViewSource As CollectionViewSource = Nothing
Private m_TreeItemList_View As CollectionView = Nothing
Public ReadOnly Property TreeItemList_View As CollectionView
Get
Return m_TreeItemList_View
End Get
End Property
Private m_DirectoryInfo As DirectoryInfo
Private m_FolderList As New ObservableCollection(Of EgtDirectory)
Public Property FolderList As ObservableCollection(Of EgtDirectory)
Get
Return m_FolderList
End Get
Set(value As ObservableCollection(Of EgtDirectory))
m_FolderList = value
End Set
End Property
Public Overrides ReadOnly Property sFullName As String
Get
Return m_DirectoryInfo.FullName
End Get
End Property
Public Overrides ReadOnly Property sName As String
Get
Return m_DirectoryInfo.Name
End Get
End Property
Public Overrides ReadOnly Property sTypeItem As String
Get
Return EgtMsg(15064) ' Cartella di File
End Get
End Property
Public Overrides ReadOnly Property sLastModifyDate As String
Get
Return m_DirectoryInfo.LastWriteTime.ToString("dd/MM/yyyy HH:mm:ss")
End Get
End Property
Public Overrides Property IsExpanded As Boolean
Get
Return m_bIsExpanded
End Get
Set(value As Boolean)
m_bIsExpanded = value
NotifyPropertyChanged(NameOf(IsExpanded))
If m_bIsExpanded Then
SetFolderList()
End If
End Set
End Property
Public Overrides Property IsSelected As Boolean
Get
Return m_bIsSelected
End Get
Set(value As Boolean)
m_bIsSelected = value
m_refEgtManageFileDialogVM.sSelPath = m_DirectoryInfo.FullName
If m_bIsSelected Then
SetFolderList()
refUpdateSelTreeItem(Me)
NotifyPropertyChanged(NameOf(IsSelected))
End If
End Set
End Property
Friend Sub SetIsSelected(value As Boolean, bRefreshList As Boolean)
Dim sSelListItemPath As String = ""
If Not IsNothing(m_refEgtManageFileDialogVM.SelTreeItem) Then
sSelListItemPath = m_refEgtManageFileDialogVM.SelTreeItem.sFullName
End If
m_bIsSelected = value
m_refEgtManageFileDialogVM.sSelPath = m_DirectoryInfo.FullName
If m_bIsSelected Then
If bRefreshList Then SetFolderList()
refUpdateSelTreeItem(Me)
End If
If Not IsNothing(sSelListItemPath) Then
Dim SelFolderItem As EgtDirectory = m_FolderList.FirstOrDefault(Function(x) x.sFullName = sSelListItemPath)
If Not IsNothing(SelFolderItem) Then
m_refEgtManageFileDialogVM.SetItemSelected(SelFolderItem)
End If
End If
NotifyPropertyChanged(NameOf(IsSelected))
End Sub
#End Region ' Fields & Properties
#Region "CONTRUCTORS"
Sub New()
End Sub
Sub New(DirectoryInfo As DirectoryInfo, Parent As EgtDirectory, Optional IconSource As String = "\Resources\EgtDialog\Folder.png")
m_DirectoryInfo = DirectoryInfo
m_sIconSource = IconSource
Try
If DirectoryInfo.EnumerateDirectories.Count > 0 Then
m_FolderList.Add(New EgtFolder())
End If
Catch ex As Exception
End Try
m_ParentFolder = Parent
m_ItemList_View = CollectionViewSource.GetDefaultView(m_FolderList)
m_ItemList_View.Filter = AddressOf ItemFilter
m_TreeItemList_ViewSource = New CollectionViewSource() With {.Source = m_FolderList}
m_TreeItemList_View = m_TreeItemList_ViewSource.View
m_TreeItemList_View.Filter = AddressOf TreeItemListFilter
NotifyPropertyChanged(NameOf(sName))
NotifyPropertyChanged(NameOf(sLastModifyDate))
NotifyPropertyChanged(NameOf(sTypeItem))
NotifyPropertyChanged(NameOf(sIconSource))
NotifyPropertyChanged(NameOf(FolderList))
NotifyPropertyChanged(NameOf(ParentFolder))
End Sub
#End Region ' Constructors
#Region "METHODS"
''' <summary>
''' Funzione per la visualizzazione delle sole cartelle nell'albero TreeView
''' </summary>
''' <param name="CurrItem"></param>
''' <returns></returns>
Private Function TreeItemListFilter(CurrItem As Object) As Boolean
Return TypeOf CurrItem Is EgtFolder
End Function
''' <summary>
''' Funzione per il controllo del filtro per i singoli Item se l'estensione scelta e' .icrs verrano visualizzati tutti i file con l'estensione .icrs
''' </summary>
''' <param name="Item"></param>
''' <returns></returns>
Private Function ItemFilter(Item As Object) As Boolean
Dim CurrItem As EgtItem = TryCast(Item, EgtItem)
If Not IsNothing(CurrItem) AndAlso Not IsNothing(m_refEgtManageFileDialogVM.m_SelFilter.m_sExstension) Then
If String.Equals(CurrItem.sTypeItem, m_refEgtManageFileDialogVM.m_SelFilter.m_sExstension.TrimStart("*"c), StringComparison.OrdinalIgnoreCase) Then
Return True
ElseIf m_refEgtManageFileDialogVM.m_SelFilter.m_sExstension.TrimStart("*"c) = ".*" Then
Return True
Else
Return False
End If
End If
Return True
End Function
''' <summary>
''' Funzione per popolare la lista FolderList
''' </summary>
Private Sub SetFolderList()
Dim DirectoryList() As DirectoryInfo
Dim FileList() As FileInfo
Try
' ProgramData
DirectoryList = m_DirectoryInfo.GetDirectories().Where(Function(file) (file.Attributes And FileAttributes.Hidden And file.Name <> EgtMsg(15071)) = 0).ToArray()
FileList = m_DirectoryInfo.GetFiles().Where(Function(file) (file.Attributes And FileAttributes.Hidden) = 0).ToArray()
Catch ex As Exception
DirectoryList = Nothing
FileList = Nothing
End Try
m_FolderList.Clear()
If Not IsNothing(DirectoryList) AndAlso m_FolderList.Count = 0 Then
For Each subDir As DirectoryInfo In DirectoryList
Dim directory As New EgtFolder(subDir, Me)
m_FolderList.Add(directory)
Next
End If
If Not IsNothing(FileList) Then
For Each files As FileInfo In FileList
Dim file As New EgtItem(files)
m_FolderList.Add(file)
Next
End If
End Sub
#End Region ' Methods
End Class
Public Class EgtItem
Inherits EgtDirectory
#Region "FIELDS & PROPERTIES"
Private m_FileInfo As FileInfo
Public Overrides ReadOnly Property sFullName As String
Get
Return m_FileInfo.FullName
End Get
End Property
Public Overrides ReadOnly Property sName As String
Get
Return m_FileInfo.Name
End Get
End Property
Public Overrides ReadOnly Property sTypeItem As String
Get
If Not IsNothing(m_FileInfo) AndAlso Not IsNothing(m_FileInfo.Extension) AndAlso Not String.IsNullOrWhiteSpace(m_FileInfo.Extension) Then
Return m_FileInfo.Extension
Else
Return ""
End If
End Get
End Property
Public Overrides ReadOnly Property ghTypeItem As String
Get
Return If(Not String.IsNullOrWhiteSpace(sTypeItem), "File " & sTypeItem.ToUpper(), "")
End Get
End Property
Public ReadOnly Property sDimension As String
Get
Return If(m_FileInfo.Length / 1024 / 1024 > 1, String.Format("{0:#,##0.00}", m_FileInfo.Length / 1024 / 1024) & " Mb", String.Format("{0:#,##0.00}", m_FileInfo.Length / 1024) & " Kb")
End Get
End Property
Public Overrides ReadOnly Property sLastModifyDate As String
Get
Return m_FileInfo.LastWriteTime.ToString("dd/MM/yyyy HH:mm:ss")
End Get
End Property
Public Overrides Property IsSelected As Boolean
Get
Return m_bIsSelected
End Get
Set(value As Boolean)
m_bIsSelected = value
refUpdateSelTreeItem(Me)
End Set
End Property
#End Region ' Fields & Properties
#Region "CONTRUCTORS"
Sub New(FileInfo As FileInfo)
m_FileInfo = FileInfo
m_sIconSource = "\Resources\EgtDialog\New.png"
NotifyPropertyChanged(NameOf(sName))
NotifyPropertyChanged(NameOf(sDimension))
NotifyPropertyChanged(NameOf(sLastModifyDate))
NotifyPropertyChanged(NameOf(sTypeItem))
NotifyPropertyChanged(NameOf(sIconSource))
End Sub
#End Region ' Constructors
End Class