GMLPreviewWidget.cpp 1.2 KB

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