@@ -42,6 +42,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4242#include " answer.h"
4343#include " printer.h"
4444
45+ #include " osspec.h"
46+
4547const char *MCdialogtypes[] =
4648{
4749 " plain" ,
@@ -494,6 +496,17 @@ Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
494496 if (!t_error && !MCSecureModeCanAccessDisk ())
495497 t_error = EE_DISK_NOPERM;
496498
499+ char *t_initial_resolved;
500+ t_initial_resolved = nil;
501+
502+ if (!t_error && t_initial != nil)
503+ {
504+ // IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
505+ t_initial_resolved = MCS_get_canonical_path (t_initial);
506+ if (nil == t_initial_resolved)
507+ t_error == EE_NO_MEMORY;
508+ }
509+
497510 if (!t_error)
498511 {
499512 if (MCsystemFS && MCscreen -> hasfeature ( PLATFORM_FEATURE_OS_FILE_DIALOGS ) )
@@ -505,23 +518,26 @@ Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
505518 t_options |= MCA_OPTION_PLURAL;
506519
507520 if (t_types != NULL )
508- MCA_file_with_types (ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial , t_options);
521+ MCA_file_with_types (ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial_resolved , t_options);
509522 else
510- MCA_file (ep, p_title, t_prompt, t_filter, t_initial , t_options);
523+ MCA_file (ep, p_title, t_prompt, t_filter, t_initial_resolved , t_options);
511524 }
512525 else
513526 {
514527 MCExecPoint ep2 (ep);
515528 ep2 . clear ();
516529 for (uint4 t_type = 0 ; t_type < t_type_count; ++t_type)
517530 ep2 . concatcstring (t_type_strings[t_type], EC_RETURN, t_type == 0 );
518- t_error = exec_custom (ep, MCfsnamestring, mode == AT_FILE ? " file" : " files" , 5 , p_title, *t_prompt, *t_filter, *t_initial , ep2 . getsvalue () . getstring ());
531+ t_error = exec_custom (ep, MCfsnamestring, mode == AT_FILE ? " file" : " files" , 5 , p_title, *t_prompt, *t_filter, t_initial_resolved , ep2 . getsvalue () . getstring ());
519532 }
520533
521534 if (ep . getsvalue () == MCnullmcstring && t_types == NULL )
522535 MCresult -> sets (MCcancelstring);
523536 }
524537
538+ if (t_initial_resolved != nil)
539+ MCCStringFree (t_initial_resolved);
540+
525541 delete[] t_types;
526542 delete t_type_strings;
527543
@@ -546,6 +562,17 @@ Exec_errors MCAnswer::exec_folder(MCExecPoint& ep, const char *p_title)
546562 if (!t_error && !MCSecureModeCanAccessDisk ())
547563 t_error = EE_DISK_NOPERM;
548564
565+ char *t_initial_resolved;
566+ t_initial_resolved = nil;
567+
568+ if (!t_error && t_initial != nil)
569+ {
570+ // IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
571+ t_initial_resolved = MCS_get_canonical_path (t_initial);
572+ if (nil == t_initial_resolved)
573+ t_error == EE_NO_MEMORY;
574+ }
575+
549576 if (!t_error)
550577 {
551578 unsigned int t_options = 0 ;
@@ -555,14 +582,17 @@ Exec_errors MCAnswer::exec_folder(MCExecPoint& ep, const char *p_title)
555582 t_options |= MCA_OPTION_PLURAL;
556583
557584 if (MCsystemFS)
558- MCA_folder (ep, p_title, t_prompt, t_initial , t_options);
585+ MCA_folder (ep, p_title, t_prompt, t_initial_resolved , t_options);
559586 else
560- t_error = exec_custom (ep, MCfsnamestring, mode == AT_FOLDER ? " folder" : " folders" , 4 , p_title, *t_prompt, NULL , *t_initial );
587+ t_error = exec_custom (ep, MCfsnamestring, mode == AT_FOLDER ? " folder" : " folders" , 4 , p_title, *t_prompt, NULL , t_initial_resolved );
561588
562589 if (ep . getsvalue () == MCnullmcstring)
563590 MCresult -> sets (MCcancelstring);
564591 }
565592
593+ if (t_initial_resolved != nil)
594+ MCCStringFree (t_initial_resolved);
595+
566596 return t_error;
567597}
568598#endif /* MCAnswer::exec_folder */
0 commit comments