浏览代码

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.
Karol Kosek 3 年之前
父节点
当前提交
07b369b7d9
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp

+ 6 - 1
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<SpreadsheetView&>(selected_widget);
+    };
+
     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());