11use core:: f32;
22use std:: ops:: RangeInclusive ;
3+ use std:: path:: PathBuf ;
34use std:: sync:: mpsc:: { Sender } ;
45use std:: sync:: { Arc , RwLock } ;
56use std:: time:: Duration ;
@@ -71,7 +72,7 @@ pub struct MyApp {
7172 plotting_range : i32 ,
7273 console : Vec < Print > ,
7374 dropped_files : Vec < egui:: DroppedFile > ,
74- picked_path : String ,
75+ picked_path : PathBuf ,
7576 data : DataContainer ,
7677 gui_conf : GuiSettingsContainer ,
7778 print_lock : Arc < RwLock < Vec < Print > > > ,
@@ -80,7 +81,7 @@ pub struct MyApp {
8081 baud_lock : Arc < RwLock < u32 > > ,
8182 connected_lock : Arc < RwLock < bool > > ,
8283 data_lock : Arc < RwLock < DataContainer > > ,
83- save_tx : Sender < String > ,
84+ save_tx : Sender < PathBuf > ,
8485 send_tx : Sender < String > ,
8586 clear_tx : Sender < bool > ,
8687 eol : String ,
@@ -97,15 +98,15 @@ impl MyApp {
9798 baud_lock : Arc < RwLock < u32 > > ,
9899 connected_lock : Arc < RwLock < bool > > ,
99100 gui_conf : GuiSettingsContainer ,
100- save_tx : Sender < String > ,
101+ save_tx : Sender < PathBuf > ,
101102 send_tx : Sender < String > ,
102103 clear_tx : Sender < bool > ,
103104 ) -> Self {
104105 Self {
105106 dark_mode : true ,
106107 ready : false ,
107108 dropped_files : vec ! [ ] ,
108- picked_path : "" . to_string ( ) ,
109+ picked_path : PathBuf :: new ( ) ,
109110 device : "" . to_string ( ) ,
110111 data : DataContainer :: default ( ) ,
111112 console : vec ! [ Print :: MESSAGE ( format!( "waiting for serial connection..," ) . to_string( ) ) ] ,
@@ -381,20 +382,22 @@ impl eframe::App for MyApp {
381382 ui. end_row ( ) ;
382383 if ui. button ( "Save to file" ) . clicked ( ) {
383384 match rfd:: FileDialog :: new ( ) . save_file ( ) {
384- Some ( path) =>
385- // TODO: here we should really include .csv as extension!
385+ Some ( mut path) =>
386386 {
387- let extension = ".csv" . to_string ( ) ;
388- let mut final_path: String ;
389- if path. display ( ) . to_string ( ) . ends_with ( ".csv" ) {
390- final_path = path. display ( ) . to_string ( ) ;
391- } else {
392- final_path = path. display ( ) . to_string ( ) ;
393- final_path. push_str ( & extension) ;
387+ let extension = "csv" ;
388+ match path. extension ( ) {
389+ None => {
390+ path. set_extension ( & extension) ;
391+ }
392+ Some ( ext) => {
393+ if ext != "csv" {
394+ path. set_extension ( & extension) ;
395+ }
396+ }
394397 }
395- self . picked_path = final_path ;
398+ self . picked_path = path ;
396399 }
397- None => self . picked_path = "" . to_string ( )
400+ None => self . picked_path = PathBuf :: new ( )
398401 }
399402 match self . save_tx . send ( self . picked_path . clone ( ) ) {
400403 Ok ( _) => { }
0 commit comments