Skip to content

Commit 651eff7

Browse files
Merge remote-tracking branch 'origin/develop-6.7' into merge-6.7.8-071015_2
Refactor changes to 'answer' and 'ask' commands
2 parents 21a0d3b + b7c6eb8 commit 651eff7

3 files changed

Lines changed: 81 additions & 26 deletions

File tree

docs/notes/bugfix-16111.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Save As dialog always opens in a folder deep in LiveCode's app bundle

engine/src/answer.cpp

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,21 @@ void MCAnswer::exec_ctxt(MCExecContext& ctxt)
344344
MCAutoStringRef t_initial_resolved;
345345
if (*t_initial != nil)
346346
{
347-
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
348-
if (!MCS_resolvepath(*t_initial, &t_initial_resolved))
347+
// We only want to resolve the path if it is relative
348+
// (otherwise it will be created where LiveCode is located)
349+
if (MCStringContains(*t_initial, MCSTR("/"), kMCStringOptionCompareExact))
349350
{
350-
ctxt . LegacyThrow(EE_NO_MEMORY);
351-
return;
351+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
352+
if (!MCS_resolvepath(*t_initial, &t_initial_resolved))
353+
{
354+
ctxt . LegacyThrow(EE_NO_MEMORY);
355+
return;
356+
}
357+
}
358+
else
359+
{
360+
// We simply take the initial path as it is
361+
t_initial_resolved = *t_initial;
352362
}
353363
}
354364

@@ -381,11 +391,21 @@ void MCAnswer::exec_ctxt(MCExecContext& ctxt)
381391
MCAutoStringRef t_initial_resolved;
382392
if (*t_initial != nil)
383393
{
384-
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
385-
if (!MCS_resolvepath(*t_initial, &t_initial_resolved))
394+
// We only want to resolve the path if it is relative
395+
// (otherwise it will be created where LiveCode is located)
396+
if (MCStringContains(*t_initial, MCSTR("/"), kMCStringOptionCompareExact))
386397
{
387-
ctxt . LegacyThrow(EE_NO_MEMORY);
388-
return;
398+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
399+
if (!MCS_resolvepath(*t_initial, &t_initial_resolved))
400+
{
401+
ctxt . LegacyThrow(EE_NO_MEMORY);
402+
return;
403+
}
404+
}
405+
else
406+
{
407+
// We simply take the initial path as it is
408+
t_initial_resolved = *t_initial;
389409
}
390410
}
391411

@@ -634,11 +654,18 @@ Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
634654
t_initial_resolved = nil;
635655

636656
if (!t_error && t_initial != nil)
637-
{
638-
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
639-
t_initial_resolved = MCS_get_canonical_path(t_initial);
640-
if (nil == t_initial_resolved)
641-
t_error == EE_NO_MEMORY;
657+
{
658+
// We only want to resolve the path if the path is relative (otherwise
659+
// it will be created at the current folder - which is /Applications)
660+
if (strchr(t_initial, '/'))
661+
{
662+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
663+
t_initial_resolved = MCS_get_canonical_path(t_initial);
664+
if (nil == t_initial_resolved)
665+
t_error = EE_NO_MEMORY;
666+
}
667+
else
668+
t_initial_resolved = strclone(t_initial);
642669
}
643670

644671
if (!t_error)
@@ -700,11 +727,18 @@ Exec_errors MCAnswer::exec_folder(MCExecPoint& ep, const char *p_title)
700727
t_initial_resolved = nil;
701728

702729
if (!t_error && t_initial != nil)
703-
{
704-
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
705-
t_initial_resolved = MCS_get_canonical_path(t_initial);
706-
if (nil == t_initial_resolved)
707-
t_error == EE_NO_MEMORY;
730+
{
731+
// We only want to resolve the path if the path is relative (otherwise
732+
// it will be created at the current folder - which is /Applications)
733+
if (strchr(t_initial, '/'))
734+
{
735+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
736+
t_initial_resolved = MCS_get_canonical_path(t_initial);
737+
if (nil == t_initial_resolved)
738+
t_error = EE_NO_MEMORY;
739+
}
740+
else
741+
t_initial_resolved = strclone(t_initial);
708742
}
709743

710744
if (!t_error)

engine/src/ask.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,21 @@ void MCAsk::exec_ctxt(class MCExecContext& ctxt)
261261
MCAutoStringRef t_initial_resolved;
262262
if (*t_initial != nil)
263263
{
264-
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
265-
if (!MCS_resolvepath(*t_initial, &t_initial_resolved))
264+
// We only want to resolve the path if it is relative
265+
// (otherwise it will be created where LiveCode is located)
266+
if (MCStringContains(*t_initial, MCSTR("/"), kMCStringOptionCompareExact))
266267
{
267-
ctxt . LegacyThrow(EE_NO_MEMORY);
268-
return;
268+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
269+
if (!MCS_resolvepath(*t_initial, &t_initial_resolved))
270+
{
271+
ctxt . LegacyThrow(EE_NO_MEMORY);
272+
return;
273+
}
274+
}
275+
else
276+
{
277+
// We simply take the initial path as it is
278+
t_initial_resolved = *t_initial;
269279
}
270280
}
271281

@@ -417,10 +427,20 @@ Exec_errors MCAsk::exec_file(MCExecPoint& ep, const char *p_title)
417427

418428
if (!t_error && t_initial != nil)
419429
{
420-
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
421-
t_initial_resolved = MCS_get_canonical_path(t_initial);
422-
if (nil == t_initial_resolved)
423-
t_error == EE_NO_MEMORY;
430+
// We only want to resolve the path if the path is relative (otherwise
431+
// it will be created at the current folder - which is /Applications)
432+
if (strchr(t_initial, '/'))
433+
{
434+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
435+
t_initial_resolved = MCS_get_canonical_path(t_initial);
436+
if (nil == t_initial_resolved)
437+
t_error = EE_NO_MEMORY;
438+
}
439+
else
440+
{
441+
// Simply copy the file path
442+
t_initial_resolved = strclone(*t_initial);
443+
}
424444
}
425445

426446
if (!t_error)

0 commit comments

Comments
 (0)