From 62668ebd81133f838a98a62e5743cb8633a18d85 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sun, 27 Feb 2022 11:03:21 +0100 Subject: [PATCH] Spreadsheet: Move tab widget actions to the main widget constructor There's no need to reassign these functions when we add a new tab. Nothing changes inside them and they don't depend on anything in the function. --- .../Spreadsheet/SpreadsheetWidget.cpp | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index 8682c519b8..a29da2ab4a 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -242,6 +242,26 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe m_cut_action->set_enabled(false); m_copy_action->set_enabled(false); + + m_tab_widget->on_context_menu_request = [&](auto& widget, auto& event) { + m_tab_context_menu_sheet_view = static_cast(widget); + m_tab_context_menu->popup(event.screen_position()); + }; + + m_tab_widget->on_double_click = [&](auto& widget) { + m_tab_context_menu_sheet_view = static_cast(widget); + VERIFY(m_tab_context_menu_sheet_view); + + auto* sheet_ptr = m_tab_context_menu_sheet_view->sheet_if_available(); + VERIFY(sheet_ptr); // How did we get here without a sheet? + auto& sheet = *sheet_ptr; + String new_name; + if (GUI::InputBox::show(window(), new_name, String::formatted("New name for '{}'", sheet.name()), "Rename sheet") == GUI::Dialog::ExecOK) { + sheet.set_name(new_name); + sheet.update(); + m_tab_widget->set_tab_title(static_cast(*m_tab_context_menu_sheet_view), new_name); + } + }; } void SpreadsheetWidget::resize_event(GUI::ResizeEvent& event) @@ -339,26 +359,6 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector new_sheets) static_cast(const_cast(m_cell_value_editor->syntax_highlighter()))->set_cell(nullptr); }; } - - m_tab_widget->on_context_menu_request = [&](auto& widget, auto& event) { - m_tab_context_menu_sheet_view = static_cast(widget); - m_tab_context_menu->popup(event.screen_position()); - }; - - m_tab_widget->on_double_click = [&](auto& widget) { - m_tab_context_menu_sheet_view = static_cast(widget); - VERIFY(m_tab_context_menu_sheet_view); - - auto* sheet_ptr = m_tab_context_menu_sheet_view->sheet_if_available(); - VERIFY(sheet_ptr); // How did we get here without a sheet? - auto& sheet = *sheet_ptr; - String new_name; - if (GUI::InputBox::show(window(), new_name, String::formatted("New name for '{}'", sheet.name()), "Rename sheet") == GUI::Dialog::ExecOK) { - sheet.set_name(new_name); - sheet.update(); - m_tab_widget->set_tab_title(static_cast(*m_tab_context_menu_sheet_view), new_name); - } - }; } void SpreadsheetWidget::try_generate_tip_for_input_expression(StringView source, size_t cursor_offset)