Commit 7bf5ab18 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Replace AddDialogButton with Add{Ok,Cancel}Button

This is more readable to me (after using it twice) and you don't need to
remember how to spell ui::DIALOG_BUTTON_CANCEL.

It also removes Set{Accept,Cancel}Callback by making these callbacks
part of Add{Ok,Cancel}Button().

Bug: 1106422
Change-Id: I208b80c041616ac506e4b77913a7bb6150c200dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351370
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Auto-Submit: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797479}
parent 3567ff8b
...@@ -180,18 +180,15 @@ void BookmarkBubbleView::ShowBubble( ...@@ -180,18 +180,15 @@ void BookmarkBubbleView::ShowBubble(
.SetTitle(l10n_util::GetStringUTF16( .SetTitle(l10n_util::GetStringUTF16(
already_bookmarked ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK already_bookmarked ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK
: IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED)) : IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED))
.SetAcceptCallback(base::BindOnce(&BookmarkBubbleDelegate::ApplyEdits,
base::Unretained(bubble_delegate)))
.SetCancelCallback(
base::BindOnce(&BookmarkBubbleDelegate::RemoveBookmark,
base::Unretained(bubble_delegate)))
.SetWindowClosingCallback( .SetWindowClosingCallback(
base::BindOnce(&BookmarkBubbleDelegate::OnWindowClosing, base::BindOnce(&BookmarkBubbleDelegate::OnWindowClosing,
base::Unretained(bubble_delegate))) base::Unretained(bubble_delegate)))
.AddDialogButton(ui::DIALOG_BUTTON_OK, .AddOkButton(base::BindOnce(&BookmarkBubbleDelegate::ApplyEdits,
l10n_util::GetStringUTF16(IDS_DONE)) base::Unretained(bubble_delegate)),
.AddDialogButton( l10n_util::GetStringUTF16(IDS_DONE))
ui::DIALOG_BUTTON_CANCEL, .AddCancelButton(
base::BindOnce(&BookmarkBubbleDelegate::RemoveBookmark,
base::Unretained(bubble_delegate)),
l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK), l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK),
ui::DialogModelButton::Params().AddAccelerator( ui::DialogModelButton::Params().AddAccelerator(
ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN))) ui::Accelerator(ui::VKEY_R, ui::EF_ALT_DOWN)))
......
...@@ -29,18 +29,6 @@ DialogModel::Builder& DialogModel::Builder::SetTitle(base::string16 title) { ...@@ -29,18 +29,6 @@ DialogModel::Builder& DialogModel::Builder::SetTitle(base::string16 title) {
return *this; return *this;
} }
DialogModel::Builder& DialogModel::Builder::SetAcceptCallback(
base::OnceClosure callback) {
model_->accept_callback_ = std::move(callback);
return *this;
}
DialogModel::Builder& DialogModel::Builder::SetCancelCallback(
base::OnceClosure callback) {
model_->cancel_callback_ = std::move(callback);
return *this;
}
DialogModel::Builder& DialogModel::Builder::SetCloseCallback( DialogModel::Builder& DialogModel::Builder::SetCloseCallback(
base::OnceClosure callback) { base::OnceClosure callback) {
model_->close_callback_ = std::move(callback); model_->close_callback_ = std::move(callback);
...@@ -53,11 +41,25 @@ DialogModel::Builder& DialogModel::Builder::SetWindowClosingCallback( ...@@ -53,11 +41,25 @@ DialogModel::Builder& DialogModel::Builder::SetWindowClosingCallback(
return *this; return *this;
} }
DialogModel::Builder& DialogModel::Builder::AddDialogButton( DialogModel::Builder& DialogModel::Builder::AddOkButton(
DialogButton button, base::OnceClosure callback,
base::string16 label,
const DialogModelButton::Params& params) {
DCHECK(!params.has_callback()) << "Use |callback| only.";
DCHECK(!model_->accept_callback_);
model_->accept_callback_ = std::move(callback);
model_->AddDialogButton(ui::DIALOG_BUTTON_OK, std::move(label), params);
return *this;
}
DialogModel::Builder& DialogModel::Builder::AddCancelButton(
base::OnceClosure callback,
base::string16 label, base::string16 label,
const DialogModelButton::Params& params) { const DialogModelButton::Params& params) {
model_->AddDialogButton(button, std::move(label), params); DCHECK(!params.has_callback()) << "Use |callback| only.";
DCHECK(!model_->cancel_callback_);
model_->cancel_callback_ = std::move(callback);
model_->AddDialogButton(ui::DIALOG_BUTTON_CANCEL, std::move(label), params);
return *this; return *this;
} }
......
...@@ -64,14 +64,11 @@ class COMPONENT_EXPORT(UI_BASE) DialogModelDelegate { ...@@ -64,14 +64,11 @@ class COMPONENT_EXPORT(UI_BASE) DialogModelDelegate {
// auto dialog_model = // auto dialog_model =
// ui::DialogModel::Builder(std::move(model_delegate)) // ui::DialogModel::Builder(std::move(model_delegate))
// .SetTitle(base::ASCIIToUTF16("Hello, world!")) // .SetTitle(base::ASCIIToUTF16("Hello, world!"))
// .AddDialogButton(ui::DIALOG_BUTTON_OK, // .AddOkButton(base::BindOnce(&Delegate::OnDialogAccepted,
// l10n_util::GetStringUTF16(IDS_OK)) // base::Unretained(model_delegate_ptr)))
// .AddTextfield( // .AddTextfield(
// base::ASCIIToUTF16("Name"), base::string16(), // base::ASCIIToUTF16("Name"), base::string16(),
// ui::DialogModelTextfield::Params().SetUniqueId(kNameTextfield)) // ui::DialogModelTextfield::Params().SetUniqueId(kNameTextfield))
// .SetAcceptCallback(
// base::BindOnce(&Delegate::OnDialogAccepted,
// base::Unretained(model_delegate_ptr)))
// .Build(); // .Build();
// //
// // DialogModelBase::Host specific. In this example, uses views-specific // // DialogModelBase::Host specific. In this example, uses views-specific
...@@ -96,12 +93,8 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final { ...@@ -96,12 +93,8 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final {
Builder& SetShowCloseButton(bool show_close_button); Builder& SetShowCloseButton(bool show_close_button);
Builder& SetTitle(base::string16 title); Builder& SetTitle(base::string16 title);
// Called when the dialog is accepted, before it closes. // Called when the dialog is explicitly closed (Esc, close-x). Not called
Builder& SetAcceptCallback(base::OnceClosure callback); // during accept/cancel.
// Called when the dialog is cancelled.
Builder& SetCancelCallback(base::OnceClosure callback);
// Called when the dialog is explicitly closed (for instance, close-x). Not
// called during accept/cancel.
Builder& SetCloseCallback(base::OnceClosure callback); Builder& SetCloseCallback(base::OnceClosure callback);
// TODO(pbos): Clarify and enforce (through tests) that this is called after // TODO(pbos): Clarify and enforce (through tests) that this is called after
...@@ -110,12 +103,19 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final { ...@@ -110,12 +103,19 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final {
// {accept,cancel,close} callbacks. // {accept,cancel,close} callbacks.
Builder& SetWindowClosingCallback(base::OnceClosure callback); Builder& SetWindowClosingCallback(base::OnceClosure callback);
// Adds a dialog button (ok, cancel) to the dialog. Note that the callbacks // Adds a dialog button (ok, cancel) to the dialog. The |callback| is called
// for these button actions should be set using SetAcceptCallback() and // when the dialog is accepted or cancelled, before it closes. Use
// SetCancelCallback(). // base::DoNothing() as callback if you want nothing extra to happen as a
Builder& AddDialogButton( // result, besides the dialog closing.
DialogButton button, // If no |label| is provided, default strings are chosen by the
base::string16 label, // DialogModelHost implementation.
Builder& AddOkButton(
base::OnceClosure callback,
base::string16 label = base::string16(),
const DialogModelButton::Params& params = DialogModelButton::Params());
Builder& AddCancelButton(
base::OnceClosure callback,
base::string16 label = base::string16(),
const DialogModelButton::Params& params = DialogModelButton::Params()); const DialogModelButton::Params& params = DialogModelButton::Params());
// Use of the extra button in new dialogs are discouraged. If this is deemed // Use of the extra button in new dialogs are discouraged. If this is deemed
......
...@@ -75,9 +75,11 @@ BubbleDialogModelHost::BubbleDialogModelHost( ...@@ -75,9 +75,11 @@ BubbleDialogModelHost::BubbleDialogModelHost(
button_mask |= field->model_field_id(GetPassKey()); button_mask |= field->model_field_id(GetPassKey());
SetButtons(button_mask); SetButtons(button_mask);
SetButtonLabel( if (!button->label().empty()) {
static_cast<ui::DialogButton>(field->model_field_id(GetPassKey())), SetButtonLabel(
button->label()); static_cast<ui::DialogButton>(field->model_field_id(GetPassKey())),
button->label());
}
} }
// Populate dialog using the observer functions to make sure they use the same // Populate dialog using the observer functions to make sure they use the same
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment