1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

GMLPlayground: Add a Statusbar

This commit is contained in:
Sam Atkins 2023-06-17 16:40:56 +01:00 committed by Andreas Kling
parent 506f9484e3
commit ae6bde6847
3 changed files with 19 additions and 1 deletions

View file

@ -20,4 +20,8 @@
name: "preview_frame"
}
}
@GUI::Statusbar {
name: "statusbar"
}
}

View file

@ -24,6 +24,7 @@
#include <LibGUI/Painter.h>
#include <LibGUI/RegularEditingEngine.h>
#include <LibGUI/Splitter.h>
#include <LibGUI/Statusbar.h>
#include <LibGUI/TextEditor.h>
#include <LibGUI/Toolbar.h>
#include <LibGUI/VimEditingEngine.h>
@ -62,7 +63,7 @@ void UnregisteredWidget::paint_event(GUI::PaintEvent& event)
ErrorOr<NonnullRefPtr<MainWidget>> MainWidget::try_create(GUI::Icon const& icon)
{
auto main_widget = TRY(try_make_ref_counted<MainWidget>());
auto main_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MainWidget()));
TRY(main_widget->load_from_gml(gml_playground_window_gml));
main_widget->m_icon = icon;
@ -70,6 +71,7 @@ ErrorOr<NonnullRefPtr<MainWidget>> MainWidget::try_create(GUI::Icon const& icon)
main_widget->m_splitter = main_widget->find_descendant_of_type_named<GUI::HorizontalSplitter>("splitter");
main_widget->m_editor = main_widget->find_descendant_of_type_named<GUI::TextEditor>("text_editor");
main_widget->m_preview_frame_widget = main_widget->find_descendant_of_type_named<GUI::Frame>("preview_frame");
main_widget->m_statusbar = main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
main_widget->m_preview_window = TRY(GUI::Window::try_create(main_widget));
main_widget->m_preview_window->set_title("Preview - GML Playground");
@ -100,6 +102,16 @@ ErrorOr<NonnullRefPtr<MainWidget>> MainWidget::try_create(GUI::Icon const& icon)
return main_widget;
}
MainWidget::MainWidget()
{
GUI::Application::the()->on_action_enter = [this](GUI::Action& action) {
m_statusbar->set_override_text(action.status_tip());
};
GUI::Application::the()->on_action_leave = [this](GUI::Action&) {
m_statusbar->set_override_text({});
};
}
void MainWidget::update_title()
{
window()->set_title(DeprecatedString::formatted("{}[*] - GML Playground", m_file_path.is_empty() ? "Untitled"sv : m_file_path.view()));

View file

@ -30,6 +30,7 @@ public:
GUI::TextEditor& editor() const { return *m_editor; }
private:
MainWidget();
virtual void drag_enter_event(GUI::DragEvent&) override;
virtual void drop_event(GUI::DropEvent&) override;
@ -37,6 +38,7 @@ private:
RefPtr<GUI::TextEditor> m_editor;
RefPtr<GUI::Toolbar> m_toolbar;
RefPtr<GUI::Splitter> m_splitter;
RefPtr<GUI::Statusbar> m_statusbar;
RefPtr<GUI::Frame> m_preview_frame_widget;
RefPtr<GUI::Window> m_preview_window;