Skip to content

Commit 0c6d117

Browse files
authored
Merge pull request livecode#5969 from livecodeian/bugfix-16713
[[ Bug 16713 ]] Check order of buttons when returning answer dialog result
2 parents 7a7dddb + 0f6bb2d commit 0c6d117

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

docs/notes/bugfix-16713.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Return correct button from answer dialog when "ok","cancel" options swapped

engine/src/em-dc.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ MCScreenDC::wait(real64_t p_duration,
291291

292292
// These functions are implemented in javascript
293293
extern "C" int32_t MCEmscriptenDialogShowAlert(const unichar_t* p_message, size_t p_message_length);
294-
extern "C" int32_t MCEmscriptenDialogShowConfirm(const unichar_t* p_message, size_t p_message_length);
294+
extern "C" bool MCEmscriptenDialogShowConfirm(const unichar_t* p_message, size_t p_message_length);
295295
extern "C" int32_t MCEmscriptenDialogShowPrompt(const unichar_t* p_message, size_t p_message_length, const unichar_t* p_default, size_t p_default_length, unichar_t** r_result, size_t* r_result_length);
296296

297297
int32_t
@@ -316,7 +316,21 @@ MCScreenDC::popupanswerdialog(MCStringRef *p_buttons, uint32_t p_button_count, u
316316

317317
case 2:
318318
// Two buttons - treat it as an "OK"/"Cancel" button pair
319-
t_result = MCEmscriptenDialogShowConfirm(t_message_u16.Ptr(), t_message_u16.Size());
319+
{
320+
int32_t t_ok_button = 0, t_cancel_button = 1;
321+
// check order of ok/cancel
322+
if (MCStringIsEqualToCString(p_buttons[1], "ok", kMCStringOptionCompareCaseless) ||
323+
MCStringIsEqualToCString(p_buttons[0], "cancel", kMCStringOptionCompareCaseless))
324+
{
325+
t_ok_button = 1;
326+
t_cancel_button = 0;
327+
}
328+
329+
if (MCEmscriptenDialogShowConfirm(t_message_u16.Ptr(), t_message_u16.Size()))
330+
t_result = t_ok_button;
331+
else
332+
t_result = t_cancel_button;
333+
}
320334
break;
321335

322336
default:

engine/src/em-dialog.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ mergeInto(LibraryManager.library, {
3030
showConfirm: function(message_buffer, message_length) {
3131
var message = LiveCodeUtil.stringFromUTF16(message_buffer, message_length);
3232

33-
// Confirm returns true/false but we need the button ID
3433
var result = confirm(message);
35-
if (result) {
36-
return 0;
37-
} else {
38-
return 1;
39-
}
34+
return result;
4035
},
4136

4237
showPrompt: function(message_buffer, message_length, default_buffer, default_length, return_buffer, return_length) {

0 commit comments

Comments
 (0)