mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:07:43 +00:00
GTextEditor: Create the "go to line" action eagerly
Previously it was created the first time you requested a context menu for the GTextEditor by right-clicking in it. That meant it wasn't possible to use Ctrl+L to "go to line" before you had first right-clicked the editor.
This commit is contained in:
parent
a33259483a
commit
1c34348b0c
2 changed files with 15 additions and 11 deletions
|
@ -83,6 +83,18 @@ void GTextEditor::create_actions()
|
||||||
m_copy_action = GCommonActions::make_copy_action([&](auto&) { copy(); }, this);
|
m_copy_action = GCommonActions::make_copy_action([&](auto&) { copy(); }, this);
|
||||||
m_paste_action = GCommonActions::make_paste_action([&](auto&) { paste(); }, this);
|
m_paste_action = GCommonActions::make_paste_action([&](auto&) { paste(); }, this);
|
||||||
m_delete_action = GCommonActions::make_delete_action([&](auto&) { do_delete(); }, this);
|
m_delete_action = GCommonActions::make_delete_action([&](auto&) { do_delete(); }, this);
|
||||||
|
m_go_to_line_action = GAction::create(
|
||||||
|
"Go to line...", { Mod_Ctrl, Key_L }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) {
|
||||||
|
auto input_box = GInputBox::construct("Line:", "Go to line", window());
|
||||||
|
auto result = input_box->exec();
|
||||||
|
if (result == GInputBox::ExecOK) {
|
||||||
|
bool ok;
|
||||||
|
auto line_number = input_box->text_value().to_uint(ok);
|
||||||
|
if (ok)
|
||||||
|
set_cursor(line_number - 1, 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::set_text(const StringView& text)
|
void GTextEditor::set_text(const StringView& text)
|
||||||
|
@ -1223,17 +1235,7 @@ void GTextEditor::context_menu_event(GContextMenuEvent& event)
|
||||||
m_context_menu->add_action(delete_action());
|
m_context_menu->add_action(delete_action());
|
||||||
if (is_multi_line()) {
|
if (is_multi_line()) {
|
||||||
m_context_menu->add_separator();
|
m_context_menu->add_separator();
|
||||||
m_context_menu->add_action(GAction::create(
|
m_context_menu->add_action(go_to_line_action());
|
||||||
"Go to line...", { Mod_Ctrl, Key_L }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) {
|
|
||||||
auto input_box = GInputBox::construct("Line:", "Go to line", window());
|
|
||||||
auto result = input_box->exec();
|
|
||||||
if (result == GInputBox::ExecOK) {
|
|
||||||
bool ok;
|
|
||||||
auto line_number = input_box->text_value().to_uint(ok);
|
|
||||||
if (ok)
|
|
||||||
set_cursor(line_number - 1, 0);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
if (!m_custom_context_menu_actions.is_empty()) {
|
if (!m_custom_context_menu_actions.is_empty()) {
|
||||||
m_context_menu->add_separator();
|
m_context_menu->add_separator();
|
||||||
|
|
|
@ -124,6 +124,7 @@ public:
|
||||||
GAction& copy_action() { return *m_copy_action; }
|
GAction& copy_action() { return *m_copy_action; }
|
||||||
GAction& paste_action() { return *m_paste_action; }
|
GAction& paste_action() { return *m_paste_action; }
|
||||||
GAction& delete_action() { return *m_delete_action; }
|
GAction& delete_action() { return *m_delete_action; }
|
||||||
|
GAction& go_to_line_action() { return *m_go_to_line_action; }
|
||||||
|
|
||||||
void add_custom_context_menu_action(GAction&);
|
void add_custom_context_menu_action(GAction&);
|
||||||
|
|
||||||
|
@ -230,6 +231,7 @@ private:
|
||||||
RefPtr<GAction> m_copy_action;
|
RefPtr<GAction> m_copy_action;
|
||||||
RefPtr<GAction> m_paste_action;
|
RefPtr<GAction> m_paste_action;
|
||||||
RefPtr<GAction> m_delete_action;
|
RefPtr<GAction> m_delete_action;
|
||||||
|
RefPtr<GAction> m_go_to_line_action;
|
||||||
CElapsedTimer m_triple_click_timer;
|
CElapsedTimer m_triple_click_timer;
|
||||||
NonnullRefPtrVector<GAction> m_custom_context_menu_actions;
|
NonnullRefPtrVector<GAction> m_custom_context_menu_actions;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue