diff options
author | Samuel Bowman <sam@sambowman.tech> | 2022-10-15 13:15:03 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-15 23:16:38 +0200 |
commit | 5e26bb764308a87082c769eff65755ac2bcf23d9 (patch) | |
tree | 01ee0e65a60a79c18a23bd0e34f87c476ea56b15 /Userland | |
parent | 094f9bf6a274f17fe602f11414deb9f96077f86b (diff) | |
download | serenity-5e26bb764308a87082c769eff65755ac2bcf23d9.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/DevTools/GMLPlayground/main.cpp | 43 |
1 files 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 <LibCore/File.h> #include <LibCore/System.h> #include <LibDesktop/Launcher.h> +#include <LibGUI/ActionGroup.h> #include <LibGUI/Application.h> #include <LibGUI/FilePicker.h> #include <LibGUI/GML/AutocompleteProvider.h> @@ -84,9 +85,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) window->resize(800, 600); auto splitter = TRY(window->try_set_main_widget<GUI::HorizontalSplitter>()); - auto editor = TRY(splitter->try_add<GUI::TextEditor>()); - auto preview = TRY(splitter->try_add<GUI::Frame>()); + auto preview_frame_widget = TRY(splitter->try_add<GUI::Frame>()); + + 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>()); + + GUI::Widget* preview = preview_frame_widget; editor->set_syntax_highlighter(make<GUI::GML::SyntaxHighlighter>()); editor->set_autocomplete_provider(make<GUI::GML::AutocompleteProvider>()); @@ -246,6 +253,38 @@ ErrorOr<int> 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"); |