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_ProjectNameMsg As String Public Property ProjectNameMsg As String Get Return m_ProjectNameMsg End Get Set(value As String) ' sostituisco il nome del direttorio con il path completo 'm_ProjectNameMsg = "EgtDOORCreator - " & SetTitle(value) 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 Enum ListPageEnum As Integer nNothingSelected nAssemblyPage nDDFPage 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_PartPage As PartPageV Private m_AssemblyPage As AssemblyPageV Public ReadOnly Property PageControl As ContentControl Get If m_SelectedPage = ListPageEnum.nDDFPage Then Return m_PartPage ElseIf m_SelectedPage = ListPageEnum.nAssemblyPage Then Return m_AssemblyPage Else Return Nothing End If End Get End Property Sub New() Map.SetRefMainWindowVM(Me) m_AssemblyPage = New AssemblyPageV m_AssemblyPage.DataContext = New AssemblyPageVM m_PartPage = New PartPageV m_PartPage.DataContext = New PartPageVM End Sub ' Comandi Private m_cmdAboutBox As ICommand Private m_cmdClose As ICommand Public Sub SetLauncher() Select Case OptionModule.m_OptionLauncherList.IndexOf(OptionModule.m_SelectedOptionLauncher) Case 0 ' 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 1 ' se non trovo salvato nessun ultimo file allora apro vuoto If GetMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, "", m_sLastProject) < 0 Then Exit Select Else ' apro l'ultimo progetto Map.refProjectManagerVM.OpenLastProject() End If ' non fa assolutamente nulla End Select End Sub ' questa funzione restituisce il nome del direttorio corrente Friend Function SetTitle(DirectoryTitle As String) As String If Not String.IsNullOrWhiteSpace(DirectoryTitle) Then Dim Items() As String = DirectoryTitle.Split("\".ToCharArray) If Items.Count = 1 Then Items = DirectoryTitle.Split("-".ToCharArray) End If ' restituisco il nome dell'ultimo direttorio aperto DirectoryTitle = Items(Items.Count - 1) End If Return DirectoryTitle End Function Friend Sub ModifyTitle(bModified As Boolean) If bModified Then If Not m_ProjectNameMsg(m_ProjectNameMsg.Count - 1) = "*" Then ProjectNameMsg &= "*" End If Else If m_ProjectNameMsg(m_ProjectNameMsg.Count - 1) = "*" Then ProjectNameMsg.Trim("*"c) End If End If 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" ''' ''' Returns a command that manage the MainWindow_Unloaded command ''' 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 ''' ''' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. ''' Public Sub CloseApplication(ByVal param As Object) ' verifico se selezionato esiste e modificato 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) Case MessageBoxResult.No ' Non faccio alcunchè Case MessageBoxResult.Cancel Return End Select End If ' scrivo il nome dell'ultimo file aperto If Not IsNothing(Map.refAssemblyManagerVM.CurrProject) Then WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.Name) End If EgtExit() '' Disabilito gestore Idle 'RemoveHandler Application.Idle, AddressOf Application_Idle Application.Current.MainWindow.Close() '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