diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index 33fc5a06336..ef6cf3293dc 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -209,6 +210,31 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe }, window()); + m_insert_emoji_action = GUI::CommonActions::make_insert_emoji_action([&](auto&) { + auto emoji_input_dialog = GUI::EmojiInputDialog::construct(window()); + emoji_input_dialog->set_window_mode(GUI::WindowMode::Passive); + if (emoji_input_dialog->exec() != GUI::EmojiInputDialog::ExecResult::OK) + return; + + auto emoji_code_point = emoji_input_dialog->selected_emoji_text(); + + if (m_cell_value_editor->has_focus_within()) { + m_cell_value_editor->insert_at_cursor_or_replace_selection(emoji_code_point); + } + + auto* worksheet_ptr = current_worksheet_if_available(); + if (!worksheet_ptr) { + GUI::MessageBox::show_error(window(), "There are no active worksheets"sv); + return; + } + auto& sheet = *worksheet_ptr; + for (auto& cell : sheet.selected_cells()) + sheet.ensure(cell).set_data(emoji_code_point); + + update(); + }, + window()); + m_undo_action = GUI::CommonActions::make_undo_action([&](auto&) { undo(); }); @@ -253,6 +279,7 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe m_cut_action->set_enabled(false); m_copy_action->set_enabled(false); m_paste_action->set_enabled(false); + m_insert_emoji_action->set_enabled(false); m_tab_widget->on_change = [this](auto& selected_widget) { // for keyboard shortcuts and command palette @@ -305,6 +332,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector new_sheets) m_cut_action->set_enabled(true); m_copy_action->set_enabled(true); m_paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type().starts_with("text/"sv)); + m_insert_emoji_action->set_enabled(true); m_current_cell_label->set_enabled(true); m_cell_value_editor->set_enabled(true); @@ -373,6 +401,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector new_sheets) m_cut_action->set_enabled(false); m_copy_action->set_enabled(false); m_paste_action->set_enabled(false); + m_insert_emoji_action->set_enabled(false); static_cast(const_cast(m_cell_value_editor->syntax_highlighter()))->set_cell(nullptr); }; @@ -597,6 +626,7 @@ void SpreadsheetWidget::initialize_menubar(GUI::Window& window) edit_menu.add_action(*m_cut_action); edit_menu.add_action(*m_copy_action); edit_menu.add_action(*m_paste_action); + edit_menu.add_action(*m_insert_emoji_action); auto& help_menu = window.add_menu("&Help"); help_menu.add_action(*m_functions_help_action); diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.h b/Userland/Applications/Spreadsheet/SpreadsheetWidget.h index 734223b04e6..89a126b7b14 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.h +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.h @@ -89,6 +89,7 @@ private: RefPtr m_cut_action; RefPtr m_copy_action; RefPtr m_paste_action; + RefPtr m_insert_emoji_action; RefPtr m_undo_action; RefPtr m_redo_action;