From 640e22bbdbd441e913f30926286a60564de9d06a Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 28 Dec 2022 22:48:22 -0500 Subject: [PATCH] SQLStudio: Only display the character/word count of selected text It's not particularly useful to see the word count of a SQL script, except for when displaying the number of selected words. This changes SQLStudio to behave exactly like HackStudio in this regard. We will use segment 0 to display the selected text stats (if any) and segment 2 for the cursor position. Segment 1 will be used in an upcoming commit for the current SQL connection status. We also now handle displaying action text the same way as HackStudio. --- Userland/DevTools/SQLStudio/MainWidget.cpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Userland/DevTools/SQLStudio/MainWidget.cpp b/Userland/DevTools/SQLStudio/MainWidget.cpp index 2c0bfdf991..56abc65c7f 100644 --- a/Userland/DevTools/SQLStudio/MainWidget.cpp +++ b/Userland/DevTools/SQLStudio/MainWidget.cpp @@ -192,13 +192,21 @@ MainWidget::MainWidget() }; m_statusbar = find_descendant_of_type_named("statusbar"sv); - - m_statusbar->segment(1).set_mode(GUI::Statusbar::Segment::Mode::Fixed); - m_statusbar->segment(1).set_fixed_width(font().width("000000 characters (00000 words) selected"sv) + font().max_glyph_width()); - + m_statusbar->segment(1).set_mode(GUI::Statusbar::Segment::Mode::Auto); m_statusbar->segment(2).set_mode(GUI::Statusbar::Segment::Mode::Fixed); m_statusbar->segment(2).set_fixed_width(font().width("Ln 0000, Col 000"sv) + font().max_glyph_width()); + GUI::Application::the()->on_action_enter = [this](GUI::Action& action) { + auto text = action.status_tip(); + if (text.is_empty()) + text = Gfx::parse_ampersand_string(action.text()); + m_statusbar->set_override_text(move(text)); + }; + + GUI::Application::the()->on_action_leave = [this](GUI::Action&) { + m_statusbar->set_override_text({}); + }; + m_sql_client = SQL::SQLClient::try_create().release_value_but_fixme_should_propagate_errors(); m_sql_client->on_execution_success = [this](auto, auto, auto, auto, auto, auto) { read_next_sql_statement_of_editor(); @@ -357,21 +365,19 @@ void MainWidget::on_editor_change() void MainWidget::update_statusbar(ScriptEditor* editor) { if (!editor) { - m_statusbar->set_text(1, ""); + m_statusbar->set_text(0, ""); m_statusbar->set_text(2, ""); return; } + StringBuilder builder; if (editor->has_selection()) { auto character_count = editor->selected_text().length(); auto word_count = editor->number_of_selected_words(); - m_statusbar->set_text(1, DeprecatedString::formatted("{} {} ({} {}) selected", character_count, character_count == 1 ? "character" : "characters", word_count, word_count == 1 ? "word" : "words")); - } else { - auto character_count = editor->text().length(); - auto word_count = editor->number_of_words(); - m_statusbar->set_text(1, DeprecatedString::formatted("{} {} ({} {})", character_count, character_count == 1 ? "character" : "characters", word_count, word_count == 1 ? "word" : "words")); + builder.appendff("Selected: {} {} ({} {})", character_count, character_count == 1 ? "character" : "characters", word_count, word_count != 1 ? "words" : "word"); } + m_statusbar->set_text(0, builder.to_deprecated_string()); m_statusbar->set_text(2, DeprecatedString::formatted("Ln {}, Col {}", editor->cursor().line() + 1, editor->cursor().column())); }