From 5e26bb764308a87082c769eff65755ac2bcf23d9 Mon Sep 17 00:00:00 2001 From: Samuel Bowman Date: Sat, 15 Oct 2022 13:15:03 -0400 Subject: [PATCH] GMLPlayground: Allow previewing GML in a separate window Previously, Playground would always preview the rendered GML in a frame next to the editor. This can be annoying when trying to work with small or large widget hierarchies since the size of the preview is tied to the size of the editor. Now there is a view menu which allows you to toggle between the frame or a separate window which can be resized independent of the editor. --- Userland/DevTools/GMLPlayground/main.cpp | 43 ++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/Userland/DevTools/GMLPlayground/main.cpp b/Userland/DevTools/GMLPlayground/main.cpp index 9530a76c47..42a231baab 100644 --- a/Userland/DevTools/GMLPlayground/main.cpp +++ b/Userland/DevTools/GMLPlayground/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -84,9 +85,15 @@ ErrorOr serenity_main(Main::Arguments arguments) window->resize(800, 600); auto splitter = TRY(window->try_set_main_widget()); - auto editor = TRY(splitter->try_add()); - auto preview = TRY(splitter->try_add()); + auto preview_frame_widget = TRY(splitter->try_add()); + + auto preview_window = TRY(GUI::Window::try_create()); + preview_window->set_title("Preview - GML Playground"); + preview_window->set_icon(app_icon.bitmap_for_size(16)); + auto preview_window_widget = TRY(preview_window->try_set_main_widget()); + + GUI::Widget* preview = preview_frame_widget; editor->set_syntax_highlighter(make()); editor->set_autocomplete_provider(make()); @@ -246,6 +253,38 @@ ErrorOr serenity_main(Main::Arguments arguments) vim_emulation_setting_action->set_checked(false); TRY(edit_menu->try_add_action(vim_emulation_setting_action)); + auto view_menu = TRY(window->try_add_menu("&View")); + GUI::ActionGroup views_group; + views_group.set_exclusive(true); + views_group.set_unchecking_allowed(false); + + auto view_frame_action = GUI::Action::create_checkable("&Frame", [&](auto&) { + dbgln("View switched to frame"); + preview = preview_frame_widget; + editor->on_change(); + preview_window->hide(); + preview_frame_widget->set_preferred_width(splitter->width() / 2); + preview_frame_widget->set_visible(true); + }); + view_menu->add_action(view_frame_action); + views_group.add_action(view_frame_action); + view_frame_action->set_checked(true); + + auto view_window_action = GUI::Action::create_checkable("&Window", [&](auto&) { + dbgln("View switched to window"); + preview = preview_window_widget; + editor->on_change(); + preview_window->resize(400, 300); + preview_window->show(); + preview_frame_widget->set_visible(false); + }); + view_menu->add_action(view_window_action); + views_group.add_action(view_window_action); + + preview_window->on_close = [&] { + view_frame_action->activate(); + }; + auto help_menu = TRY(window->try_add_menu("&Help")); TRY(help_menu->try_add_action(GUI::CommonActions::make_help_action([](auto&) { Desktop::Launcher::open(URL::create_with_file_scheme("/usr/share/man/man1/GMLPlayground.md"), "/bin/Help");