diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-25 21:33:08 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-25 21:33:08 +0200 |
commit | a6be213287977c82eda977f334b0c475e42d308b (patch) | |
tree | b63e0ac97fa1e70ee4b71b97fa4e86cf71c1e151 | |
parent | 0df72136702796e3bdcca10e822da76a1b1ef1bd (diff) | |
download | serenity-a6be213287977c82eda977f334b0c475e42d308b.zip |
GTextEditor: Add add_custom_context_menu_action()
This allows embedders to add their own custom GAction set to a text
editor's context menu.
-rw-r--r-- | Libraries/LibGUI/GTextEditor.cpp | 11 | ||||
-rw-r--r-- | Libraries/LibGUI/GTextEditor.h | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp index 42b0eaaa5d..3b932826fc 100644 --- a/Libraries/LibGUI/GTextEditor.cpp +++ b/Libraries/LibGUI/GTextEditor.cpp @@ -1204,6 +1204,12 @@ void GTextEditor::context_menu_event(GContextMenuEvent& event) m_context_menu->add_action(copy_action()); m_context_menu->add_action(paste_action()); m_context_menu->add_action(delete_action()); + if (!m_custom_context_menu_actions.is_empty()) { + m_context_menu->add_separator(); + for (auto& action : m_custom_context_menu_actions) { + m_context_menu->add_action(action); + } + } } m_context_menu->popup(event.screen_position()); } @@ -1413,3 +1419,8 @@ int GTextEditor::Line::visual_line_containing(int column) const }); return visual_line_index; } + +void GTextEditor::add_custom_context_menu_action(GAction& action) +{ + m_custom_context_menu_actions.append(action); +} diff --git a/Libraries/LibGUI/GTextEditor.h b/Libraries/LibGUI/GTextEditor.h index 74a5345bb5..cb7e3d77ac 100644 --- a/Libraries/LibGUI/GTextEditor.h +++ b/Libraries/LibGUI/GTextEditor.h @@ -3,6 +3,7 @@ #include <AK/Function.h> #include <AK/HashMap.h> #include <AK/NonnullOwnPtrVector.h> +#include <AK/NonnullRefPtrVector.h> #include <LibDraw/TextAlignment.h> #include <LibGUI/GScrollableWidget.h> @@ -162,6 +163,8 @@ public: GAction& paste_action() { return *m_paste_action; } GAction& delete_action() { return *m_delete_action; } + void add_custom_context_menu_action(GAction&); + private: virtual void paint_event(GPaintEvent&) override; virtual void mousedown_event(GMouseEvent&) override; @@ -266,6 +269,7 @@ private: RefPtr<GAction> m_paste_action; RefPtr<GAction> m_delete_action; CElapsedTimer m_triple_click_timer; + NonnullRefPtrVector<GAction> m_custom_context_menu_actions; }; inline const LogStream& operator<<(const LogStream& stream, const GTextPosition& value) |