From c9ed88309b6c8e7fce9fc2f1237ae133f713e564 Mon Sep 17 00:00:00 2001 From: Humberto Alves Date: Tue, 28 Jun 2022 17:08:34 +0100 Subject: [PATCH] Playground: Set `editor->on_change` before opening files Set `editor->on_change` callback before opening files, otherwise the compiled GML preview will only be available after some manual input in the text editor. --- Userland/DevTools/Playground/main.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Userland/DevTools/Playground/main.cpp b/Userland/DevTools/Playground/main.cpp index bd09bd5f39..8ae7395ba9 100644 --- a/Userland/DevTools/Playground/main.cpp +++ b/Userland/DevTools/Playground/main.cpp @@ -109,6 +109,18 @@ ErrorOr serenity_main(Main::Arguments arguments) window->set_title(builder.to_string()); }; + editor->on_change = [&] { + preview->remove_all_children(); + preview->load_from_gml(editor->text(), [](const String& class_name) -> RefPtr { + return UnregisteredWidget::construct(class_name); + }); + }; + + editor->on_modified_change = [&](bool modified) { + window->set_modified(modified); + update_title(); + }; + if (String(path).is_empty()) { editor->set_text(R"~~~(@GUI::Frame { layout: @GUI::VerticalBoxLayout { @@ -134,18 +146,6 @@ ErrorOr serenity_main(Main::Arguments arguments) update_title(); } - editor->on_change = [&] { - preview->remove_all_children(); - preview->load_from_gml(editor->text(), [](const String& class_name) -> RefPtr { - return UnregisteredWidget::construct(class_name); - }); - }; - - editor->on_modified_change = [&](bool modified) { - window->set_modified(modified); - update_title(); - }; - auto file_menu = TRY(window->try_add_menu("&File")); auto save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {