@@ -23,32 +23,48 @@ enum DialogType {
2323
2424/// Open single file dialog
2525#[ inline( always) ]
26- pub fn open_file_dialog ( filter_list : & str , default_path : & str ) -> NFDResult {
26+ pub fn open_file_dialog ( filter_list : Option < & str > , default_path : Option < & str > ) -> NFDResult {
2727 open_dialog ( filter_list, default_path, & DialogType :: SingleFile )
2828}
2929
3030/// Open save dialog
3131#[ inline( always) ]
32- pub fn open_save_dialog ( filter_list : & str , default_path : & str ) -> NFDResult {
32+ pub fn open_save_dialog ( filter_list : Option < & str > , default_path : Option < & str > ) -> NFDResult {
3333 open_dialog ( filter_list, default_path, & DialogType :: SaveFile )
3434}
3535
36- fn open_dialog ( filter_list : & str , default_path : & str , dialog_type : & DialogType ) -> NFDResult {
36+ fn open_dialog ( filter_list : Option < & str > , default_path : Option < & str > , dialog_type : & DialogType ) -> NFDResult {
3737 let result: nfdresult_t ;
3838 let result_cstring;
3939
40- let filter_list_cstring = CString :: new ( filter_list) . unwrap ( ) ;
41- let default_path_cstring = CString :: new ( default_path) . unwrap ( ) ;
40+ let filter_list_cstring;
41+ let filter_list_ptr = match filter_list {
42+ Some ( fl_str) => {
43+ filter_list_cstring = CString :: new ( fl_str) . unwrap ( ) ;
44+ filter_list_cstring. as_ptr ( )
45+ }
46+ None => std:: ptr:: null ( )
47+ } ;
48+
49+ let default_path_cstring;
50+ let default_path_ptr = match default_path {
51+ Some ( dp_str) => {
52+ default_path_cstring = CString :: new ( dp_str) . unwrap ( ) ;
53+ default_path_cstring. as_ptr ( )
54+ }
55+ None => std:: ptr:: null ( )
56+ } ;
57+
4258 let out_path = CString :: new ( "" ) . unwrap ( ) . into_raw ( ) as * mut * mut c_char ;
4359
4460 unsafe {
4561 result = match dialog_type {
4662 & DialogType :: SingleFile => {
47- NFD_OpenDialog ( filter_list_cstring . as_ptr ( ) , default_path_cstring . as_ptr ( ) , out_path)
63+ NFD_OpenDialog ( filter_list_ptr , default_path_ptr , out_path)
4864 } ,
4965
5066 & DialogType :: SaveFile => {
51- NFD_SaveDialog ( filter_list_cstring . as_ptr ( ) , default_path_cstring . as_ptr ( ) , out_path)
67+ NFD_SaveDialog ( filter_list_ptr , default_path_ptr , out_path)
5268 } ,
5369 } ;
5470
0 commit comments