Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 83984de

Browse files
committed
[[ Bug 12686 ]] Previous change ported to platform API.
1 parent eac31f5 commit 83984de

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

engine/src/desktop-ans.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,32 @@
3030

3131
////////////////////////////////////////////////////////////////////////////////
3232

33+
// MW-2014-06-25: [[ Bug 12686 ]] Make sure we first try the defaultStack, then
34+
// the topStack.
35+
static MCPlatformWindowRef compute_sheet_owner(unsigned int p_options)
36+
{
37+
if ((p_options & MCA_OPTION_SHEET) == 0)
38+
return nil;
39+
40+
MCPlatformWindowRef t_window;
41+
t_window = MCdefaultstackptr -> getwindow();
42+
if (t_window != nil && MCPlatformIsWindowVisible(t_window))
43+
return t_window;
44+
45+
t_window = MCtopstackptr -> getwindow();
46+
if (t_window != nil && MCPlatformIsWindowVisible(t_window))
47+
return t_window;
48+
49+
return nil;
50+
}
51+
52+
////////////////////////////////////////////////////////////////////////////////
53+
3354
// MM-2012-02-13: Updated to use Cocoa APIs. Code mostly cribbed from plugin dialog stuff
3455
int MCA_folder(MCExecPoint& ep, const char *p_title, const char *p_prompt, const char *p_initial, unsigned int p_options)
3556
{
3657
MCPlatformWindowRef t_owner;
37-
if ((p_options & MCA_OPTION_SHEET) != 0)
38-
t_owner = MCtopstackptr -> getwindow();
39-
else
40-
t_owner = nil;
58+
t_owner = compute_sheet_owner(p_options);
4159

4260
MCPlatformBeginFolderDialog(t_owner, p_title, p_prompt, p_initial);
4361

@@ -126,10 +144,7 @@ int MCA_file(MCExecPoint& ep, const char *p_title, const char *p_prompt, const c
126144
filter_to_type_list(p_filter, t_types, t_type_count);
127145

128146
MCPlatformWindowRef t_owner;
129-
if ((p_options & MCA_OPTION_SHEET) != 0)
130-
t_owner = MCtopstackptr -> getwindow();
131-
else
132-
t_owner = nil;
147+
t_owner = compute_sheet_owner(p_options);
133148

134149
MCPlatformFileDialogKind t_kind;
135150
if ((p_options & MCA_OPTION_PLURAL) != 0)
@@ -167,10 +182,7 @@ int MCA_file(MCExecPoint& ep, const char *p_title, const char *p_prompt, const c
167182
int MCA_file_with_types(MCExecPoint& ep, const char *p_title, const char *p_prompt, char * const p_types[], uint4 p_type_count, const char *p_initial, unsigned int p_options)
168183
{
169184
MCPlatformWindowRef t_owner;
170-
if ((p_options & MCA_OPTION_SHEET) != 0)
171-
t_owner = MCtopstackptr -> getwindow();
172-
else
173-
t_owner = nil;
185+
t_owner = compute_sheet_owner(p_options);
174186

175187
MCPlatformFileDialogKind t_kind;
176188
if ((p_options & MCA_OPTION_PLURAL) != 0)
@@ -216,10 +228,7 @@ int MCA_ask_file(MCExecPoint& ep, const char *p_title, const char *p_prompt, con
216228
filter_to_type_list(p_filter, t_types, t_type_count);
217229

218230
MCPlatformWindowRef t_owner;
219-
if ((p_options & MCA_OPTION_SHEET) != 0)
220-
t_owner = MCtopstackptr -> getwindow();
221-
else
222-
t_owner = nil;
231+
t_owner = compute_sheet_owner(p_options);
223232

224233
MCPlatformBeginFileDialog(kMCPlatformFileDialogKindSave, t_owner, p_title, p_prompt, t_types, t_type_count, p_initial);
225234

@@ -251,10 +260,7 @@ int MCA_ask_file(MCExecPoint& ep, const char *p_title, const char *p_prompt, con
251260
int MCA_ask_file_with_types(MCExecPoint& ep, const char *p_title, const char *p_prompt, char * const p_types[], uint4 p_type_count, const char *p_initial, unsigned int p_options)
252261
{
253262
MCPlatformWindowRef t_owner;
254-
if ((p_options & MCA_OPTION_SHEET) != 0)
255-
t_owner = MCtopstackptr -> getwindow();
256-
else
257-
t_owner = nil;
263+
t_owner = compute_sheet_owner(p_options);
258264

259265
MCPlatformBeginFileDialog(kMCPlatformFileDialogKindSave, t_owner, p_title, p_prompt, p_types, p_type_count, p_initial);
260266

0 commit comments

Comments
 (0)