mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
LibGUI: Add Yes/No and Yes/No/Cancel MessageBoxes
This commit is contained in:
parent
48f7c28a5c
commit
4755f355c6
3 changed files with 35 additions and 21 deletions
|
@ -36,7 +36,9 @@ public:
|
||||||
enum ExecResult {
|
enum ExecResult {
|
||||||
ExecOK = 0,
|
ExecOK = 0,
|
||||||
ExecCancel = 1,
|
ExecCancel = 1,
|
||||||
ExecAborted = 2
|
ExecAborted = 2,
|
||||||
|
ExecYes = 3,
|
||||||
|
ExecNo = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Dialog() override;
|
virtual ~Dialog() override;
|
||||||
|
|
|
@ -74,7 +74,17 @@ bool MessageBox::should_include_ok_button() const
|
||||||
|
|
||||||
bool MessageBox::should_include_cancel_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()
|
void MessageBox::build()
|
||||||
|
@ -114,27 +124,25 @@ void MessageBox::build()
|
||||||
button_container->layout()->set_spacing(5);
|
button_container->layout()->set_spacing(5);
|
||||||
button_container->layout()->set_margins({ 15, 0, 15, 0 });
|
button_container->layout()->set_margins({ 15, 0, 15, 0 });
|
||||||
|
|
||||||
if (should_include_ok_button()) {
|
auto add_button = [&](String label, Dialog::ExecResult result) {
|
||||||
auto ok_button = Button::construct(button_container);
|
auto button = Button::construct(button_container);
|
||||||
ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
ok_button->set_preferred_size(0, 20);
|
button->set_preferred_size(0, 20);
|
||||||
ok_button->set_text("OK");
|
button->set_text(label);
|
||||||
ok_button->on_click = [this](auto&) {
|
button->on_click = [=](auto&) {
|
||||||
dbgprintf("GMessageBox: OK button clicked\n");
|
dbg() << "GUI::MessageBox: '" << label << "' button clicked";
|
||||||
done(Dialog::ExecOK);
|
done(result);
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
if (should_include_cancel_button()) {
|
if (should_include_ok_button())
|
||||||
auto cancel_button = Button::construct(button_container);
|
add_button("OK", Dialog::ExecOK);
|
||||||
cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
if (should_include_yes_button())
|
||||||
cancel_button->set_preferred_size(0, 20);
|
add_button("Yes", Dialog::ExecYes);
|
||||||
cancel_button->set_text("Cancel");
|
if (should_include_no_button())
|
||||||
cancel_button->on_click = [this](auto&) {
|
add_button("No", Dialog::ExecNo);
|
||||||
dbgprintf("GMessageBox: Cancel button clicked\n");
|
if (should_include_cancel_button())
|
||||||
done(Dialog::ExecCancel);
|
add_button("Cancel", Dialog::ExecCancel);
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
set_rect(x(), y(), text_width + icon_width + 80, 100);
|
set_rect(x(), y(), text_width + icon_width + 80, 100);
|
||||||
set_resizable(false);
|
set_resizable(false);
|
||||||
|
|
|
@ -43,6 +43,8 @@ public:
|
||||||
enum class InputType {
|
enum class InputType {
|
||||||
OK,
|
OK,
|
||||||
OKCancel,
|
OKCancel,
|
||||||
|
YesNo,
|
||||||
|
YesNoCancel,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~MessageBox() override;
|
virtual ~MessageBox() override;
|
||||||
|
@ -54,6 +56,8 @@ private:
|
||||||
|
|
||||||
bool should_include_ok_button() const;
|
bool should_include_ok_button() const;
|
||||||
bool should_include_cancel_button() const;
|
bool should_include_cancel_button() const;
|
||||||
|
bool should_include_yes_button() const;
|
||||||
|
bool should_include_no_button() const;
|
||||||
void build();
|
void build();
|
||||||
RefPtr<Gfx::Bitmap> icon() const;
|
RefPtr<Gfx::Bitmap> icon() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue