diff --git a/VECTO3GUI/Helper/FileDialogHelper.cs b/VECTO3GUI/Helper/FileDialogHelper.cs index e8bfe59e80d6798c8db1502f09c8672edabbba55..9ca61b169232367db5739dcd1d566d3ef4139d36 100644 --- a/VECTO3GUI/Helper/FileDialogHelper.cs +++ b/VECTO3GUI/Helper/FileDialogHelper.cs @@ -14,7 +14,7 @@ namespace VECTO3GUI.Helper public static class FileDialogHelper { public const string XMLFilter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*"; - public const string JobFilter = "Job Files (*.vectojob|*.vectojob|All Files (*.*)|*.*"; + public const string JobFilter = "Vecto Files (*.vecto|*.vecto|All Files (*.*)|*.*"; public static string[] ShowSelectFilesDialog(bool multiselect) { diff --git a/VECTO3GUI/ViewModel/Impl/AbstractBusJobViewModel.cs b/VECTO3GUI/ViewModel/Impl/AbstractBusJobViewModel.cs index ead3ff00bf527140a55a53e8739aa39a9b3fb4e2..7ff301c9b793492efcd3dffbacfd485d1cefa5b3 100644 --- a/VECTO3GUI/ViewModel/Impl/AbstractBusJobViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/AbstractBusJobViewModel.cs @@ -1,5 +1,5 @@ using System; -using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -23,7 +23,7 @@ namespace VECTO3GUI.ViewModel.Impl { CompletedBusFile, PrimaryBusFile, - PIFBusFile + PIFBusFile, } public static class JobFileTypeHelper @@ -67,6 +67,7 @@ namespace VECTO3GUI.ViewModel.Impl protected SettingsModel Settings { get; private set; } protected JobType JobType; + protected JobEntry JobEntry; private readonly bool _editJob; #endregion @@ -147,6 +148,8 @@ namespace VECTO3GUI.ViewModel.Impl private void SetJobEntryData(JobEntry jobEntry) { + JobEntry = jobEntry; + FirstFilePath = jobEntry.Header.JobType == JobType.SingleBusJob ? jobEntry.Body.PrimaryVehicle : jobEntry.Body.PrimaryVehicleResults; @@ -167,7 +170,7 @@ namespace VECTO3GUI.ViewModel.Impl } private void DoSelectFirstFileCommand(JobFileType jobFileType) { - FirstFilePath = OpenFileSelector(jobFileType, nameof(FirstFilePath)); + FirstFilePath = OpenFileSelector(jobFileType, nameof(FirstFilePath), FirstFilePath); } public ICommand SelectSecondFileCommand @@ -180,7 +183,7 @@ namespace VECTO3GUI.ViewModel.Impl } private void DoSelectSecondFileCommand(JobFileType jobFileType) { - SecondFilePath = OpenFileSelector(jobFileType, nameof(SecondFilePath)); + SecondFilePath = OpenFileSelector(jobFileType, nameof(SecondFilePath), SecondFilePath); } public ICommand CancelCommand @@ -253,23 +256,46 @@ namespace VECTO3GUI.ViewModel.Impl } - private string OpenFileSelector(JobFileType jobFileType, string textPropertyName) + private string OpenFileSelector(JobFileType jobFileType, string textPropertyName, string filePath) { - var dialogResult = FileDialogHelper.ShowSelectFilesDialog(false, FileDialogHelper.XMLFilter, Settings.XmlFilePathFolder); - if (dialogResult == null) - return null; + var folderPath = GetFolderPath(filePath); - var filePath = dialogResult.FirstOrDefault(); - var validationResult = IsValideXml(jobFileType, filePath); + var dialogResult = FileDialogHelper.ShowSelectFilesDialog(false, FileDialogHelper.XMLFilter, folderPath); + if (dialogResult != null) { - if (!validationResult) - AddPropertyError(textPropertyName, $"Selected XML-File is not a valid {jobFileType.GetLable()}!"); - else - RemovePropertyError(textPropertyName); + filePath = dialogResult.FirstOrDefault(); + var validationResult = IsValideXml(jobFileType, filePath); + + if (!validationResult) + AddPropertyError(textPropertyName, $"Selected XML-File is not a valid {jobFileType.GetLable()}!"); + else + RemovePropertyError(textPropertyName); - return !validationResult ? null : filePath; + return !validationResult ? null : filePath; + } + + return filePath; } + private string GetFolderPath(string filePath) + { + if (!_editJob || filePath.IsNullOrEmpty()) + return Settings.XmlFilePathFolder; + + if (IsFileName(filePath)) { + return !JobEntry.JobEntryFilePath.IsNullOrEmpty() + ? Path.GetDirectoryName(JobEntry.JobEntryFilePath) + : Path.GetDirectoryName(Settings.XmlFilePathFolder); + } + + return filePath; + } + + private bool IsFileName( string filePath) + { + return !Directory.Exists(filePath); + } + private bool IsValideXml(JobFileType jobFileType, string filePath) { if (filePath.IsNullOrEmpty()) diff --git a/VECTO3GUI/ViewModel/Impl/JoblistViewModel.cs b/VECTO3GUI/ViewModel/Impl/JoblistViewModel.cs index b88563191e991c0f043a46e7a8eb3315eedefd27..88f82773cd5962197826f596d54b09f1d1d3c2a0 100644 --- a/VECTO3GUI/ViewModel/Impl/JoblistViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/JoblistViewModel.cs @@ -48,6 +48,7 @@ namespace VECTO3GUI.ViewModel.Impl private ICommand _moveJobDownCommand; private ICommand _startSimulationCommand; private ICommand _openInFolderCommand; + private ICommand _doubleClickCommand; #endregion @@ -125,6 +126,19 @@ namespace VECTO3GUI.ViewModel.Impl #region Commands + + public ICommand DoubleClickCommand + { + get { return _doubleClickCommand ?? (_doubleClickCommand = new RelayCommand<JobEntry>(DoDoubleClick)); } + } + private void DoDoubleClick(JobEntry jobEntry) + { + if (!CanEditCompletdFile(jobEntry)) + return; + DoEditJob(jobEntry); + } + + public ICommand RemoveJob { get diff --git a/VECTO3GUI/ViewModel/Interfaces/IJoblistViewModel.cs b/VECTO3GUI/ViewModel/Interfaces/IJoblistViewModel.cs index 09bcf5e9d90d3b5a1735bf6ca7810ff73a63706f..0eb145dae962f2dd62db6c43ded2b41af409f722 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IJoblistViewModel.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IJoblistViewModel.cs @@ -23,5 +23,7 @@ namespace VECTO3GUI.ViewModel.Interfaces ICommand OpenSettings { get; } ICommand ExitMainCommand { get; } ICommand OpenInFolder { get; } + ICommand DoubleClickCommand { get; } + } } diff --git a/VECTO3GUI/Views/JoblistTabView.xaml b/VECTO3GUI/Views/JoblistTabView.xaml index f5391b0b561d4f8594d818f793509b59acab96da..54a665f085084ecc6aa3070abc1abf7737bfbb7b 100644 --- a/VECTO3GUI/Views/JoblistTabView.xaml +++ b/VECTO3GUI/Views/JoblistTabView.xaml @@ -34,7 +34,7 @@ CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/> <MenuItem Header="Save to" Command="{Binding SaveToJob}"/> <Separator HorizontalAlignment="Stretch" Background="Gray"/> - <MenuItem Header="Exit" + <MenuItem Header="Close" Command="{Binding CloseJob}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/> </MenuItem> diff --git a/VECTO3GUI/Views/JoblistView.xaml b/VECTO3GUI/Views/JoblistView.xaml index 8cc63c9467189b5db115e826fec105a9ddb97036..aef6a140c9acb615e0834e1a634d6da4a71f9951 100644 --- a/VECTO3GUI/Views/JoblistView.xaml +++ b/VECTO3GUI/Views/JoblistView.xaml @@ -64,7 +64,16 @@ <DataGrid x:Name="JobList" ItemsSource="{Binding Jobs}" SelectedValue="{Binding DataContext.SelectedJobEntry, RelativeSource={RelativeSource AncestorType=views:JoblistView}}" Style="{DynamicResource AzureDataGrid}" BorderThickness="1" CanUserAddRows="False" AutoGenerateColumns="False" SelectionUnit="FullRow" - IsReadOnly="False" HeadersVisibility="All" RowHeaderWidth="5" > + IsReadOnly="False" HeadersVisibility="All" RowHeaderWidth="5" IsSynchronizedWithCurrentItem="True" > + + <DataGrid.InputBindings> + <MouseBinding + MouseAction="LeftDoubleClick" + Command="{Binding DoubleClickCommand}" + CommandParameter="{Binding Jobs/}"/> + </DataGrid.InputBindings> + + <DataGrid.Resources> <ContextMenu x:Key="RowMenu">