diff --git a/Application.xaml.vb b/Application.xaml.vb index 763c54b..1c6bdc7 100644 --- a/Application.xaml.vb +++ b/Application.xaml.vb @@ -119,6 +119,8 @@ Class Application Friend Const SHOW As String = "Show" Friend Const DONE As String = "Done" Friend Const EXECUTECOMMAND As String = "ExecuteCommand" + Friend Const MANAGEMODIFIED As String = "ManageModified" + Friend Const ALLOWWINDOWTOCLOSE As String = "AllowWindowToClose" ' DrawOptionPanel messages Friend Const PREPAREINPUTBOX As String = "PrepareInputBox" diff --git a/MainWindow/MainWindow.xaml b/MainWindow/MainWindow.xaml index 2214c1b..c3515a9 100644 --- a/MainWindow/MainWindow.xaml +++ b/MainWindow/MainWindow.xaml @@ -4,7 +4,10 @@ xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:EgtWPFLib5="clr-namespace:EgtWPFLib5;assembly=EgtWPFLib5" xmlns:local="clr-namespace:EgtCAM5" - Title="MainWindow" Height="768" Width="1366" Icon="/Resources/EgtCAM5.ico" AboutBox="{Binding AboutBox}" WindowStyle="None" ResizeMode="NoResize"> + xmlns:EgtCAM5="clr-namespace:EgtCAM5.EgtCAM5" + Title="MainWindow" Height="768" Width="1366" Icon="/Resources/EgtCAM5.ico" + AboutBox="{Binding AboutBox}" WindowStyle="None" ResizeMode="NoResize" + CloseCommand="{Binding CloseApplicationCommand,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"> diff --git a/MainWindow/MainWindowViewModel.vb b/MainWindow/MainWindowViewModel.vb index 6c84005..cee58f5 100644 --- a/MainWindow/MainWindowViewModel.vb +++ b/MainWindow/MainWindowViewModel.vb @@ -47,6 +47,7 @@ Namespace EgtCAM5 Private m_cmdMainWindow_Deactivated As ICommand ' MainWindow Closing Event Private m_cmdMainWindow_Closing As ICommand + Private m_cmdCloseApplication As ICommand ' GRAPHICAL ELEMENTS Private m_TopCommandBar As TopCommandBarView @@ -132,7 +133,7 @@ Namespace EgtCAM5 #Region "CONSTRUCTOR" Sub New() - 'Application.Current.MainWindow.Icon = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/EgtCAM5.ico", UriKind.Relative)) + RegisterMyMessages() ' INITIALIZE EGALTECH ENVIRONMENT InitializeEgtEnvironment() @@ -170,9 +171,9 @@ Namespace EgtCAM5 Public Sub MainWindow_Closing(ByVal param As Object) Application.Msn.NotifyColleagues(Application.CLOSEAPPLICATION) '' Gestisco eventuale file corrente modificato - 'If Not m_Controller.ManageModified() Then - ' E.Cancel = True - ' Return + Application.Msn.NotifyColleagues(Application.MANAGEMODIFIED) + 'If m_allowWindowToClose Then + ' CloseCommand = New RelayCommand(Nothing, Function() True) 'End If ' Salvo posizione Form (se non minimizzato) If Application.Current.MainWindow.WindowState <> WindowState.Minimized Then @@ -208,6 +209,63 @@ Namespace EgtCAM5 #End Region ' Closing Command +#Region "CloseApplicationCommand" + + ''' + ''' Returns a command that manage the MainWindow_Unloaded command + ''' + Public ReadOnly Property CloseApplicationCommand() As ICommand + Get + If m_cmdCloseApplication Is Nothing Then + m_cmdCloseApplication = New RelayCommand(AddressOf CloseApplication, AddressOf CanCloseApplication) + End If + Return m_cmdCloseApplication + End Get + End Property + + ''' + ''' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. + ''' + Public Sub CloseApplication(ByVal param As Object) + '' Gestisco eventuale file corrente modificato + Application.Msn.NotifyColleagues(Application.MANAGEMODIFIED) + If m_allowWindowToClose Then + Application.Msn.NotifyColleagues(Application.CLOSEAPPLICATION) + ' Salvo posizione Form (se non minimizzato) + If Application.Current.MainWindow.WindowState <> WindowState.Minimized Then + Dim WinPos As New WinPos + WindowToWinPos(Application.Current.MainWindow, WinPos) + WritePrivateProfileWinPos(S_GENERAL, K_WINPLACE, WinPos.nFlag, WinPos.nLeft, WinPos.nTop, WinPos.nWidth, WinPos.nHeight) + End If + ' Terminazione generale di EgtInterface + EgtExit() + ' Rilascio mutex + m_objMutex.Close() + ' Aggiorno istanze usate + Dim nTmp As Integer = GetPrivateProfileInt(S_GENERAL, K_INSTANCES, 0) + nTmp -= (1 << (m_nInstance - 1)) + WritePrivateProfileString(S_GENERAL, K_INSTANCES, nTmp.ToString()) + '' Disabilito gestore Idle + 'RemoveHandler Application.Idle, AddressOf Application_Idle + Application.Current.MainWindow.Close() + End If + End Sub + + ''' + ''' Returns true if the application can be closed + ''' + Private Function CanCloseApplication(ByVal param As Object) As Boolean + '' Impedisco uscita se script in esecuzione + 'If m_bScriptRunning Then + ' m_bStopScript = True + ' E.Cancel = True + ' Return + 'End If + Return True + End Function + +#End Region ' CloseApplicationCommand + #Region "cmdMainWindow_ContentRendered" ''' @@ -288,6 +346,9 @@ Namespace EgtCAM5 Application.Msn.Register(Application.CLOSEAPPLICATIONCOMMAND, Sub() Application.Current.MainWindow.Close() End Sub) + Application.Msn.Register(Application.ALLOWWINDOWTOCLOSE, Sub(bBoolean As Boolean) + m_allowWindowToClose = bBoolean + End Sub) End Sub ''' @@ -470,6 +531,16 @@ Namespace EgtCAM5 End If End Sub +#End Region + +#Region "Verify closing" + + ''' + ''' Should we let our window close? + ''' + Private m_allowWindowToClose As Boolean = False + + #End Region End Class diff --git a/ProjectPage/ProjectViewModel.vb b/ProjectPage/ProjectViewModel.vb index f470a8f..01e1dfb 100644 --- a/ProjectPage/ProjectViewModel.vb +++ b/ProjectPage/ProjectViewModel.vb @@ -519,6 +519,10 @@ Namespace EgtCAM5 Application.Msn.Register(Application.EXECUTECOMMAND, Sub(sString As Controller.CMD) m_Controller.ExecuteCommand(sString) End Sub) + Application.Msn.Register(Application.MANAGEMODIFIED, Sub() + Dim AllowClose = m_Controller.ManageModified() + Application.Msn.NotifyColleagues(Application.ALLOWWINDOWTOCLOSE, AllowClose) + End Sub) End Sub Sub RegisterMainWindowCommands()