e4aaac1c46
-> bloccaggio dei progetti in fase di lettura, -> correzione nell'intestazione della pagina DOORCreator (nome progetto corrente), -> correzione della lettura degli swing nell'HardwareManager, -> se si crea per la prima volta una componente questa viene salvata nella radice (a meno che non sia stata definita almeno una cartella)
370 lines
16 KiB
VB.net
370 lines
16 KiB
VB.net
Imports EgtUILib
|
|
Imports System.ComponentModel
|
|
Imports System.IO
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class MainWindowVM
|
|
Implements INotifyPropertyChanged
|
|
|
|
' Modello del MainWindow (classe vera e propria)
|
|
Private m_MainWindowModel As New MainWindowModel
|
|
|
|
Private m_VisibilityAssemblyManager As Visibility = Visibility.Visible
|
|
Public Property VisibilityAssemblyManager As Visibility
|
|
Get
|
|
Return m_VisibilityAssemblyManager
|
|
End Get
|
|
Set(value As Visibility)
|
|
m_VisibilityAssemblyManager = value
|
|
NotifyPropertyChanged("VisibilityAssemblyManager")
|
|
End Set
|
|
End Property
|
|
|
|
Private m_ProjectNameMsg As String
|
|
Public Property ProjectNameMsg As String
|
|
Get
|
|
Return m_ProjectNameMsg
|
|
End Get
|
|
Set(value As String)
|
|
m_ProjectNameMsg = "EgtDOORCreator - " & value
|
|
NotifyPropertyChanged("ProjectNameMsg")
|
|
End Set
|
|
End Property
|
|
|
|
Private m_Launcher As LauncherV
|
|
Public ReadOnly Property Launcher As LauncherV
|
|
Get
|
|
If IsNothing(m_Launcher) Then
|
|
m_Launcher = New LauncherV
|
|
m_Launcher.DataContext = New LauncherVM(Me)
|
|
End If
|
|
Return m_Launcher
|
|
End Get
|
|
End Property
|
|
|
|
Private m_OptionPage As OptionsVM
|
|
Public ReadOnly Property OptionPage As OptionsVM
|
|
Get
|
|
If IsNothing(m_OptionPage) Then
|
|
m_OptionPage = New OptionsVM
|
|
End If
|
|
Return m_OptionPage
|
|
End Get
|
|
End Property
|
|
|
|
Enum ListPageEnum As Integer
|
|
nNothingSelected
|
|
nAssemblyPage
|
|
nDDFPage
|
|
nHardwarePage
|
|
End Enum
|
|
|
|
Private m_SelectedPage As ListPageEnum
|
|
Public Property SelectedPage As ListPageEnum
|
|
Get
|
|
Return m_SelectedPage
|
|
End Get
|
|
Set(value As ListPageEnum)
|
|
m_SelectedPage = value
|
|
NotifyPropertyChanged("PageControl")
|
|
End Set
|
|
End Property
|
|
|
|
Private m_ProjectManagerHardware As ProjectManagerHardwareV
|
|
Private m_ProjectManager As ProjectManagerV
|
|
Private m_AssemblyManager As AssemblyManagerV
|
|
Private m_PartPage As PartPageV
|
|
Private m_AssemblyPage As AssemblyPageV
|
|
Private m_HardwarePage As HardwarePageV
|
|
|
|
Private Watcher As FileSystemWatcher = New FileSystemWatcher(IniFile.m_CompoDir, "*" & LUA_EXTENSION)
|
|
|
|
Public ReadOnly Property PageControl As ContentControl
|
|
Get
|
|
If m_SelectedPage = ListPageEnum.nDDFPage Then
|
|
VisibilityAssemblyManager = Visibility.Visible
|
|
NotifyPropertyChanged("AssemblyManagerControl")
|
|
NotifyPropertyChanged("ProjectManagerControl")
|
|
Return m_PartPage
|
|
ElseIf m_SelectedPage = ListPageEnum.nAssemblyPage Then
|
|
VisibilityAssemblyManager = Visibility.Visible
|
|
NotifyPropertyChanged("AssemblyManagerControl")
|
|
NotifyPropertyChanged("ProjectManagerControl")
|
|
Return m_AssemblyPage
|
|
ElseIf m_SelectedPage = ListPageEnum.nHardwarePage Then
|
|
VisibilityAssemblyManager = Visibility.Collapsed
|
|
NotifyPropertyChanged("AssemblyManagerControl")
|
|
NotifyPropertyChanged("ProjectManagerControl")
|
|
Return m_HardwarePage
|
|
Else
|
|
VisibilityAssemblyManager = Visibility.Visible
|
|
NotifyPropertyChanged("AssemblyManagerControl")
|
|
NotifyPropertyChanged("ProjectManagerControl")
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property AssemblyManagerControl As ContentControl
|
|
Get
|
|
If VisibilityAssemblyManager = Visibility.Visible Then
|
|
Return m_AssemblyManager
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property ProjectManagerControl As ContentControl
|
|
Get
|
|
If VisibilityAssemblyManager = Visibility.Visible Then
|
|
Return m_ProjectManager
|
|
Else
|
|
ProjectNameMsg = "HardwareManager"
|
|
Return m_ProjectManagerHardware
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Sub New()
|
|
Map.SetRefMainWindowVM(Me)
|
|
m_AssemblyPage = New AssemblyPageV
|
|
m_AssemblyPage.DataContext = New AssemblyPageVM
|
|
m_ProjectManagerHardware = New ProjectManagerHardwareV
|
|
m_ProjectManagerHardware.DataContext = New ProjectManagerHardwareVM
|
|
m_ProjectManager = New ProjectManagerV
|
|
m_ProjectManager.DataContext = New ProjectManagerVM
|
|
m_PartPage = New PartPageV
|
|
m_PartPage.DataContext = New PartPageVM
|
|
m_HardwarePage = New HardwarePageV
|
|
m_HardwarePage.DataContext = New HardwarePageVM
|
|
m_AssemblyManager = New AssemblyManagerV
|
|
m_AssemblyManager.DataContext = New AssemblyManagerVM
|
|
Dim OptionsPage As OptionsVM = OptionPage
|
|
InitWatcher()
|
|
End Sub
|
|
|
|
#Region "Watcher"
|
|
|
|
Public Enum WatcherCalling
|
|
OnCreated
|
|
OnDeleted
|
|
OnChanged
|
|
OnRenamed
|
|
OnLoadTempFile
|
|
NoEvents
|
|
End Enum
|
|
|
|
Public selectedWatcher As WatcherCalling = WatcherCalling.NoEvents
|
|
|
|
Public CompoDDFName As String = String.Empty
|
|
|
|
Public Event Er(message As String, sPath As String)
|
|
Public StartReload As Boolean = False
|
|
Public Sub PrintMessagesFromWatcher(message As String, sPath As String) Handles Me.Er
|
|
StartReload = True
|
|
' MessageBox.Show(Application.Current.MainWindow, message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
|
|
If sPath.Contains(IniFile.m_CompoDir) Then
|
|
sPath = Trim(sPath.Replace(IniFile.m_CompoDir & "\", ""))
|
|
End If
|
|
Dim sItems() As String = sPath.Split("\"c)
|
|
If sItems.Count > 1 Then
|
|
If Not IsNothing(Map.refCompoPanelVM) AndAlso Not IsNothing(Map.refCompoPanelVM.CompoTypeList) Then
|
|
For Each ItemCompo In Map.refCompoPanelVM.CompoTypeList
|
|
If ItemCompo.Path.Contains(sItems(0)) Then
|
|
' ricarico l'elenco dei direttori e dei file
|
|
ItemCompo.LoadListTemplate()
|
|
CompoDDFName = ItemCompo.DDFName
|
|
If Not IsNothing(Map.refProjectManagerVM) Then Map.refProjectManagerVM.ReloadCmd()
|
|
CompoDDFName = String.Empty
|
|
StartReload = False
|
|
Return
|
|
End If
|
|
Next
|
|
End If
|
|
End If
|
|
If Not IsNothing(Map.refProjectManagerVM) Then Map.refProjectManagerVM.ReloadCmd()
|
|
CompoDDFName = String.Empty
|
|
StartReload = False
|
|
End Sub
|
|
|
|
' Inizializzatore dell'evento Watcher (controllo dei direttori e dei files) su un nuovo Thread
|
|
Friend Sub InitWatcher(Optional ByVal StopWatcher As Boolean = False)
|
|
Watcher.IncludeSubdirectories = True
|
|
Watcher.Path = IniFile.m_CompoDir
|
|
' AddHandler Watcher.Changed, New FileSystemEventHandler(AddressOf OnChanged)
|
|
AddHandler Watcher.Deleted, New FileSystemEventHandler(AddressOf OnDeleted)
|
|
AddHandler Watcher.Created, New FileSystemEventHandler(AddressOf OnCreated)
|
|
AddHandler Watcher.Renamed, New RenamedEventHandler(AddressOf OnRenamed)
|
|
Watcher.EnableRaisingEvents = Not StopWatcher
|
|
End Sub
|
|
|
|
' cominico una modifica (forzo l'utilizzo del Thread principale richiamando un evento Er)
|
|
Private Sub OnChanged(source As Object, e As FileSystemEventArgs)
|
|
If m_SelectedPage = ListPageEnum.nHardwarePage Then Return
|
|
If StartReload Then Return
|
|
Dim Message As String = "File: " & e.FullPath & " " & e.ChangeType
|
|
selectedWatcher = WatcherCalling.OnChanged
|
|
Application.Current.Dispatcher.BeginInvoke(New Action(Sub()
|
|
RaiseEvent Er(Message, e.FullPath)
|
|
End Sub), System.Windows.Threading.DispatcherPriority.ContextIdle, Nothing)
|
|
'If Not IsNothing(Map.refProjectManagerVM) Then Map.refProjectManagerVM.ReloadCmd()
|
|
End Sub
|
|
|
|
' cominico una eliminazione(forzo l'utilizzo del Thread principale richiamando un evento Er)
|
|
Private Sub OnDeleted(source As Object, e As FileSystemEventArgs)
|
|
If m_SelectedPage = ListPageEnum.nHardwarePage Then Return
|
|
If StartReload Then Return
|
|
Dim Message As String = "It has been deleted file: " & e.FullPath & " " & e.ChangeType
|
|
selectedWatcher = WatcherCalling.OnDeleted
|
|
Application.Current.Dispatcher.BeginInvoke(New Action(Sub()
|
|
RaiseEvent Er(Message, e.FullPath)
|
|
End Sub), System.Windows.Threading.DispatcherPriority.ContextIdle, Nothing)
|
|
' comunico che nessun evento particolare è stato selezionato
|
|
End Sub
|
|
|
|
' cominico una rinomina (forzo l'utilizzo del Thread principale richiamando un evento Er)
|
|
Private Sub OnRenamed(source As Object, e As FileSystemEventArgs)
|
|
If m_SelectedPage = ListPageEnum.nHardwarePage Then Return
|
|
If StartReload Then Return
|
|
Dim Message As String = "It has been renamed file: " & e.FullPath & " " & e.ChangeType
|
|
selectedWatcher = WatcherCalling.OnRenamed
|
|
Application.Current.Dispatcher.BeginInvoke(New Action(Sub()
|
|
RaiseEvent Er(Message, e.FullPath)
|
|
End Sub), System.Windows.Threading.DispatcherPriority.ContextIdle, Nothing)
|
|
'If Not IsNothing(Map.refProjectManagerVM) Then Map.refProjectManagerVM.ReloadCmd()
|
|
End Sub
|
|
|
|
' cominico una creazione (forzo l'utilizzo del Thread principale richiamando un evento Er)
|
|
Private Sub OnCreated(source As Object, e As FileSystemEventArgs)
|
|
If m_SelectedPage = ListPageEnum.nHardwarePage Then Return
|
|
If StartReload Then Return
|
|
Dim Message As String = "It has been created new file: " & e.FullPath & " " & e.ChangeType
|
|
selectedWatcher = WatcherCalling.OnCreated
|
|
Application.Current.Dispatcher.BeginInvoke(New Action(Sub()
|
|
RaiseEvent Er(Message, e.FullPath)
|
|
End Sub), System.Windows.Threading.DispatcherPriority.ContextIdle, Nothing)
|
|
'If Not IsNothing(Map.refProjectManagerVM) Then Map.refProjectManagerVM.ReloadCmd()
|
|
End Sub
|
|
|
|
#End Region ' Watcher
|
|
|
|
' Comandi
|
|
Private m_cmdAboutBox As ICommand
|
|
Private m_cmdClose As ICommand
|
|
|
|
Public Sub SetLauncher()
|
|
Dim nLauncher As Integer = If(OptionModule.m_bLauncherOpenOnce, LauncherOpt.Open_last_project, OptionModule.m_SelectedOptionLauncher)
|
|
Select Case nLauncher
|
|
Case LauncherOpt.Open_window
|
|
' apre la finestra
|
|
Dim Launcher As New LauncherV
|
|
Launcher.Height = 200
|
|
Launcher.Width = 250
|
|
LauncherModule.InitLauncherModule()
|
|
Launcher.DataContext = New LauncherVM(Me)
|
|
Launcher.Owner = Application.Current.MainWindow
|
|
Launcher.ShowDialog()
|
|
Case LauncherOpt.Open_last_project
|
|
' se definito ultimo progetto, lo apro
|
|
If GetMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, "", m_sLastProject) > 0 Then
|
|
Map.refProjectManagerVM.OpenLastProject()
|
|
End If
|
|
Case Else
|
|
' non fa assolutamente nulla
|
|
End Select
|
|
End Sub
|
|
|
|
#Region "AboutBoxCommand"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property AboutBoxCommand() As ICommand
|
|
Get
|
|
If m_cmdAboutBox Is Nothing Then
|
|
m_cmdAboutBox = New Command(AddressOf AboutBox)
|
|
End If
|
|
Return m_cmdAboutBox
|
|
End Get
|
|
End Property
|
|
|
|
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
|
|
Public Sub AboutBox(ByVal param As Object)
|
|
Dim AboutBoxWindow As New AboutBoxV
|
|
AboutBoxWindow.Owner = Application.Current.MainWindow
|
|
AboutBoxWindow.ShowDialog()
|
|
End Sub
|
|
|
|
#End Region ' AboutBoxCommand
|
|
|
|
#Region "CloseApplicationCommand"
|
|
|
|
Public ReadOnly Property CloseApplicationCommand() As ICommand
|
|
Get
|
|
If m_cmdClose Is Nothing Then
|
|
m_cmdClose = New Command(AddressOf CloseApplication)
|
|
End If
|
|
Return m_cmdClose
|
|
End Get
|
|
End Property
|
|
|
|
'Public Sub CloseApplication(ByVal param As Object)
|
|
Public Sub CloseApplication()
|
|
' verifico se selezionato esiste e modificato
|
|
Select Case SelectedPage
|
|
Case ListPageEnum.nHardwarePage
|
|
If Not IsNothing(Map.refHardwarePageVM) And Not IsNothing(Map.refHardwarePageVM.CurrHardware) Then
|
|
If Map.refHardwarePageVM.CurrHardware.SaveControl() = Hardware.SaveResult.nCancel Then
|
|
Return
|
|
ElseIf Map.refHardwarePageVM.CurrHardware.SaveControl() = Hardware.SaveResult.nYes Then
|
|
Map.refHardwarePageVM.CurrHardware.Save()
|
|
End If
|
|
Map.refHardwarePageVM.CurrHardware.DeleteTempFile()
|
|
End If
|
|
Utility.UnLockDir()
|
|
Case Else
|
|
If Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) AndAlso Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified Then
|
|
Dim sText As String = String.Format(EgtMsg(50109), Path.GetFileNameWithoutExtension(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name))
|
|
Select Case MessageBox.Show(sText, "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)
|
|
Case MessageBoxResult.Yes
|
|
Map.refAssemblyManagerVM.Save(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName)
|
|
If Not DdfFile.DDFIsCorrect Then Return ' se il ddf non è corretto non permetto il salvataggio
|
|
Case MessageBoxResult.No
|
|
' Non faccio alcunchè
|
|
Case MessageBoxResult.Cancel
|
|
Return
|
|
End Select
|
|
End If
|
|
End Select
|
|
'' scrivo il nome dell'ultimo file aperto
|
|
'If Not IsNothing(Map.refAssemblyManagerVM.CurrProject) AndAlso
|
|
' Not String.IsNullOrWhiteSpace(Map.refAssemblyManagerVM.CurrProject.Name) Then
|
|
' WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.Name)
|
|
'End If
|
|
|
|
If Not IsNothing(Map.refAssemblyManagerVM.CurrProject) AndAlso Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) AndAlso
|
|
Not String.IsNullOrWhiteSpace(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name) Then
|
|
If File.Exists(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name) Then
|
|
WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name)
|
|
Else
|
|
WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.Name)
|
|
End If
|
|
ElseIf Not IsNothing(Map.refAssemblyManagerVM.CurrProject) AndAlso
|
|
Not String.IsNullOrWhiteSpace(Map.refAssemblyManagerVM.CurrProject.Name) Then
|
|
WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.Name)
|
|
End If
|
|
EgtExit()
|
|
Application.Current.MainWindow.Close()
|
|
Utility.UnLockDir()
|
|
'End If
|
|
End Sub
|
|
|
|
#End Region ' CloseApplicationCommand
|
|
|
|
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
|
|
|
|
Public Sub NotifyPropertyChanged(propName As String)
|
|
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
|
|
End Sub
|
|
|
|
End Class
|