mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-08 12:56:23 +03:00
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.
This commit is contained in:
parent
a4d2b366b6
commit
640e22bbdb
Notes:
sideshowbarker
2024-07-17 07:08:37 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/640e22bbdb Pull-request: https://github.com/SerenityOS/serenity/pull/16710
@ -192,13 +192,21 @@ MainWidget::MainWidget()
|
||||
};
|
||||
|
||||
m_statusbar = find_descendant_of_type_named<GUI::Statusbar>("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()));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user