diff options
author | FalseHonesty <thefalsehonesty@gmail.com> | 2020-05-29 16:00:18 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-29 22:14:45 +0200 |
commit | 9a2177437bd197fc53cb1296a52f13afb5c64475 (patch) | |
tree | 05dfa082e2455fecb01031f8cd7590d16e19bfc0 /Applications/Browser | |
parent | 2619d72eeb3f4a198d3b9c520373927bf805466a (diff) | |
download | serenity-9a2177437bd197fc53cb1296a52f13afb5c64475.zip |
Browser: Add clear output button to the console
Diffstat (limited to 'Applications/Browser')
-rw-r--r-- | Applications/Browser/ConsoleWidget.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Applications/Browser/ConsoleWidget.cpp b/Applications/Browser/ConsoleWidget.cpp index d67178a824..497ea3e497 100644 --- a/Applications/Browser/ConsoleWidget.cpp +++ b/Applications/Browser/ConsoleWidget.cpp @@ -27,6 +27,7 @@ #include "ConsoleWidget.h" #include <AK/StringBuilder.h> #include <LibGUI/BoxLayout.h> +#include <LibGUI/Button.h> #include <LibGUI/JSSyntaxHighlighter.h> #include <LibGUI/TextBox.h> #include <LibJS/Interpreter.h> @@ -59,10 +60,13 @@ ConsoleWidget::ConsoleWidget() m_output_view = add<Web::PageView>(); m_output_view->set_document(base_document); - m_input = add<GUI::TextBox>(); + auto& bottom_container = add<GUI::Widget>(); + bottom_container.set_layout<GUI::HorizontalBoxLayout>(); + bottom_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + bottom_container.set_preferred_size(0, 22); + + m_input = bottom_container.add<GUI::TextBox>(); m_input->set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>()); - m_input->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - m_input->set_preferred_size(0, 22); // FIXME: Syntax Highlighting breaks the cursor's position on non fixed-width fonts. m_input->set_font(Gfx::Font::default_fixed_width_font()); m_input->set_history_enabled(true); @@ -104,6 +108,15 @@ ConsoleWidget::ConsoleWidget() print_html(JS::MarkupGenerator::html_from_value(m_interpreter->last_value())); }; + + auto& clear_button = bottom_container.add<GUI::Button>(); + clear_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); + clear_button.set_preferred_size(22, 22); + clear_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/delete.png")); + clear_button.set_tooltip("Clear the console output"); + clear_button.on_click = [this](auto) { + clear_output(); + }; } ConsoleWidget::~ConsoleWidget() @@ -148,7 +161,8 @@ void ConsoleWidget::print_html(const StringView& line) void ConsoleWidget::clear_output() { - const_cast<Web::HTMLBodyElement*>(m_output_view->document()->body())->remove_all_children(); + m_output_container->remove_all_children(); + m_output_view->update(); } } |