mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
HackStudio: Add statusbar with file and selected text information
This commit is contained in:
parent
e22a34badb
commit
2634cab7a8
8 changed files with 50 additions and 9 deletions
|
@ -50,6 +50,7 @@
|
|||
#include <LibGUI/RegularEditingEngine.h>
|
||||
#include <LibGUI/Splitter.h>
|
||||
#include <LibGUI/StackWidget.h>
|
||||
#include <LibGUI/Statusbar.h>
|
||||
#include <LibGUI/TabWidget.h>
|
||||
#include <LibGUI/TableView.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
|
@ -135,6 +136,8 @@ HackStudioWidget::HackStudioWidget(const String& path_to_project)
|
|||
|
||||
create_toolbar(toolbar_container);
|
||||
|
||||
m_statusbar = add<GUI::Statusbar>(3);
|
||||
|
||||
auto maybe_watcher = Core::FileWatcher::create();
|
||||
if (maybe_watcher.is_error()) {
|
||||
warnln("Couldn't create a file watcher, deleted files won't be noticed! Error: {}", maybe_watcher.error());
|
||||
|
@ -280,6 +283,8 @@ bool HackStudioWidget::open_file(const String& full_filename)
|
|||
current_editor_wrapper().set_filename(filename);
|
||||
|
||||
current_editor().set_focus(true);
|
||||
|
||||
current_editor().on_cursor_change = [this] { update_statusbar(); };
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -496,6 +501,7 @@ void HackStudioWidget::add_new_editor(GUI::Widget& parent)
|
|||
m_all_editor_wrappers.append(wrapper);
|
||||
wrapper->editor().set_focus(true);
|
||||
wrapper->set_project_root(LexicalPath(m_project->root_path()));
|
||||
wrapper->editor().on_cursor_change = [this] { update_statusbar(); };
|
||||
}
|
||||
|
||||
NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_next_editor_action()
|
||||
|
@ -1038,6 +1044,21 @@ void HackStudioWidget::initialize_menubar(GUI::Menubar& menubar)
|
|||
create_help_menubar(menubar);
|
||||
}
|
||||
|
||||
void HackStudioWidget::update_statusbar()
|
||||
{
|
||||
m_statusbar->set_text(0, String::formatted("Ln {}, Col {}", current_editor().cursor().line() + 1, current_editor().cursor().column()));
|
||||
|
||||
StringBuilder builder;
|
||||
if (current_editor().has_selection()) {
|
||||
String selected_text = current_editor().selected_text();
|
||||
auto word_count = current_editor().number_of_selected_words();
|
||||
builder.appendff("Selected: {} {} ({} {})", selected_text.length(), selected_text.length() == 1 ? "character" : "characters", word_count, word_count != 1 ? "words" : "word");
|
||||
}
|
||||
|
||||
m_statusbar->set_text(1, builder.to_string());
|
||||
m_statusbar->set_text(2, current_editor_wrapper().editor().code_document().language_name());
|
||||
}
|
||||
|
||||
void HackStudioWidget::handle_external_file_deletion(const String& filepath)
|
||||
{
|
||||
m_open_files.remove(filepath);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue