summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-03 16:46:39 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-03 16:46:39 +0100
commitb1d35248e45a6c4e4e9b9a55aa5d8fa60e60c276 (patch)
tree6b632bd6c96f98bca11d0848759e8d158f4603ee
parent71e96ee728dd8c9aed2ff769eaa38652e7e881a4 (diff)
downloadserenity-b1d35248e45a6c4e4e9b9a55aa5d8fa60e60c276.zip
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. :^)
-rw-r--r--Applications/SystemMenu/PowerDialog.cpp11
-rw-r--r--Applications/SystemMenu/PowerDialog.h2
2 files changed, 7 insertions, 6 deletions
diff --git a/Applications/SystemMenu/PowerDialog.cpp b/Applications/SystemMenu/PowerDialog.cpp
index 650ee23e89..b81f911353 100644
--- a/Applications/SystemMenu/PowerDialog.cpp
+++ b/Applications/SystemMenu/PowerDialog.cpp
@@ -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;
}
}
@@ -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");
diff --git a/Applications/SystemMenu/PowerDialog.h b/Applications/SystemMenu/PowerDialog.h
index a001c7f42f..1a1c18a8d3 100644
--- a/Applications/SystemMenu/PowerDialog.h
+++ b/Applications/SystemMenu/PowerDialog.h
@@ -36,4 +36,6 @@ public:
private:
PowerDialog();
~PowerDialog();
+
+ int m_selected_option { -1 };
};