From ebcecce79f1ffb87b0a8b5d28fcc987da4fbea63 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Tue, 25 May 2021 13:23:21 +0200 Subject: [PATCH] added output path to gui --- VECTO3GUI2020/App.config | 3 ++ VECTO3GUI2020/Properties/Settings.Designer.cs | 12 ++++++ VECTO3GUI2020/Properties/Settings.settings | 3 ++ .../Implementation/JobListViewModel.cs | 29 ++++++------- .../Implementation/SettingsViewModel.cs | 34 +++++++++++++-- VECTO3GUI2020/Views/SettingsView.xaml | 43 ++++++++++++++----- 6 files changed, 94 insertions(+), 30 deletions(-) diff --git a/VECTO3GUI2020/App.config b/VECTO3GUI2020/App.config index 0251970b1f..f16f0863ce 100644 --- a/VECTO3GUI2020/App.config +++ b/VECTO3GUI2020/App.config @@ -37,6 +37,9 @@ <setting name="SerializeVectoRunData" serializeAs="String"> <value>True</value> </setting> + <setting name="DefaultOutputPath" serializeAs="String"> + <value /> + </setting> </VECTO3GUI2020.Properties.Settings> </userSettings> <runtime> diff --git a/VECTO3GUI2020/Properties/Settings.Designer.cs b/VECTO3GUI2020/Properties/Settings.Designer.cs index 3bc037f81a..78e0471711 100644 --- a/VECTO3GUI2020/Properties/Settings.Designer.cs +++ b/VECTO3GUI2020/Properties/Settings.Designer.cs @@ -106,5 +106,17 @@ namespace VECTO3GUI2020.Properties { this["SerializeVectoRunData"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string DefaultOutputPath { + get { + return ((string)(this["DefaultOutputPath"])); + } + set { + this["DefaultOutputPath"] = value; + } + } } } diff --git a/VECTO3GUI2020/Properties/Settings.settings b/VECTO3GUI2020/Properties/Settings.settings index 2df355f46b..7d279b47c5 100644 --- a/VECTO3GUI2020/Properties/Settings.settings +++ b/VECTO3GUI2020/Properties/Settings.settings @@ -23,5 +23,8 @@ <Setting Name="SerializeVectoRunData" Type="System.Boolean" Scope="User"> <Value Profile="(Default)">True</Value> </Setting> + <Setting Name="DefaultOutputPath" Type="System.String" Scope="User"> + <Value Profile="(Default)" /> + </Setting> </Settings> </SettingsFile> \ No newline at end of file diff --git a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs index 70c23b77c8..20b83f277a 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs @@ -187,13 +187,14 @@ namespace VECTO3GUI2020.ViewModel.Implementation Time = DateTime.Now, Type = MessageType.InfoMessage, }); + return; } } //TODO add output path to settings var outputPath = Settings.Default.DefaultFilePath; - var sumFileWriter = new FileOutputWriter(outputPath); + var sumFileWriter = new FileOutputWriter(GetOutputDirectory(Jobs.First(x => x.Selected).DataSource.SourceFile)); @@ -453,21 +454,17 @@ namespace VECTO3GUI2020.ViewModel.Implementation private string GetOutputDirectory(string jobFilePath) { var outFile = jobFilePath; - var OutputDirectory = Settings.Default.DefaultFilePath; - if (!string.IsNullOrWhiteSpace(OutputDirectory)) - { - if (Path.IsPathRooted(OutputDirectory)) - { - outFile = Path.Combine(OutputDirectory, Path.GetFileName(jobFilePath) ?? ""); - } - else - { - outFile = Path.Combine(Path.GetDirectoryName(jobFilePath) ?? "", OutputDirectory, Path.GetFileName(jobFilePath) ?? ""); - } - if (!Directory.Exists(Path.GetDirectoryName(outFile))) - { - Directory.CreateDirectory(Path.GetDirectoryName(outFile)); - } + var outputDirectory = Settings.Default.DefaultOutputPath; + if (string.IsNullOrWhiteSpace(outputDirectory)) { + return outFile; + } + + outFile = Path.IsPathRooted(outputDirectory) + ? Path.Combine(outputDirectory, Path.GetFileName(jobFilePath) ?? "") + : Path.Combine(Path.GetDirectoryName(jobFilePath) ?? "", outputDirectory, + Path.GetFileName(jobFilePath) ?? ""); + if (!Directory.Exists(Path.GetDirectoryName(outFile))) { + Directory.CreateDirectory(Path.GetDirectoryName(outFile)); } return outFile; diff --git a/VECTO3GUI2020/ViewModel/Implementation/SettingsViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/SettingsViewModel.cs index 7b25852acf..e1a1adcb50 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/SettingsViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/SettingsViewModel.cs @@ -17,19 +17,20 @@ namespace VECTO3GUI2020.ViewModel.Implementation private Settings _settings; private ICommand _changePath; - + private ICommand _changeOutPath; private IDialogHelper _dialogHelper; - private String _defaultFilePath; + private string _defaultFilePath; + private string _defaultOutputPath; private bool _writeModalResults; private bool _modalResults1Hz; private bool _validate; private bool _actualModalData; private bool _serializeVectoRunData; - public String DefaultFilePath + public string DefaultFilePath { get => _defaultFilePath; set @@ -40,7 +41,14 @@ namespace VECTO3GUI2020.ViewModel.Implementation } } - + public string DefaultOutputPath { + get => _defaultOutputPath; + set { + _settings.DefaultOutputPath = value; + _settings.Save(); + SetProperty(ref _defaultOutputPath, value, "DefaultOutputPath"); + } + } public SettingsViewModel(IDialogHelper dialogHelper) { @@ -56,6 +64,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation } private ICommand _closeWindowCommand; + public ICommand CloseWindowCommand { get @@ -101,6 +110,21 @@ namespace VECTO3GUI2020.ViewModel.Implementation } } + public ICommand ChangeOutputPath { + get { + return _changeOutPath ?? new RelayCommand(() => { + var new_path = _dialogHelper.OpenFolderDialog(DefaultFilePath); + if (new_path != null) { + DefaultOutputPath = new_path; + } + }, () => { return true; }); + } + private set { + _changeOutPath = value; + OnPropertyChanged(); + } + } + public bool SerializeVectoRunData { get => _serializeVectoRunData; @@ -167,5 +191,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation } } } + + } } diff --git a/VECTO3GUI2020/Views/SettingsView.xaml b/VECTO3GUI2020/Views/SettingsView.xaml index 3f8531f45b..225d950648 100644 --- a/VECTO3GUI2020/Views/SettingsView.xaml +++ b/VECTO3GUI2020/Views/SettingsView.xaml @@ -29,6 +29,7 @@ <ColumnDefinition Width="1*"></ColumnDefinition> </Grid.ColumnDefinitions> <Grid.RowDefinitions> + <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="30"></RowDefinition> <RowDefinition Height="30"></RowDefinition> @@ -41,20 +42,42 @@ Text="{Binding DefaultFilePath}" HorizontalAlignment="Stretch" Command="{Binding ChangeFilePath}"/> - <Label Grid.Row="1" Grid.Column="0">Serialize Vecto Run Data</Label> - <CheckBox Grid.Row="1" Grid.Column="1" IsChecked="{Binding SerializeVectoRunData}"></CheckBox> + <Label Grid.Row="1" Grid.Column="0" DockPanel.Dock="Left">Default Path</Label> + <Grid Grid.Row="1" Grid.Column="1" Margin="4" VerticalAlignment="Stretch" Grid.ColumnSpan="3" DockPanel.Dock="Right"> + <Grid.RowDefinitions> + <RowDefinition></RowDefinition> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition></ColumnDefinition> + <ColumnDefinition Width="30px"></ColumnDefinition> + </Grid.ColumnDefinitions> + <TextBox x:Name="textBox" VerticalContentAlignment="Center" Padding="4" Margin = "0 0 0 0" IsReadOnly="false" + Text="{Binding DefaultOutputPath}" HorizontalAlignment="Stretch" TextWrapping="Wrap" + Style="{DynamicResource TextBoxStyle1}"/> + <Button x:Name="button" Padding="4" Margin="4 0 0 0" Grid.Column="1" ContentTemplate="{DynamicResource AddDocumentIcon}" + Command="{Binding ChangeOutputPath}" Style="{DynamicResource FilePickerButtonStyle}"> + + </Button> + </Grid> + <!--<customControls:FilePicker Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" DockPanel.Dock="Right" + Text="{Binding DefaultOutputPath}" + HorizontalAlignment="Stretch" Command="{Binding ChangeOutputPath}"/>--> + + + <Label Grid.Row="2" Grid.Column="0">Serialize Vecto Run Data</Label> + <CheckBox Grid.Row="2" Grid.Column="1" IsChecked="{Binding SerializeVectoRunData}"></CheckBox> - <Label Grid.Row="1" Grid.Column="2">Write Modal Results</Label> - <CheckBox Grid.Row="1" Grid.Column="3" IsChecked="{Binding WriteModalResults}"></CheckBox> + <Label Grid.Row="3" Grid.Column="2">Write Modal Results</Label> + <CheckBox Grid.Row="3" Grid.Column="3" IsChecked="{Binding WriteModalResults}"></CheckBox> - <Label Grid.Row="2" Grid.Column="0">Validate</Label> - <CheckBox Grid.Row="2" Grid.Column="1" IsChecked="{Binding Validate}"></CheckBox> + <Label Grid.Row="3" Grid.Column="0">Validate</Label> + <CheckBox Grid.Row="3" Grid.Column="1" IsChecked="{Binding Validate}"></CheckBox> - <Label Grid.Row="2" Grid.Column="2">Actual Modal Data</Label> - <CheckBox Grid.Row="2" Grid.Column="3" IsChecked="{Binding ActualModalData}"></CheckBox> + <Label Grid.Row="4" Grid.Column="2">Actual Modal Data</Label> + <CheckBox Grid.Row="4" Grid.Column="3" IsChecked="{Binding ActualModalData}"></CheckBox> - <Label Grid.Row="3" Grid.Column="0">ModalResults1Hz</Label> - <CheckBox Grid.Row="3" Grid.Column="1" IsChecked="{Binding ModalResults1Hz}"></CheckBox> + <Label Grid.Row="4" Grid.Column="0">ModalResults1Hz</Label> + <CheckBox Grid.Row="4" Grid.Column="1" IsChecked="{Binding ModalResults1Hz}"></CheckBox> </Grid> <!--<DockPanel DockPanel.Dock="Bottom" LastChildFill="False"> <Button DockPanel.Dock="Right" -- GitLab