Serenity Operating System
1/*
2 * Copyright (c) 2021, Conor Byrne <cbyrneee@protonmail.com>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include "GMLPreviewWidget.h"
8#include <LibGUI/BoxLayout.h>
9#include <LibGUI/Label.h>
10
11namespace HackStudio {
12
13GMLPreviewWidget::GMLPreviewWidget(DeprecatedString const& gml_content)
14{
15 set_layout<GUI::VerticalBoxLayout>();
16 load_gml(gml_content);
17}
18
19void GMLPreviewWidget::load_gml(DeprecatedString const& gml)
20{
21 remove_all_children();
22
23 if (gml.is_empty()) {
24 auto& label = add<GUI::Label>();
25 label.set_text("Open a .gml file to show the preview");
26
27 return;
28 }
29
30 // FIXME: Parsing errors happen while the user is typing. What should we do about them?
31 (void)load_from_gml(gml, [](DeprecatedString const& name) -> ErrorOr<NonnullRefPtr<Core::Object>> {
32 return GUI::Label::try_create(DeprecatedString::formatted("{} is not registered as a GML element!", name));
33 });
34
35 if (children().is_empty()) {
36 auto& label = add<GUI::Label>();
37 label.set_text("Failed to load GML!");
38 }
39}
40
41}