From a33259483a99f9056c4397f98ad54c7c5ba70760 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 23 Jan 2020 21:21:55 +0100 Subject: [PATCH] GTextEditor: Move "Go to line" feature from HackStudio into GTextEditor This is a handy feature for any multi-line GTextEditor, so let's just have it in the base widget. :^) Fixes #1122. --- DevTools/HackStudio/EditorWrapper.cpp | 14 -------------- Libraries/LibGUI/GTextEditor.cpp | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/DevTools/HackStudio/EditorWrapper.cpp b/DevTools/HackStudio/EditorWrapper.cpp index a454ab77bc..5bdd140dd6 100644 --- a/DevTools/HackStudio/EditorWrapper.cpp +++ b/DevTools/HackStudio/EditorWrapper.cpp @@ -67,20 +67,6 @@ EditorWrapper::EditorWrapper(GWidget* parent) m_editor->on_focus = [this] { g_current_editor_wrapper = this; }; - - m_editor->add_custom_context_menu_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) { - m_editor->set_cursor(line_number - 1, 0); - } - } - }, - m_editor)); } EditorWrapper::~EditorWrapper() diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp index 46f1cb855c..0ff02f1da9 100644 --- a/Libraries/LibGUI/GTextEditor.cpp +++ b/Libraries/LibGUI/GTextEditor.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1220,6 +1221,20 @@ 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 (is_multi_line()) { + m_context_menu->add_separator(); + m_context_menu->add_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); + } + })); + } if (!m_custom_context_menu_actions.is_empty()) { m_context_menu->add_separator(); for (auto& action : m_custom_context_menu_actions) {