|
@@ -74,7 +74,17 @@ bool MessageBox::should_include_ok_button() const
|
|
|
|
|
|
bool MessageBox::should_include_cancel_button() const
|
|
|
{
|
|
|
- return m_input_type == InputType::OKCancel;
|
|
|
+ return m_input_type == InputType::OKCancel || m_input_type == InputType::YesNoCancel;
|
|
|
+}
|
|
|
+
|
|
|
+bool MessageBox::should_include_yes_button() const
|
|
|
+{
|
|
|
+ return m_input_type == InputType::YesNo || m_input_type == InputType::YesNoCancel;
|
|
|
+}
|
|
|
+
|
|
|
+bool MessageBox::should_include_no_button() const
|
|
|
+{
|
|
|
+ return should_include_yes_button();
|
|
|
}
|
|
|
|
|
|
void MessageBox::build()
|
|
@@ -114,27 +124,25 @@ void MessageBox::build()
|
|
|
button_container->layout()->set_spacing(5);
|
|
|
button_container->layout()->set_margins({ 15, 0, 15, 0 });
|
|
|
|
|
|
- if (should_include_ok_button()) {
|
|
|
- auto ok_button = Button::construct(button_container);
|
|
|
- ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
|
|
- ok_button->set_preferred_size(0, 20);
|
|
|
- ok_button->set_text("OK");
|
|
|
- ok_button->on_click = [this](auto&) {
|
|
|
- dbgprintf("GMessageBox: OK button clicked\n");
|
|
|
- done(Dialog::ExecOK);
|
|
|
+ auto add_button = [&](String label, Dialog::ExecResult result) {
|
|
|
+ auto button = Button::construct(button_container);
|
|
|
+ button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
|
|
+ button->set_preferred_size(0, 20);
|
|
|
+ button->set_text(label);
|
|
|
+ button->on_click = [=](auto&) {
|
|
|
+ dbg() << "GUI::MessageBox: '" << label << "' button clicked";
|
|
|
+ done(result);
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- if (should_include_cancel_button()) {
|
|
|
- auto cancel_button = Button::construct(button_container);
|
|
|
- cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
|
|
- cancel_button->set_preferred_size(0, 20);
|
|
|
- cancel_button->set_text("Cancel");
|
|
|
- cancel_button->on_click = [this](auto&) {
|
|
|
- dbgprintf("GMessageBox: Cancel button clicked\n");
|
|
|
- done(Dialog::ExecCancel);
|
|
|
- };
|
|
|
- }
|
|
|
+ };
|
|
|
+
|
|
|
+ if (should_include_ok_button())
|
|
|
+ add_button("OK", Dialog::ExecOK);
|
|
|
+ if (should_include_yes_button())
|
|
|
+ add_button("Yes", Dialog::ExecYes);
|
|
|
+ if (should_include_no_button())
|
|
|
+ add_button("No", Dialog::ExecNo);
|
|
|
+ if (should_include_cancel_button())
|
|
|
+ add_button("Cancel", Dialog::ExecCancel);
|
|
|
|
|
|
set_rect(x(), y(), text_width + icon_width + 80, 100);
|
|
|
set_resizable(false);
|