HackStudio: Show line numbers in the text editor by default

This commit is contained in:
Andreas Kling 2019-10-21 19:03:09 +02:00
parent 0a0dfeee8b
commit c1f72e0bbf
Notes: sideshowbarker 2024-07-19 11:35:41 +09:00

View file

@ -1,7 +1,9 @@
#include "Project.h"
#include <LibCore/CFile.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GInputBox.h>
#include <LibGUI/GListView.h>
#include <LibGUI/GMessageBox.h>
#include <LibGUI/GSplitter.h>
@ -44,6 +46,7 @@ int main(int argc, char** argv)
project_list_view->set_preferred_size(200, 0);
auto text_editor = GTextEditor::construct(GTextEditor::MultiLine, splitter);
text_editor->set_ruler_visible(true);
project_list_view->on_activation = [&](auto& index) {
auto filename = project_list_view->model()->data(index).to_string();
@ -61,6 +64,18 @@ int main(int argc, char** argv)
statusbar->set_text(String::format("Line: %d, Column: %d", text_editor->cursor().line(), text_editor->cursor().column()));
};
text_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"), [&](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) {
text_editor->set_cursor(line_number, 0);
}
}
}));
window->show();
return app.exec();
}