mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
Userland: Dynamically update the MonitorSettingsWidget countdown timer
This causes the number of seconds in "Do you want to keep the new settings? They will be reverted after 10 seconds." to be dynamically updated.
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 01:43:16 +09:00
Author: https://github.com/S-D-R Commit: https://github.com/SerenityOS/serenity/commit/d01ca4e3e2 Pull-request: https://github.com/SerenityOS/serenity/pull/12610
@@ -220,14 +220,26 @@ void MonitorSettingsWidget::apply_settings()
|
||||
if (result.success()) {
|
||||
load_current_settings(); // Refresh
|
||||
|
||||
auto box = GUI::MessageBox::construct(window(), String::formatted("Do you want to keep the new settings? They will be reverted after 10 seconds."),
|
||||
"Apply new screen layout", GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo);
|
||||
auto seconds_until_revert = 10;
|
||||
|
||||
auto box_text = [&seconds_until_revert] {
|
||||
return String::formatted("Do you want to keep the new settings? They will be reverted after {} {}.",
|
||||
seconds_until_revert, seconds_until_revert == 1 ? "second" : "seconds");
|
||||
};
|
||||
|
||||
auto box = GUI::MessageBox::construct(window(), box_text(), "Apply new screen layout",
|
||||
GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo);
|
||||
box->set_icon(window()->icon());
|
||||
|
||||
// If after 10 seconds the user doesn't close the message box, just close it.
|
||||
auto timer = Core::Timer::construct(10000, [&] {
|
||||
box->close();
|
||||
auto revert_timer = Core::Timer::create_repeating(1000, [&] {
|
||||
seconds_until_revert -= 1;
|
||||
box->set_text(box_text());
|
||||
if (seconds_until_revert <= 0) {
|
||||
box->close();
|
||||
}
|
||||
});
|
||||
revert_timer->start();
|
||||
|
||||
// If the user selects "No", closes the window or the window gets closed by the 10 seconds timer, revert the changes.
|
||||
if (box->exec() == GUI::MessageBox::ExecYes) {
|
||||
|
||||
Reference in New Issue
Block a user