From 6b08374e294bc8fa5b81e742a088c8596238d3f1 Mon Sep 17 00:00:00 2001 From: "harald.martini@student.tugraz.at" <harald.martini@student.tugraz.at> Date: Tue, 22 Jun 2021 07:59:03 +0200 Subject: [PATCH] Select File in Folder --- .gitignore | 1 + .../Implementation/JobListViewModel.cs | 4 +-- .../Implementation/OutputViewModel.cs | 34 ++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 0f6e6ab57c..27fd0863a2 100644 --- a/.gitignore +++ b/.gitignore @@ -219,3 +219,4 @@ Documentation/VehiclesReleaseComparisonDeclarationMode/tmp/ /VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/tests.xml /VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/finalGroup41.VIF_Report_4.xml /VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/output +/Vecto3GUI2020Test/TestData/output diff --git a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs index 08d76a8756..2ba4e70116 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs @@ -593,14 +593,14 @@ namespace VECTO3GUI2020.ViewModel.Implementation { get { - return _cancelSimulationCommand ?? new RelayCommand(() => { + return _cancelSimulationCommand ?? (_cancelSimulationCommand = new RelayCommand(() => { _outputViewModel.AddMessage(new MessageEntry() { Message="Canceling Simulation", Type=MessageType.StatusMessage, }); cancellationTokenSource.Cancel(); }, - () => SimulationRunning); + () => SimulationRunning)); } } diff --git a/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs index 790a3d2379..e0b8aaa5b1 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; +using System.Linq; +using System.Text; using System.Windows.Data; using System.Windows.Input; using Microsoft.Toolkit.Mvvm.Input; @@ -65,10 +67,12 @@ namespace VECTO3GUI2020.ViewModel #region Commands + // ReSharper disable once UnusedMember.Global public ICommand OpenFolderCommand => _openFolderCommand ?? (_openFolderCommand = new RelayCommand<string>( OpenFolderExecute)); + // ReSharper disable once UnusedMember.Global public ICommand OpenFileCommand => _openFileCommand ?? (_openFileCommand = new RelayCommand<string>( OpenFileExecute)); @@ -79,10 +83,17 @@ namespace VECTO3GUI2020.ViewModel return; } + link = Path.GetFullPath(link); - var directoryPath = Path.GetDirectoryName(link); + var explorerCommandStrBuilder = new StringBuilder(); + explorerCommandStrBuilder.Append("explorer.exe"); + explorerCommandStrBuilder.Append(" /select "); + explorerCommandStrBuilder.Append(link); - StartProcess(directoryPath); + //var directoryPath = Path.GetDirectoryName(link); + //StartProcess(directoryPath); + + StartProcess("explorer.exe", ("/select," + link)); } private void OpenFileExecute(string link){ @@ -95,11 +106,26 @@ namespace VECTO3GUI2020.ViewModel } - private void StartProcess(string command) + 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); + Process.Start(command, argumentsString ); } catch (Exception e) { -- GitLab