🐧 add default button index for linux/gtk
This commit is contained in:
parent
f1edd5f26f
commit
22c455175a
1 changed files with 14 additions and 4 deletions
|
@ -29,6 +29,7 @@ class GtkMessageBox {
|
||||||
GtkMessageBox(NativeWindow* parent_window,
|
GtkMessageBox(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int default_button_index,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
|
@ -60,9 +61,16 @@ class GtkMessageBox {
|
||||||
|
|
||||||
// Add buttons.
|
// Add buttons.
|
||||||
for (size_t i = 0; i < buttons.size(); ++i) {
|
for (size_t i = 0; i < buttons.size(); ++i) {
|
||||||
gtk_dialog_add_button(GTK_DIALOG(dialog_),
|
if (i == (size_t)default_button_index) {
|
||||||
|
GtkWidget* button = gtk_dialog_add_button(GTK_DIALOG(dialog_),
|
||||||
|
TranslateToStock(i, buttons[i]),
|
||||||
|
i);
|
||||||
|
gtk_widget_grab_focus(button);
|
||||||
|
} else {
|
||||||
|
gtk_dialog_add_button(GTK_DIALOG(dialog_),
|
||||||
TranslateToStock(i, buttons[i]),
|
TranslateToStock(i, buttons[i]),
|
||||||
i);
|
i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent window.
|
// Parent window.
|
||||||
|
@ -161,19 +169,21 @@ void GtkMessageBox::OnResponseDialog(GtkWidget* widget, int response) {
|
||||||
int ShowMessageBox(NativeWindow* parent,
|
int ShowMessageBox(NativeWindow* parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int default_button_index,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
int options,
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
const gfx::ImageSkia& icon) {
|
const gfx::ImageSkia& icon) {
|
||||||
return GtkMessageBox(parent, type, buttons, cancel_id, title, message, detail,
|
return GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, title, message, detail,
|
||||||
icon).RunSynchronous();
|
icon).RunSynchronous();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowMessageBox(NativeWindow* parent,
|
void ShowMessageBox(NativeWindow* parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int default_button_index,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
int options,
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
@ -181,13 +191,13 @@ void ShowMessageBox(NativeWindow* parent,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
const gfx::ImageSkia& icon,
|
const gfx::ImageSkia& icon,
|
||||||
const MessageBoxCallback& callback) {
|
const MessageBoxCallback& callback) {
|
||||||
(new GtkMessageBox(parent, type, buttons, cancel_id, title, message, detail,
|
(new GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, title, message, detail,
|
||||||
icon))->RunAsynchronous(callback);
|
icon))->RunAsynchronous(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
||||||
if (Browser::Get()->is_ready()) {
|
if (Browser::Get()->is_ready()) {
|
||||||
GtkMessageBox(nullptr, MESSAGE_BOX_TYPE_ERROR, { "OK" }, 0, "Error",
|
GtkMessageBox(nullptr, MESSAGE_BOX_TYPE_ERROR, { "OK" }, -1, 0, "Error",
|
||||||
base::UTF16ToUTF8(title).c_str(),
|
base::UTF16ToUTF8(title).c_str(),
|
||||||
base::UTF16ToUTF8(content).c_str(),
|
base::UTF16ToUTF8(content).c_str(),
|
||||||
gfx::ImageSkia()).RunSynchronous();
|
gfx::ImageSkia()).RunSynchronous();
|
||||||
|
|
Loading…
Reference in a new issue