mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-16 17:00:35 +03:00
Spreadsheet: Add Insert Emoji action
This adds the Insert Emoji action to Spreadsheet.
This commit is contained in:
parent
44a5deff40
commit
fff79379d4
Notes:
sideshowbarker
2024-07-17 07:20:43 +09:00
Author: https://github.com/electrikmilk Commit: https://github.com/SerenityOS/serenity/commit/fff79379d4 Pull-request: https://github.com/SerenityOS/serenity/pull/15163 Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/trflynn89
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user