diff --git a/VECTO3GUI2020/Helper/ProcessHelper.cs b/VECTO3GUI2020/Helper/ProcessHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..a5383aa430a705134b34b18323ca71ed3cb8c141 --- /dev/null +++ b/VECTO3GUI2020/Helper/ProcessHelper.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VECTO3GUI2020.Helper +{ + public static class ProcessHelper + { + + public static void OpenFolder(string path) + { + if (path == null) + { + return; + } + + path = Path.GetFullPath(path); + + var explorerCommandStrBuilder = new StringBuilder(); + explorerCommandStrBuilder.Append("explorer.exe"); + explorerCommandStrBuilder.Append(" /select "); + explorerCommandStrBuilder.Append(path); + + StartProcess("explorer.exe", ("/select," + path)); + } + + + + public static void OpenFile(string path) + { + if (path == null) + { + return; + } + + StartProcess(path); + + + } + + private static void StartProcess(string command, params string[] arguments) + { + string argumentsString = ""; + if (arguments != null) + { + var argumentsStrBuilder = new StringBuilder(); + foreach (var argument in arguments) + { + argumentsStrBuilder.Append(argument); + if (argument != arguments.Last()) + { + argumentsStrBuilder.Append(" "); + } + } + + argumentsString = argumentsStrBuilder.ToString(); + Debug.WriteLine(argumentsString); + } + + try + { + Process.Start(command, argumentsString); + } + catch (Exception e) + { + Debug.WriteLine(e.Message); + } + } + + } +} diff --git a/VECTO3GUI2020/MainWindow.xaml b/VECTO3GUI2020/MainWindow.xaml index 7a5938e4aa38d802ab8f5d419f67c0557f9938b7..195e1ac57fd128ffa20c4bbbb5248bd5570c97f0 100644 --- a/VECTO3GUI2020/MainWindow.xaml +++ b/VECTO3GUI2020/MainWindow.xaml @@ -20,11 +20,11 @@ <DockPanel Margin="0 0 0 0"> <StackPanel DockPanel.Dock="Top" Grid.Row="0" Orientation="Vertical"> <Menu IsMainMenu="True"> - <MenuItem Header="File" x:Name="MenuItemFile" AutomationProperties.Name="=" VerticalAlignment="Stretch"> + <MenuItem Header="File" VerticalAlignment="Stretch"> <MenuItem Header="New File"> - <MenuItem Header="Primary and Interim Job" Command="{Binding JobListVm.NewVifCommand}"/> - <MenuItem Header="Interim/Completed Job" Command="{Binding JobListVm.NewManufacturingStageFileCommand}"/> - <MenuItem Header="Complete Job"></MenuItem> + <MenuItem Header="New Primary and Interim Job" Command="{Binding JobListVm.NewVifCommand}"/> + <MenuItem Header="New Interim/Completed Job" Command="{Binding JobListVm.NewManufacturingStageFileCommand}"/> + <MenuItem Header="New Complete Job"></MenuItem> <Separator></Separator> <MenuItem Header="Create interim/completeted input" Command="{Binding JobListVm.NewCompletedInputCommand}"/> <MenuItem Header="Create extemted interim/completed input" Command="{Binding JobListVm.NewExemptedCompletedInputCommand}"/> @@ -32,6 +32,14 @@ <MenuItem Header="Load File" Command="{Binding AddJob}"/> <MenuItem Header="Settings" Command="{Binding OpenSettings}"/> </MenuItem> + <MenuItem Header="Edit" VerticalAlignment="Stretch"> + <MenuItem Header="Edit Job" ToolTip="Edit selected Job" Command="{Binding JobListVm.EditDocument}"/> + <MenuItem Header="Source File"> + <MenuItem Header="Show in Explorer" Command="{Binding JobListVm.ShowSourceFileCommand}"/> + <MenuItem Header="Open in Editor" Command="{Binding JobListVm.OpenSourceFileCommand}"/> + </MenuItem> + <!--<MenuItem Header="Simulate Job" ToolTip="Simulates the selected Job"/>--> + </MenuItem> </Menu> </StackPanel> <UniformGrid Margin="0 10 0 0 " Rows="1" DockPanel.Dock="Top" Width="400" HorizontalAlignment="Left"> diff --git a/VECTO3GUI2020/VECTO3GUI2020.csproj b/VECTO3GUI2020/VECTO3GUI2020.csproj index afcc049844fc2a6d94eb48ccccc5731e5769c31d..0694a9e9318226ce283fdc8a30e6c53c17702950 100644 --- a/VECTO3GUI2020/VECTO3GUI2020.csproj +++ b/VECTO3GUI2020/VECTO3GUI2020.csproj @@ -180,6 +180,7 @@ <Compile Include="Helper\FileHelper.cs" /> <Compile Include="Helper\IWindowHelper.cs" /> <Compile Include="Helper\DialogHelper.cs" /> + <Compile Include="Helper\ProcessHelper.cs" /> <Compile Include="Helper\VisualTreeHelperExtensions.cs" /> <Compile Include="Helper\TemplateSelector\MultistageParameterDataTemplateSelector.cs" /> <Compile Include="ViewModel\Implementation\Common\AdditionalJobInfoViewModel.cs" /> diff --git a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs index 8d4b27c56f1523411089de07c69433c599dac149..2c0900405ea84929d92543e4583721efc438112c 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs @@ -64,6 +64,8 @@ namespace VECTO3GUI2020.ViewModel.Implementation { if(SetProperty(ref _selectedJob, value)) { RemoveJob.NotifyCanExecuteChanged(); + _openSourceFileCommand?.NotifyCanExecuteChanged(); + _showSourceFileInExplorerCommand?.NotifyCanExecuteChanged(); }; } @@ -722,8 +724,30 @@ namespace VECTO3GUI2020.ViewModel.Implementation private ICommand _openNewFilePopUpCommand; private ICommand _newCompletedInputCommand; private ICommand _newExemptedCompletedInputCommand; - private ICommand _openAdditionalJobInformationCommand; + private IRelayCommand _openSourceFileCommand; + private IRelayCommand _showSourceFileInExplorerCommand; + + + public ICommand OpenSourceFileCommand + { + get + { + return _openSourceFileCommand ?? (_openSourceFileCommand = + new RelayCommand(() => { ProcessHelper.OpenFile(_selectedJob?.DataSource.SourceFile); }, + () => _selectedJob != null)); + } + } + + public ICommand ShowSourceFileCommand + { + get + { + return _showSourceFileInExplorerCommand ?? (_showSourceFileInExplorerCommand = + new RelayCommand(() => { ProcessHelper.OpenFolder(_selectedJob?.DataSource.SourceFile); }, + () => _selectedJob != null)); + } + } public ICommand OpenPopUpCommand @@ -982,7 +1006,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation return _openAdditionalJobInformationCommand ?? (_openAdditionalJobInformationCommand = new RelayCommand<IDocumentViewModel>( (docVm) => { _windowHelper.ShowWindow(docVm.AdditionalJobInfoVm); - }) ); + })); } } diff --git a/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs index e0b8aaa5b15b47fc89e40597789a8403e30b3e6d..3c0b356ea3fc699a732a35d41f195e3fd470b6da 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs @@ -9,6 +9,7 @@ using System.Windows.Data; using System.Windows.Input; using Microsoft.Toolkit.Mvvm.Input; using Microsoft.WindowsAPICodePack.Shell.Interop; +using VECTO3GUI2020.Helper; using VECTO3GUI2020.ViewModel.Implementation; using VECTO3GUI2020.ViewModel.Implementation.Common; using VECTO3GUI2020.ViewModel.Interfaces; @@ -77,62 +78,18 @@ namespace VECTO3GUI2020.ViewModel _openFileCommand ?? (_openFileCommand = new RelayCommand<string>( OpenFileExecute)); - private void OpenFolderExecute(string link) + private void OpenFolderExecute(string path) { - if (link == null) { - return; - } - - link = Path.GetFullPath(link); - - var explorerCommandStrBuilder = new StringBuilder(); - explorerCommandStrBuilder.Append("explorer.exe"); - explorerCommandStrBuilder.Append(" /select "); - explorerCommandStrBuilder.Append(link); - - //var directoryPath = Path.GetDirectoryName(link); - //StartProcess(directoryPath); - - StartProcess("explorer.exe", ("/select," + link)); + ProcessHelper.OpenFolder(path); } - private void OpenFileExecute(string link){ - if (link == null) { + private void OpenFileExecute(string path){ + if (path == null) { return; } - StartProcess(link); - - + ProcessHelper.OpenFile(path); } - - private void StartProcess(string command, params string[]arguments) - { - string argumentsString = ""; - if (arguments != null) { - var argumentsStrBuilder = new StringBuilder(); - foreach (var argument in arguments) { - argumentsStrBuilder.Append(argument); - if(argument != arguments.Last()) { - argumentsStrBuilder.Append(" "); - } - } - - argumentsString = argumentsStrBuilder.ToString(); - Debug.WriteLine(argumentsString); - } - - - try - { - Process.Start(command, argumentsString ); - } - catch (Exception e) - { - Debug.WriteLine(e.Message); - } - } - #endregion } diff --git a/VECTO3GUI2020/ViewModel/Interfaces/IJobListViewModel.cs b/VECTO3GUI2020/ViewModel/Interfaces/IJobListViewModel.cs index a85c14eb36ce19e89f7ef6ec8f8c0173ae5f4bc0..897994d892efbe392c478575faf12f793db94f70 100644 --- a/VECTO3GUI2020/ViewModel/Interfaces/IJobListViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Interfaces/IJobListViewModel.cs @@ -18,6 +18,8 @@ namespace VECTO3GUI2020.ViewModel.Interfaces ICommand EditDocument { get; set; } ICommand ViewXMLFile { get; set; } IAsyncRelayCommand RemoveJob { get; set; } + ICommand OpenSourceFileCommand { get; } + ICommand ShowSourceFileCommand { get; } Task<IDocumentViewModel> AddJobAsync(string fileName, bool runSimulationAfterAdding = false); void AddJob(IDocumentViewModel jobToAdd); }