From a26b63a9585631d39c97db5b5808aca351894da8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 3 Mar 2020 17:02:38 +0100 Subject: LibGUI: Remove Button& parameter from Button::on_click hook There was but a single user of this parameter and it's a bit tedious to write it out every time, so let's get rid of it. --- Applications/About/main.cpp | 2 +- Applications/Calculator/CalculatorWidget.cpp | 14 +++++++------- Applications/DisplayProperties/DisplayProperties.cpp | 6 +++--- Applications/FileManager/PropertiesDialog.cpp | 11 ++++++++--- Applications/FontEditor/FontEditor.cpp | 4 ++-- Applications/Piano/SamplerWidget.cpp | 2 +- Applications/SoundPlayer/SoundPlayerWidget.cpp | 6 +++--- Applications/SystemMenu/PowerDialog.cpp | 4 ++-- Applications/Taskbar/TaskbarWindow.cpp | 2 +- Applications/Taskbar/WindowList.cpp | 2 +- Applications/Welcome/main.cpp | 4 ++-- Demos/HelloWorld/main.cpp | 2 +- DevTools/HackStudio/FindInFilesWidget.cpp | 2 +- DevTools/VisualBuilder/main.cpp | 20 ++++++++++---------- Games/Minesweeper/Field.cpp | 4 ++-- Libraries/LibGUI/AboutDialog.cpp | 2 +- Libraries/LibGUI/Button.cpp | 2 +- Libraries/LibGUI/Button.h | 2 +- Libraries/LibGUI/ColorPicker.cpp | 4 ++-- Libraries/LibGUI/ComboBox.cpp | 2 +- Libraries/LibGUI/FilePicker.cpp | 4 ++-- Libraries/LibGUI/InputBox.cpp | 4 ++-- Libraries/LibGUI/MessageBox.cpp | 2 +- Libraries/LibGUI/SpinBox.cpp | 4 ++-- Libraries/LibHTML/DOM/HTMLInputElement.cpp | 2 +- Servers/NotificationServer/NotificationWindow.cpp | 2 +- 26 files changed, 60 insertions(+), 55 deletions(-) diff --git a/Applications/About/main.cpp b/Applications/About/main.cpp index f0ff7afea4..c1467cf39b 100644 --- a/Applications/About/main.cpp +++ b/Applications/About/main.cpp @@ -118,7 +118,7 @@ int main(int argc, char** argv) quit_button->set_text("Okay"); quit_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); quit_button->set_preferred_size(100, 20); - quit_button->on_click = [](GUI::Button&) { + quit_button->on_click = [] { GUI::Application::the().quit(0); }; diff --git a/Applications/Calculator/CalculatorWidget.cpp b/Applications/Calculator/CalculatorWidget.cpp index 1adf7b9518..ebed7602a9 100644 --- a/Applications/Calculator/CalculatorWidget.cpp +++ b/Applications/Calculator/CalculatorWidget.cpp @@ -85,7 +85,7 @@ CalculatorWidget::CalculatorWidget() m_clear_button = add(); m_clear_button->set_foreground_color(Color::NamedColor::Red); m_clear_button->set_text("C"); - m_clear_button->on_click = [this](GUI::Button&) { + m_clear_button->on_click = [this] { m_keypad.set_value(0.0); m_calculator.clear_operation(); update_display(); @@ -96,7 +96,7 @@ CalculatorWidget::CalculatorWidget() m_clear_error_button = add(); m_clear_error_button->set_foreground_color(Color::NamedColor::Red); m_clear_error_button->set_text("CE"); - m_clear_error_button->on_click = [this](GUI::Button&) { + m_clear_error_button->on_click = [this] { m_calculator.clear_error(); update_display(); }; @@ -106,7 +106,7 @@ CalculatorWidget::CalculatorWidget() m_backspace_button = add(); m_backspace_button->set_foreground_color(Color::NamedColor::Red); m_backspace_button->set_text("Backspace"); - m_backspace_button->on_click = [this](GUI::Button&) { + m_backspace_button->on_click = [this] { m_keypad.type_backspace(); update_display(); }; @@ -117,7 +117,7 @@ CalculatorWidget::CalculatorWidget() m_decimal_point_button->move_to(133, 177); m_decimal_point_button->set_foreground_color(Color::NamedColor::Blue); m_decimal_point_button->set_text("."); - m_decimal_point_button->on_click = [this](GUI::Button&) { + m_decimal_point_button->on_click = [this] { m_keypad.type_decimal_point(); update_display(); }; @@ -175,7 +175,7 @@ CalculatorWidget::CalculatorWidget() m_equals_button->move_to(211, 177); m_equals_button->set_foreground_color(Color::NamedColor::Red); m_equals_button->set_text("="); - m_equals_button->on_click = [this](GUI::Button&) { + m_equals_button->on_click = [this] { double argument = m_keypad.value(); double res = m_calculator.finish_operation(argument); m_keypad.set_value(res); @@ -191,7 +191,7 @@ CalculatorWidget::~CalculatorWidget() void CalculatorWidget::add_button(GUI::Button& button, Calculator::Operation operation) { add_button(button); - button.on_click = [this, operation](GUI::Button&) { + button.on_click = [this, operation] { double argument = m_keypad.value(); double res = m_calculator.begin_operation(operation, argument); m_keypad.set_value(res); @@ -203,7 +203,7 @@ void CalculatorWidget::add_button(GUI::Button& button, int digit) { add_button(button); button.set_text(String::number(digit)); - button.on_click = [this, digit](GUI::Button&) { + button.on_click = [this, digit] { m_keypad.type_digit(digit); update_display(); }; diff --git a/Applications/DisplayProperties/DisplayProperties.cpp b/Applications/DisplayProperties/DisplayProperties.cpp index 225457c83a..e84e18135a 100644 --- a/Applications/DisplayProperties/DisplayProperties.cpp +++ b/Applications/DisplayProperties/DisplayProperties.cpp @@ -193,7 +193,7 @@ void DisplayPropertiesWidget::create_frame() apply_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed); apply_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed); apply_button->set_preferred_size(60, 22); - apply_button->on_click = [this, tab_widget](GUI::Button&) { + apply_button->on_click = [this, tab_widget] { send_settings_to_window_server(tab_widget->active_tab_index()); }; @@ -202,7 +202,7 @@ void DisplayPropertiesWidget::create_frame() ok_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed); ok_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed); ok_button->set_preferred_size(60, 22); - ok_button->on_click = [this, tab_widget](GUI::Button&) { + ok_button->on_click = [this, tab_widget] { send_settings_to_window_server(tab_widget->active_tab_index()); GUI::Application::the().quit(); }; @@ -212,7 +212,7 @@ void DisplayPropertiesWidget::create_frame() cancel_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed); cancel_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed); cancel_button->set_preferred_size(60, 22); - cancel_button->on_click = [](auto&) { + cancel_button->on_click = [] { GUI::Application::the().quit(); }; } diff --git a/Applications/FileManager/PropertiesDialog.cpp b/Applications/FileManager/PropertiesDialog.cpp index c8fb51aca9..4c43f069ca 100644 --- a/Applications/FileManager/PropertiesDialog.cpp +++ b/Applications/FileManager/PropertiesDialog.cpp @@ -139,11 +139,16 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo button_widget->layout()->add_spacer(); - make_button("OK", button_widget)->on_click = [&](auto&) {if(apply_changes()) close(); }; - make_button("Cancel", button_widget)->on_click = [&](auto&) { close(); }; + make_button("OK", button_widget)->on_click = [this] { + if (apply_changes()) + close(); + }; + make_button("Cancel", button_widget)->on_click = [this] { + close(); + }; m_apply_button = make_button("Apply", button_widget); - m_apply_button->on_click = [&](auto&) { apply_changes(); }; + m_apply_button->on_click = [this] { apply_changes(); }; m_apply_button->set_enabled(false); update(); diff --git a/Applications/FontEditor/FontEditor.cpp b/Applications/FontEditor/FontEditor.cpp index 06775daabe..4540151deb 100644 --- a/Applications/FontEditor/FontEditor.cpp +++ b/Applications/FontEditor/FontEditor.cpp @@ -75,13 +75,13 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& edite }; m_ui->save_button->set_text("Save"); - m_ui->save_button->on_click = [this](GUI::Button&) { + m_ui->save_button->on_click = [this] { dbgprintf("write to file: '%s'\n", m_path.characters()); m_edited_font->write_to_file(m_path); }; m_ui->quit_button->set_text("Quit"); - m_ui->quit_button->on_click = [](auto&) { + m_ui->quit_button->on_click = [] { exit(0); }; diff --git a/Applications/Piano/SamplerWidget.cpp b/Applications/Piano/SamplerWidget.cpp index 543cee8ebb..d4903878ca 100644 --- a/Applications/Piano/SamplerWidget.cpp +++ b/Applications/Piano/SamplerWidget.cpp @@ -107,7 +107,7 @@ SamplerWidget::SamplerWidget(AudioEngine& audio_engine) m_open_button->set_preferred_size(24, 24); m_open_button->set_focusable(false); m_open_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png")); - m_open_button->on_click = [this](const auto&) { + m_open_button->on_click = [this] { Optional open_path = GUI::FilePicker::get_open_filepath(); if (!open_path.has_value()) return; diff --git a/Applications/SoundPlayer/SoundPlayerWidget.cpp b/Applications/SoundPlayer/SoundPlayerWidget.cpp index b3625e2e23..296c641b77 100644 --- a/Applications/SoundPlayer/SoundPlayerWidget.cpp +++ b/Applications/SoundPlayer/SoundPlayerWidget.cpp @@ -81,14 +81,14 @@ SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtradd(); m_play->set_icon(*m_pause_icon); m_play->set_enabled(false); - m_play->on_click = [this](GUI::Button& button) { - button.set_icon(m_manager.toggle_pause() ? *m_play_icon : *m_pause_icon); + m_play->on_click = [this] { + m_play->set_icon(m_manager.toggle_pause() ? *m_play_icon : *m_pause_icon); }; m_stop = control_widget->add(); m_stop->set_enabled(false); m_stop->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/stop.png")); - m_stop->on_click = [&](GUI::Button&) { m_manager.stop(); }; + m_stop->on_click = [this] { m_manager.stop(); }; m_status = add(); m_status->set_frame_shape(Gfx::FrameShape::Box); diff --git a/Applications/SystemMenu/PowerDialog.cpp b/Applications/SystemMenu/PowerDialog.cpp index b81f911353..0ce7fa87f8 100644 --- a/Applications/SystemMenu/PowerDialog.cpp +++ b/Applications/SystemMenu/PowerDialog.cpp @@ -103,13 +103,13 @@ PowerDialog::PowerDialog() button_box->layout()->set_spacing(8); auto ok_button = button_box->add(); - ok_button->on_click = [this](auto&) { + ok_button->on_click = [this] { done(m_selected_option); }; ok_button->set_text("OK"); auto cancel_button = button_box->add(); - cancel_button->on_click = [this](auto&) { + cancel_button->on_click = [this] { done(-1); }; cancel_button->set_text("Cancel"); diff --git a/Applications/Taskbar/TaskbarWindow.cpp b/Applications/Taskbar/TaskbarWindow.cpp index 0e06c8e0c8..2a20d4148f 100644 --- a/Applications/Taskbar/TaskbarWindow.cpp +++ b/Applications/Taskbar/TaskbarWindow.cpp @@ -101,7 +101,7 @@ void TaskbarWindow::create_quick_launch_bar() button->set_icon(Gfx::Bitmap::load_from_file(app_icon_path)); // FIXME: the tooltip ends up outside the screen rect. button->set_tooltip(name); - button->on_click = [app_executable](auto&) { + button->on_click = [app_executable] { pid_t pid = fork(); if (pid < 0) { perror("fork"); diff --git a/Applications/Taskbar/WindowList.cpp b/Applications/Taskbar/WindowList.cpp index e1547a3dd8..948dcb0452 100644 --- a/Applications/Taskbar/WindowList.cpp +++ b/Applications/Taskbar/WindowList.cpp @@ -50,7 +50,7 @@ Window& WindowList::ensure_window(const WindowIdentifier& identifier) return *it->value; auto window = make(identifier); window->set_button(aid_create_button(identifier)); - window->button()->on_click = [window = window.ptr(), identifier](auto&) { + window->button()->on_click = [window = window.ptr(), identifier] { if (window->is_minimized() || !window->is_active()) { GUI::WindowServerConnection::the().post_message(Messages::WindowServer::WM_SetActiveWindow(identifier.client_id(), identifier.window_id())); } else { diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp index ea25ab057d..17d6369273 100644 --- a/Applications/Welcome/main.cpp +++ b/Applications/Welcome/main.cpp @@ -37,8 +37,8 @@ #include #include #include -#include #include +#include #include #include @@ -249,7 +249,7 @@ int main(int argc, char** argv) if (first) menu_option->set_checked(true); - menu_option->on_click = [content = content.ptr(), &stack](auto&) { + menu_option->on_click = [content = content.ptr(), &stack] { stack->set_active_widget(content); content->invalidate_layout(); }; diff --git a/Demos/HelloWorld/main.cpp b/Demos/HelloWorld/main.cpp index 1abcd55738..73ce17a3a0 100644 --- a/Demos/HelloWorld/main.cpp +++ b/Demos/HelloWorld/main.cpp @@ -53,7 +53,7 @@ int main(int argc, char** argv) button->set_text("Good-bye"); button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); button->set_preferred_size(0, 20); - button->on_click = [&](GUI::Button&) { + button->on_click = [&] { app.quit(); }; diff --git a/DevTools/HackStudio/FindInFilesWidget.cpp b/DevTools/HackStudio/FindInFilesWidget.cpp index ad6a0209dc..80711db3b2 100644 --- a/DevTools/HackStudio/FindInFilesWidget.cpp +++ b/DevTools/HackStudio/FindInFilesWidget.cpp @@ -147,7 +147,7 @@ FindInFilesWidget::FindInFilesWidget() current_editor().set_focus(true); }; - m_button->on_click = [this](auto&) { + m_button->on_click = [this] { auto results_model = find_in_files(m_textbox->text()); m_result_view->set_model(results_model); }; diff --git a/DevTools/VisualBuilder/main.cpp b/DevTools/VisualBuilder/main.cpp index b06ca890ad..6b38a5fa46 100644 --- a/DevTools/VisualBuilder/main.cpp +++ b/DevTools/VisualBuilder/main.cpp @@ -116,7 +116,7 @@ RefPtr make_toolbox_window() label_button->set_button_style(Gfx::ButtonStyle::CoolBar); label_button->set_tooltip("GLabel"); label_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/label.png")); - label_button->on_click = [](GUI::Button&) { + label_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GLabel); }; @@ -125,7 +125,7 @@ RefPtr make_toolbox_window() button_button->set_button_style(Gfx::ButtonStyle::CoolBar); button_button->set_tooltip("GButton"); button_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/button.png")); - button_button->on_click = [](GUI::Button&) { + button_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GButton); }; @@ -133,7 +133,7 @@ RefPtr make_toolbox_window() spinbox_button->set_button_style(Gfx::ButtonStyle::CoolBar); spinbox_button->set_tooltip("GSpinBox"); spinbox_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/spinbox.png")); - spinbox_button->on_click = [](GUI::Button&) { + spinbox_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GSpinBox); }; @@ -141,7 +141,7 @@ RefPtr make_toolbox_window() editor_button->set_button_style(Gfx::ButtonStyle::CoolBar); editor_button->set_tooltip("GTextEditor"); editor_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/textbox.png")); - editor_button->on_click = [](GUI::Button&) { + editor_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GTextEditor); }; @@ -149,7 +149,7 @@ RefPtr make_toolbox_window() progress_bar_button->set_button_style(Gfx::ButtonStyle::CoolBar); progress_bar_button->set_tooltip("GProgressBar"); progress_bar_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/progressbar.png")); - progress_bar_button->on_click = [](GUI::Button&) { + progress_bar_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GProgressBar); }; @@ -157,7 +157,7 @@ RefPtr make_toolbox_window() slider_button->set_button_style(Gfx::ButtonStyle::CoolBar); slider_button->set_tooltip("GSlider"); slider_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/slider.png")); - slider_button->on_click = [](GUI::Button&) { + slider_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GSlider); }; @@ -165,7 +165,7 @@ RefPtr make_toolbox_window() checkbox_button->set_button_style(Gfx::ButtonStyle::CoolBar); checkbox_button->set_tooltip("GCheckBox"); checkbox_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/checkbox.png")); - checkbox_button->on_click = [](GUI::Button&) { + checkbox_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GCheckBox); }; @@ -173,7 +173,7 @@ RefPtr make_toolbox_window() radiobutton_button->set_button_style(Gfx::ButtonStyle::CoolBar); radiobutton_button->set_tooltip("GRadioButton"); radiobutton_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/filled-radio-circle.png")); - radiobutton_button->on_click = [](GUI::Button&) { + radiobutton_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GRadioButton); }; @@ -181,7 +181,7 @@ RefPtr make_toolbox_window() scrollbar_button->set_button_style(Gfx::ButtonStyle::CoolBar); scrollbar_button->set_tooltip("GScrollBar"); scrollbar_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/scrollbar.png")); - scrollbar_button->on_click = [](GUI::Button&) { + scrollbar_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GScrollBar); }; @@ -189,7 +189,7 @@ RefPtr make_toolbox_window() groupbox_button->set_button_style(Gfx::ButtonStyle::CoolBar); groupbox_button->set_tooltip("GGroupBox"); groupbox_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/groupbox.png")); - groupbox_button->on_click = [](GUI::Button&) { + groupbox_button->on_click = [] { if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GGroupBox); }; diff --git a/Games/Minesweeper/Field.cpp b/Games/Minesweeper/Field.cpp index 13b86757c0..fde8517cbf 100644 --- a/Games/Minesweeper/Field.cpp +++ b/Games/Minesweeper/Field.cpp @@ -147,7 +147,7 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b set_fill_with_background_color(true); reset(); - m_face_button.on_click = [this](auto&) { reset(); }; + m_face_button.on_click = [this] { reset(); }; set_face(Face::Default); { @@ -260,7 +260,7 @@ void Field::reset() square.label->set_icon(square.has_mine ? m_mine_bitmap : nullptr); if (!square.button) { square.button = add(); - square.button->on_click = [this, &square](GUI::Button&) { + square.button->on_click = [this, &square] { on_square_clicked(square); }; square.button->on_right_click = [this, &square] { diff --git a/Libraries/LibGUI/AboutDialog.cpp b/Libraries/LibGUI/AboutDialog.cpp index 4a0087307f..615d30ae20 100644 --- a/Libraries/LibGUI/AboutDialog.cpp +++ b/Libraries/LibGUI/AboutDialog.cpp @@ -83,7 +83,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Core:: auto ok_button = button_container->add