summaryrefslogtreecommitdiff
path: root/Userland/Applications/Spreadsheet
diff options
context:
space:
mode:
authorelectrikmilk <brandonjordan124@gmail.com>2022-09-08 18:06:43 -0400
committerLinus Groh <mail@linusgroh.de>2022-09-08 23:08:54 +0100
commitfff79379d4270ece49cce85e67d09f0e5ab7315d (patch)
treeb471c35ad0a45ddb6fe13579abf2e80419b8f090 /Userland/Applications/Spreadsheet
parent44a5deff4027925bd1e29dc5902bd452dee0ba64 (diff)
downloadserenity-fff79379d4270ece49cce85e67d09f0e5ab7315d.zip
Spreadsheet: Add Insert Emoji action
This adds the Insert Emoji action to Spreadsheet.
Diffstat (limited to 'Userland/Applications/Spreadsheet')
-rw-r--r--Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp30
-rw-r--r--Userland/Applications/Spreadsheet/SpreadsheetWidget.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp
index 33fc5a0633..ef6cf3293d 100644
--- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp
+++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp
@@ -11,6 +11,7 @@
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
+#include <LibGUI/EmojiInputDialog.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
@@ -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<Sheet> 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<Sheet> 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<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(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 734223b04e..89a126b7b1 100644
--- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.h
+++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.h
@@ -89,6 +89,7 @@ private:
RefPtr<GUI::Action> m_cut_action;
RefPtr<GUI::Action> m_copy_action;
RefPtr<GUI::Action> m_paste_action;
+ RefPtr<GUI::Action> m_insert_emoji_action;
RefPtr<GUI::Action> m_undo_action;
RefPtr<GUI::Action> m_redo_action;