mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 11:09:05 +03:00
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.
This commit is contained in:
parent
c0c9825f67
commit
62668ebd81
Notes:
sideshowbarker
2024-07-17 17:24:16 +09:00
Author: https://github.com/krkk Commit: https://github.com/SerenityOS/serenity/commit/62668ebd81 Pull-request: https://github.com/SerenityOS/serenity/pull/13032 Reviewed-by: https://github.com/kleinesfilmroellchen ✅
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user