From 170598cc70cc2272937226d3173a12921ce77b8d Mon Sep 17 00:00:00 2001
From: "harald.martini@student.tugraz.at" <harald.martini@student.tugraz.at>
Date: Tue, 11 May 2021 14:30:40 +0200
Subject: [PATCH] Added Close Button

---
 .../Converter/NullToVisibilityConverter.cs    | 19 +++++++++++++++++--
 .../Implementation/Common/ViewModelBase.cs    | 18 ++++++++++++++++++
 .../MultistageJobViewModel_v0_1.cs            | 14 +++++++++++++-
 .../NewMultiStageJobViewModel.cs              | 11 ++++++++++-
 .../Views/Multistage/MultiStageView.xaml      | 15 ++++++++++++++-
 .../Multistage/NewMultistageFileView.xaml     |  8 ++++++++
 6 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/VECTO3GUI2020/Helper/Converter/NullToVisibilityConverter.cs b/VECTO3GUI2020/Helper/Converter/NullToVisibilityConverter.cs
index 156ca4552b..8857067710 100644
--- a/VECTO3GUI2020/Helper/Converter/NullToVisibilityConverter.cs
+++ b/VECTO3GUI2020/Helper/Converter/NullToVisibilityConverter.cs
@@ -7,13 +7,28 @@ namespace VECTO3GUI2020.Helper.Converter
 {
     class NullToVisibilityConverter : IValueConverter
     {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="value"></param>
+        /// <param name="targetType"></param>
+        /// <param name="parameter">set to "invert" to invert the result</param>
+        /// <param name="culture"></param>
+        /// <returns></returns>
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
-        {
-            if(value == null)
+		{
+			bool invert = parameter as string == "invert";
+            if (value == null)
             {
+				if (invert) {
+					return Visibility.Visible;
+				}
                 return Visibility.Collapsed;
             }
             else {
+				if (invert) {
+					return Visibility.Collapsed;
+				}
 				return Visibility.Visible;
 			}
         }
diff --git a/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs b/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs
index 227bebb57d..876ef38084 100644
--- a/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs
+++ b/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs
@@ -1,6 +1,8 @@
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Runtime.CompilerServices;
+using System.Windows;
+using VECTO3GUI2020.Helper;
 using VECTO3GUI2020.ViewModel.Interfaces.Common;
 
 namespace VECTO3GUI2020.ViewModel.Implementation.Common
@@ -40,5 +42,21 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common
         }
 
 		public virtual string Title { get; set; } = "No Title Set";
+
+		protected void CloseWindow(Window window, IDialogHelper dialogHelper, bool showDialog = true)
+		{
+			MessageBoxResult result;
+			if (showDialog) {
+				result = dialogHelper.ShowMessageBox("Do you really want to close?", "Close", MessageBoxButton.YesNo,
+					MessageBoxImage.Question);
+            } else {
+				result = MessageBoxResult.Yes;
+			}
+			
+
+			if (result == MessageBoxResult.Yes) {
+				window?.Close();
+			}
+		}
 	}
 }
diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs
index ab0664fc21..c24da66929 100644
--- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs
+++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs
@@ -58,6 +58,19 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
 
 
 		#region Commands
+
+
+
+		private ICommand _closeWindowCommand;
+		public ICommand CloseWindowCommand
+		{
+			get
+			{
+				return _closeWindowCommand ?? new RelayCommand<Window>(window => CloseWindow(window, _dialogHelper.Value), window => true);
+			}
+		}
+
+
 		private ICommand _saveVifCommand;
 
 		public ICommand SaveVIFCommand
@@ -296,7 +309,6 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
 			set => _inputComplete = value;
 		}
 
-	
 
 		#endregion
 	}
diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/NewMultiStageJobViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/NewMultiStageJobViewModel.cs
index bb569a84ed..33ff82615d 100644
--- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/NewMultiStageJobViewModel.cs
+++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/NewMultiStageJobViewModel.cs
@@ -86,7 +86,16 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
 			VifPath = fileName;
 		}
 
-		
+
+		private ICommand _closeWindow;
+
+		public ICommand CloseWindow
+		{
+			get => _closeWindow ?? new RelayCommand<Window>(window => base.CloseWindow(window, _dialogHelper, false),
+				(window) => MultiStageJobViewModel == null);
+		}
+
+
 
 		#endregion
 
diff --git a/VECTO3GUI2020/Views/Multistage/MultiStageView.xaml b/VECTO3GUI2020/Views/Multistage/MultiStageView.xaml
index 6fe9f0f105..449554b41c 100644
--- a/VECTO3GUI2020/Views/Multistage/MultiStageView.xaml
+++ b/VECTO3GUI2020/Views/Multistage/MultiStageView.xaml
@@ -16,6 +16,13 @@
                 Text="{Binding VehicleInputDataFilePath, TargetNullValue=Select Vehicle Input Data . . .}"></customControls:FilePicker>
             <Border BorderThickness="1" BorderBrush="{DynamicResource ButtonHighlightColor}" Height="40" DockPanel.Dock="Bottom">
                 <DockPanel LastChildFill="False">
+                    <Button DockPanel.Dock="Right"
+                        Width="100"
+                        Command="{Binding CloseWindowCommand}" 
+                        CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"
+                        Style="{DynamicResource MultiStageButtonStyle1}"
+                        Margin="4"
+                        Padding="4">Close</Button>
                     <Button DockPanel.Dock="Right"
                             Width="100"
                             Command="{Binding SaveVIFCommand}"
@@ -29,7 +36,13 @@
                         Margin="4" 
                         Padding="4" 
                         Command="{Binding SaveInputDataCommand}">Save Input</Button>
-                    <Button DockPanel.Dock="Right" Width="100"  Style="{DynamicResource MultiStageButtonStyle1}" Margin="4" Padding="4" Command="{Binding SaveInputDataAsCommand}">Save Input As ... </Button>
+                    <Button 
+                        DockPanel.Dock="Right" 
+                        Width="100"  
+                        Style="{DynamicResource MultiStageButtonStyle1}" 
+                        Margin="4" 
+                        Padding="4" 
+                        Command="{Binding SaveInputDataAsCommand}">Save Input As ... </Button>
                 </DockPanel>
             </Border>
             <ContentControl DockPanel.Dock="Top" Content="{Binding ManufacturingStageViewModel}"/>
diff --git a/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml b/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml
index 6a6f7ee479..03e223fc51 100644
--- a/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml
+++ b/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml
@@ -14,7 +14,15 @@
                 <Grid DockPanel.Dock="Top">
                     <customControls:FilePicker x:Name="NewMultistageFilePicker" Grid.Row="0" Text="{Binding VifPath}" HorizontalAlignment="Stretch" Command="{Binding AddVifFile}"/>
                 </Grid>
+                <Button Style="{DynamicResource MultiStageButtonStyle1}" 
+                        Margin="4"  DockPanel.Dock="Bottom" 
+                        Visibility="{Binding MultiStageJobViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=invert}"
+                        Command="{Binding CloseWindow}" 
+                        CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">
+                    Cancel
+                </Button>
                 <ContentControl Grid.Row="2" Content="{Binding MultiStageJobViewModel}"/>
+
             </DockPanel>
         </Grid>
     </Grid>
-- 
GitLab