Base+LibGUI: Add insert emoji common action

This adds a common action to invoke the emoji picker.
This commit is contained in:
electrikmilk 2022-09-08 18:06:08 -04:00 committed by Linus Groh
parent dd510b24c9
commit 6a09d89329
Notes: sideshowbarker 2024-07-17 07:20:51 +09:00
5 changed files with 27 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

View file

@ -35,6 +35,7 @@ NonnullRefPtr<Action> make_paste_action(Function<void(Action&)>, Core::Object* p
NonnullRefPtr<Action> make_delete_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_move_to_front_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_move_to_back_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_insert_emoji_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_fullscreen_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_quit_action(Function<void(Action&)>);
NonnullRefPtr<Action> make_help_action(Function<void(Action&)>, Core::Object* parent = nullptr);

View file

@ -96,6 +96,13 @@ NonnullRefPtr<Action> make_paste_action(Function<void(Action&)> callback, Core::
return action;
}
NonnullRefPtr<Action> make_insert_emoji_action(Function<void(Action&)> callback, Core::Object* parent)
{
auto action = Action::create("&Insert Emoji", { Mod_Ctrl | Mod_Alt, Key_Space }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/emoji.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent);
action->set_status_tip("Open the Emoji Picker");
return action;
}
NonnullRefPtr<Action> make_fullscreen_action(Function<void(Action&)> callback, Core::Object* parent)
{
auto action = Action::create("&Fullscreen", { Mod_None, Key_F11 }, move(callback), parent);

View file

@ -17,6 +17,7 @@
#include <LibGUI/AutocompleteProvider.h>
#include <LibGUI/Clipboard.h>
#include <LibGUI/EditingEngine.h>
#include <LibGUI/EmojiInputDialog.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Painter.h>
@ -105,6 +106,7 @@ void TextEditor::create_actions()
this);
}
m_select_all_action = CommonActions::make_select_all_action([this](auto&) { select_all(); }, this);
m_insert_emoji_action = CommonActions::make_insert_emoji_action([&](auto&) { insert_emoji(); }, this);
}
void TextEditor::set_text(StringView text, AllowCallback allow_callback)
@ -771,6 +773,17 @@ void TextEditor::select_all()
update();
}
void TextEditor::insert_emoji()
{
auto emoji_input_dialog = EmojiInputDialog::construct(window());
emoji_input_dialog->set_window_mode(GUI::WindowMode::Passive);
if (emoji_input_dialog->exec() != EmojiInputDialog::ExecResult::OK)
return;
auto emoji_code_point = emoji_input_dialog->selected_emoji_text();
insert_at_cursor_or_replace_selection(emoji_code_point);
}
void TextEditor::keydown_event(KeyEvent& event)
{
if (!is_editable() && event.key() == KeyCode::Key_Tab)
@ -1667,12 +1680,14 @@ void TextEditor::set_mode(const Mode mode)
case Editable:
m_cut_action->set_enabled(has_selection() && !text_is_secret());
m_paste_action->set_enabled(true);
m_insert_emoji_action->set_enabled(true);
set_accepts_emoji_input(true);
break;
case DisplayOnly:
case ReadOnly:
m_cut_action->set_enabled(false);
m_paste_action->set_enabled(false);
m_insert_emoji_action->set_enabled(false);
set_accepts_emoji_input(false);
break;
default:
@ -1717,6 +1732,7 @@ void TextEditor::context_menu_event(ContextMenuEvent& event)
m_context_menu->add_action(paste_action());
m_context_menu->add_separator();
m_context_menu->add_action(select_all_action());
m_context_menu->add_action(insert_emoji_action());
if (is_multi_line()) {
m_context_menu->add_separator();
m_context_menu->add_action(go_to_line_action());

View file

@ -150,6 +150,7 @@ public:
void delete_previous_char();
void delete_from_line_start_to_cursor();
void select_all();
void insert_emoji();
void select_current_line();
virtual void undo();
virtual void redo();
@ -176,6 +177,7 @@ public:
Action& paste_action() { return *m_paste_action; }
Action& go_to_line_action() { return *m_go_to_line_action; }
Action& select_all_action() { return *m_select_all_action; }
Action& insert_emoji_action() { return *m_insert_emoji_action; }
void add_custom_context_menu_action(Action&);
@ -394,6 +396,7 @@ private:
RefPtr<Action> m_paste_action;
RefPtr<Action> m_go_to_line_action;
RefPtr<Action> m_select_all_action;
RefPtr<Action> m_insert_emoji_action;
Core::ElapsedTimer m_triple_click_timer;
NonnullRefPtrVector<Action> m_custom_context_menu_actions;