Skip to content

Commit

Permalink
SystemMenu: Fix bad behavior in shutdown dialog
Browse files Browse the repository at this point in the history
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. :^)
  • Loading branch information
awesomekling committed Mar 3, 2020
1 parent 71e96ee commit b1d3524
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Applications/SystemMenu/PowerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,19 @@ PowerDialog::PowerDialog()
header->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
header->set_font(Gfx::Font::default_bold_font());

int selected = -1;
for (size_t i = 0; i < options.size(); i++) {
auto action = options[i];
auto radio = main->add<GUI::RadioButton>();
radio->set_enabled(action.enabled);
radio->set_text(action.title);

radio->on_checked = [&selected, i](auto) {
selected = i;
radio->on_checked = [this, i](auto) {
m_selected_option = i;
};

if (action.default_action) {
radio->set_checked(true);
selected = i;
m_selected_option = i;
}
}

Expand All @@ -104,8 +103,8 @@ PowerDialog::PowerDialog()
button_box->layout()->set_spacing(8);

auto ok_button = button_box->add<GUI::Button>();
ok_button->on_click = [this, &selected](auto&) {
done(selected);
ok_button->on_click = [this](auto&) {
done(m_selected_option);
};
ok_button->set_text("OK");

Expand Down
2 changes: 2 additions & 0 deletions Applications/SystemMenu/PowerDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ class PowerDialog : public GUI::Dialog {
private:
PowerDialog();
~PowerDialog();

int m_selected_option { -1 };
};

0 comments on commit b1d3524

Please sign in to comment.