summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2022-02-27 11:03:21 +0100
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-03-15 12:01:27 +0330
commit62668ebd81133f838a98a62e5743cb8633a18d85 (patch)
treed6e02bc8684d7c9183ad6d12b777f49cc2da34da
parentc0c9825f67e649daf277e75829c8f4bce1428115 (diff)
downloadserenity-62668ebd81133f838a98a62e5743cb8633a18d85.zip
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.
-rw-r--r--Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp40
1 files 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<SpreadsheetView&>(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<SpreadsheetView&>(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<GUI::Widget&>(*m_tab_context_menu_sheet_view), new_name);
+ }
+ };
}
void SpreadsheetWidget::resize_event(GUI::ResizeEvent& event)
@@ -339,26 +359,6 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(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<SpreadsheetView&>(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<SpreadsheetView&>(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<GUI::Widget&>(*m_tab_context_menu_sheet_view), new_name);
- }
- };
}
void SpreadsheetWidget::try_generate_tip_for_input_expression(StringView source, size_t cursor_offset)