From 07b369b7d9fe26b697e45435c2d0f07bb0eb6b14 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sat, 26 Feb 2022 18:19:16 +0100 Subject: [PATCH] Spreadsheet: Create rename action using the GUI::CommonActions helper Besides from reusing more parts from the code, this allows us to call the action using the F2 key. That is also the reason why we have to reassign `m_tab_context_menu_sheet_view` on tab change. --- Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index 2a20fbda5b..1f9f010202 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -92,7 +92,7 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe m_workbook->add_sheet("Sheet 1"); m_tab_context_menu = GUI::Menu::construct(); - m_rename_action = GUI::Action::create("Rename...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/rename.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) { + m_rename_action = GUI::CommonActions::make_rename_action([this](auto&) { VERIFY(m_tab_context_menu_sheet_view); auto* sheet_ptr = m_tab_context_menu_sheet_view->sheet_if_available(); @@ -246,6 +246,11 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe m_cut_action->set_enabled(false); m_copy_action->set_enabled(false); + m_tab_widget->on_change = [this](auto& selected_widget) { + // for keyboard shortcuts and command palette + m_tab_context_menu_sheet_view = static_cast(selected_widget); + }; + 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());