Files
EgtWPFLib5/SaveFileDialog/SaveFileDialogV.xaml.vb
T
Emmanuele Sassi 14bc598378 EgtWPFLib5 :
- corretta finestra EgtSaveFileDialog che diventa SaveFileDialog.
2018-09-14 07:58:15 +00:00

191 lines
6.8 KiB
VB.net

Imports System.ComponentModel
Imports System.IO
Imports EgtUILib
Public Class SaveFileDialogV
'Implements INotifyPropertyChanged
Private m_SaveFileDialogVM As SaveFileDialogVM
#Region "CONSTRUCTOR"
Sub New(Owner As Window, SaveFileDialogVM As SaveFileDialogVM)
' Funzione che interpreta l'xaml
InitializeComponent()
Me.Owner = Owner
Me.DataContext = SaveFileDialogVM
' Assegno al riferimento locale al VM il VM preso dal DataContext
m_SaveFileDialogVM = SaveFileDialogVM
End Sub
#End Region ' CONSTRUCTOR
Private Sub SaveBtn_Click(sender As Object, e As RoutedEventArgs) Handles SaveBtn.Click
If m_SaveFileDialogVM.Save() Then
DialogResult = True
End If
End Sub
Public Overloads Function ShowDialog() As Boolean?
' inizializzo dialogo
m_SaveFileDialogVM.Initialize()
' pongo focus su testo
FilePath.Focus()
' mostro la finestra di dialogo
Return MyBase.ShowDialog()
End Function
' 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_sExtension As String
' Public Property Extension As String
' Get
' Return m_sExtension
' End Get
' Set(value As String)
' m_sExtension = 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
' Private m_IsFolder As Boolean
' Public Property IsFolder As Boolean
' Get
' Return m_IsFolder
' End Get
' Set(value As Boolean)
' m_IsFolder = value
' End Set
' End Property
' Private m_WriteFileName As String
' Public Property WriteFileName As String
' Get
' Return m_WriteFileName
' End Get
' Set(value As String)
' Dim TempName As String = value.Trim(Path.GetInvalidFileNameChars)
' If TempName.Length = value.Length Then
' m_WriteFileName = value
' Else
' MessageBox.Show(EgtMsg(MSG_EGTSAVEFILEDIALOG + 10), EgtMsg(MSG_EGTSAVEFILEDIALOG + 7), MessageBoxButton.OK, MessageBoxImage.Error)
' End If
' NotifyPropertyChanged("WriteFileName")
' End Set
' End Property
'#Region "Messages"
' Public ReadOnly Property TitleMsg As String
' Get
' If IsFolder Then
' Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 11)
' Else
' Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 10)
' End If
' End Get
' End Property
' Public ReadOnly Property SaveMsg As String
' Get
' Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 1)
' End Get
' End Property
' Public ReadOnly Property CancelMsg As String
' Get
' Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 2)
' End Get
' End Property
'#End Region
' Public Function EgtShowDialog() As Boolean?
' ' se la cartella d'origine non è stata impostata, esco
' If String.IsNullOrWhiteSpace(m_sDirectory) Then
' Throw New Exception("Exception: Directory is null or white space!")
' End If
' ' se non esiste, esco
' If Not IO.Directory.Exists(m_sDirectory) Then
' Throw New Exception("Exception: Directory doesn't exist!")
' End If
' If String.IsNullOrWhiteSpace(m_sExtension) Then
' Throw New Exception("Exception: Extension is null or white space!")
' End If
' ' verifico se è impostato un nome di default
' If Not String.IsNullOrWhiteSpace(m_FileName) Then
' m_WriteFileName = m_FileName
' End If
' NotifyPropertyChanged("WriteFileName")
' If IsFolder Then m_sExtension = ""
' ' pongo focus su testo
' FilePath.Focus()
' ' mostro la finestra di dialogo
' Return Me.ShowDialog()
' End Function
' Private Sub SaveBtn_Click(sender As Object, e As RoutedEventArgs) Handles SaveBtn.Click
' Dim sCompleteFileName As String = m_sDirectory & "\" & m_WriteFileName & If(IsFolder, "", m_sExtension)
' If String.IsNullOrWhiteSpace(m_WriteFileName) Then
' MessageBox.Show(EgtMsg(MSG_EGTSAVEFILEDIALOG + 8), EgtMsg(MSG_EGTSAVEFILEDIALOG + 7), MessageBoxButton.OK, MessageBoxImage.Error)
' Exit Sub
' End If
' If IsFolder Then
' If System.IO.Directory.Exists(sCompleteFileName) Then
' If MessageBox.Show(m_FileName & " " & EgtMsg(MSG_EGTSAVEFILEDIALOG + 3) & vbCrLf & EgtMsg(MSG_EGTSAVEFILEDIALOG + 4), EgtMsg(MSG_EGTSAVEFILEDIALOG + 9), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then
' Exit Sub
' End If
' End If
' Else
' If File.Exists(sCompleteFileName) Then
' If MessageBox.Show(m_FileName & " " & EgtMsg(MSG_EGTSAVEFILEDIALOG + 3) & vbCrLf & EgtMsg(MSG_EGTSAVEFILEDIALOG + 4), EgtMsg(MSG_EGTSAVEFILEDIALOG + 9), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then
' Exit Sub
' End If
' End If
' End If
' m_FileName = sCompleteFileName
' DialogResult = True
' End Sub
'Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
'Public Sub NotifyPropertyChanged(propName As String)
' RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
'End Sub
End Class
''' <summary>
''' Class that represent a Converter that convert the complete file path in the file name and vice versa.
''' </summary>
Public Class FileNameConverter
Implements IValueConverter
Dim TempPath As String
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
TempPath = CStr(value)
Return Path.GetFileNameWithoutExtension(TempPath)
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return Path.GetDirectoryName(TempPath) & "\" & CStr(value) & Path.GetExtension(TempPath)
End Function
End Class