mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:27:44 +00:00
SystemMenu: Fix bad behavior in shutdown dialog
The selected option was stored in a captured stack variable which was long gone by the time we looked at it, so this dialog didn't really behave the way you'd expect. Put it in a member instead. :^)
This commit is contained in:
parent
71e96ee728
commit
b1d35248e4
2 changed files with 7 additions and 6 deletions
|
@ -82,20 +82,19 @@ PowerDialog::PowerDialog()
|
||||||
header->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
header->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||||
header->set_font(Gfx::Font::default_bold_font());
|
header->set_font(Gfx::Font::default_bold_font());
|
||||||
|
|
||||||
int selected = -1;
|
|
||||||
for (size_t i = 0; i < options.size(); i++) {
|
for (size_t i = 0; i < options.size(); i++) {
|
||||||
auto action = options[i];
|
auto action = options[i];
|
||||||
auto radio = main->add<GUI::RadioButton>();
|
auto radio = main->add<GUI::RadioButton>();
|
||||||
radio->set_enabled(action.enabled);
|
radio->set_enabled(action.enabled);
|
||||||
radio->set_text(action.title);
|
radio->set_text(action.title);
|
||||||
|
|
||||||
radio->on_checked = [&selected, i](auto) {
|
radio->on_checked = [this, i](auto) {
|
||||||
selected = i;
|
m_selected_option = i;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (action.default_action) {
|
if (action.default_action) {
|
||||||
radio->set_checked(true);
|
radio->set_checked(true);
|
||||||
selected = i;
|
m_selected_option = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +103,8 @@ PowerDialog::PowerDialog()
|
||||||
button_box->layout()->set_spacing(8);
|
button_box->layout()->set_spacing(8);
|
||||||
|
|
||||||
auto ok_button = button_box->add<GUI::Button>();
|
auto ok_button = button_box->add<GUI::Button>();
|
||||||
ok_button->on_click = [this, &selected](auto&) {
|
ok_button->on_click = [this](auto&) {
|
||||||
done(selected);
|
done(m_selected_option);
|
||||||
};
|
};
|
||||||
ok_button->set_text("OK");
|
ok_button->set_text("OK");
|
||||||
|
|
||||||
|
|
|
@ -36,4 +36,6 @@ public:
|
||||||
private:
|
private:
|
||||||
PowerDialog();
|
PowerDialog();
|
||||||
~PowerDialog();
|
~PowerDialog();
|
||||||
|
|
||||||
|
int m_selected_option { -1 };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue