Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 1c3117a1 authored by Harald Martini's avatar Harald Martini
Browse files

Added Show Source File and Open Source File commands

parent 9ecf4b1d
No related branches found
No related tags found
No related merge requests found
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);
}
}
}
}
......@@ -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">
......
......@@ -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" />
......
......@@ -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);
}) );
}));
}
}
......
......@@ -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
}
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment