Set default cancelId in JavaScript

This commit is contained in:
Cheng Zhao 2015-07-07 18:33:11 +08:00
parent b158427271
commit fb537d91fc
3 changed files with 14 additions and 19 deletions

View file

@ -92,7 +92,13 @@ module.exports =
options.message ?= '' options.message ?= ''
options.detail ?= '' options.detail ?= ''
options.icon ?= null options.icon ?= null
options.cancelId ?= 0
unless options.cancelId?
options.cancelId = 0
for text, i in options.buttons
if text.toLowerCase() in ['cancel', 'no']
options.cancelId = i
break
binding.showMessageBox messageBoxType, binding.showMessageBox messageBoxType,
options.buttons, options.buttons,

View file

@ -93,20 +93,17 @@ class GtkMessageBox {
const char* TranslateToStock(int id, const std::string& text) { const char* TranslateToStock(int id, const std::string& text) {
std::string lower = base::StringToLowerASCII(text); std::string lower = base::StringToLowerASCII(text);
if (lower == "cancel") { if (lower == "cancel")
cancel_id_ = id;
return GTK_STOCK_CANCEL; return GTK_STOCK_CANCEL;
} else if (lower == "no") { else if (lower == "no")
cancel_id_ = id;
return GTK_STOCK_NO; return GTK_STOCK_NO;
} else if (lower == "ok") { else if (lower == "ok")
return GTK_STOCK_OK; return GTK_STOCK_OK;
} else if (lower == "yes") { else if (lower == "yes")
return GTK_STOCK_YES; return GTK_STOCK_YES;
} else { else
return text.c_str(); return text.c_str();
} }
}
void Show() { void Show() {
gtk_widget_show_all(dialog_); gtk_widget_show_all(dialog_);

View file

@ -207,19 +207,11 @@ void MessageDialog::Close() {
} }
int MessageDialog::GetResult() const { int MessageDialog::GetResult() const {
// When the dialog is closed without choosing anything, we think the user if (result_ == -1)
// chose 'Cancel', otherwise we think the default behavior is chosen.
if (result_ == -1) {
for (size_t i = 0; i < buttons_.size(); ++i)
if (LowerCaseEqualsASCII(buttons_[i]->GetText(), "cancel")) {
return i;
}
return cancel_id_; return cancel_id_;
} else { else
return result_; return result_;
} }
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// MessageDialog, private: // MessageDialog, private: