Skip to content

Commit 9f87680

Browse files
author
Chris K
committed
Simplified signature of ConfirmDialog.
1 parent e9af9e0 commit 9f87680

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

src/ecma-debugger/eventlisteners/evlistenertooltip.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ cls.EventListenerTooltip = function()
4949
var _reload_script_dialog = function(event, target)
5050
{
5151
new ConfirmDialog(ui_strings.D_RELOAD_SCRIPTS,
52-
function() { window.runtimes.reloadWindow(); },
53-
null,
54-
ui_strings.S_BUTTON_YES,
55-
ui_strings.S_BUTTON_NO).show();
52+
[function() { window.runtimes.reloadWindow(); }],
53+
ConfirmDialog.YES_NO).show();
5654
};
5755

5856
var _init = function(view)

src/ecma-debugger/stop_at.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ cls.EcmascriptDebugger["6.0"].StopAt = function()
101101
if (msg.key == 'reformat_javascript')
102102
{
103103
new ConfirmDialog(ui_strings.D_REFORMAT_SCRIPTS,
104-
function() { window.runtimes.reloadWindow(); },
105-
null,
106-
ui_strings.S_BUTTON_YES,
107-
ui_strings.S_BUTTON_NO).show();
104+
[function() { window.runtimes.reloadWindow(); }],
105+
ConfirmDialog.YES_NO).show();
108106
}
109107
}
110108
};

src/ui-scripts/dialog.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,39 @@ BaseDialog.prototype = new function()
101101
/**
102102
* @constructor
103103
*/
104-
function ConfirmDialog(template, ok_callback, cancel_callback, ok_label, cancel_label) {
105-
this._init(template, ok_callback, cancel_callback, ok_label, cancel_label);
104+
function ConfirmDialog(template, ok_callback_or_callback_list, cancel_callback_or_type, type) {
105+
this._init(template, ok_callback_or_callback_list, cancel_callback_or_type, type);
106106
};
107107

108108
function ConfirmDialogPrototype()
109109
{
110-
this._init = function(template, ok_callback, cancel_callback, ok_label, cancel_label)
110+
this._init = function(template, ok_callback_or_callback_list, cancel_callback_or_type, type)
111111
{
112+
var ACCEPT = 0;
113+
var REJECT = 1;
114+
var accept_cb = ok_callback_or_callback_list;
115+
var reject_cb = cancel_callback_or_type;
116+
if (Array.isArray(ok_callback_or_callback_list))
117+
{
118+
accept_cb = ok_callback_or_callback_list[0];
119+
reject_cb = ok_callback_or_callback_list[1];
120+
type = cancel_callback_or_type;
121+
}
122+
123+
if (!type)
124+
type = ConfirmDialog.OK_CANCEL;
125+
126+
if (!ConfirmDialog.labels[type])
127+
throw "Not a valid type in ConfirmDialog";
128+
112129
var buttons = [
113130
{
114-
label: ok_label || ui_strings.S_BUTTON_OK,
115-
handler: ok_callback,
131+
label: ConfirmDialog.labels[type][ACCEPT],
132+
handler: accept_cb,
116133
},
117134
{
118-
label: cancel_label || ui_strings.S_BUTTON_CANCEL,
119-
handler: cancel_callback,
135+
label: ConfirmDialog.labels[type][REJECT],
136+
handler: reject_cb,
120137
}
121138
];
122139
BaseDialog.prototype._init.call(this, template, buttons);
@@ -125,6 +142,11 @@ function ConfirmDialogPrototype()
125142

126143
ConfirmDialogPrototype.prototype = new BaseDialog();
127144
ConfirmDialog.prototype = new ConfirmDialogPrototype();
145+
ConfirmDialog.YES_NO = 1;
146+
ConfirmDialog.OK_CANCEL = 2;
147+
ConfirmDialog.labels = {};
148+
ConfirmDialog.labels[ConfirmDialog.YES_NO] = [ui_strings.S_BUTTON_YES, ui_strings.S_BUTTON_NO];
149+
ConfirmDialog.labels[ConfirmDialog.OK_CANCEL] = [ui_strings.S_BUTTON_OK, ui_strings.S_BUTTON_CANCEL];
128150

129151
/**
130152
* @constructor

0 commit comments

Comments
 (0)