1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

HackStudio: Propagate errors using try_set_main_widget

The documentation tooltip and parameters hint tooltip initialization
functions are now fallible and now call try_set_main_widget
instead of set_main_widget. They are only called by Editor's new
custom try_create function.
This commit is contained in:
creator1creeper1 2022-01-07 15:40:06 +01:00 committed by Andreas Kling
parent 4c0b8a70e2
commit d4484f4de3
3 changed files with 21 additions and 10 deletions

View file

@ -40,11 +40,17 @@
namespace HackStudio { namespace HackStudio {
ErrorOr<NonnullRefPtr<Editor>> Editor::try_create()
{
NonnullRefPtr<Editor> editor = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Editor()));
TRY(editor->initialize_documentation_tooltip());
TRY(editor->initialize_parameters_hint_tooltip());
return editor;
}
Editor::Editor() Editor::Editor()
{ {
set_document(CodeDocument::create()); set_document(CodeDocument::create());
initialize_documentation_tooltip();
initialize_parameters_hint_tooltip();
m_evaluate_expression_action = GUI::Action::create("Evaluate expression", { Mod_Ctrl, Key_E }, [this](auto&) { m_evaluate_expression_action = GUI::Action::create("Evaluate expression", { Mod_Ctrl, Key_E }, [this](auto&) {
VERIFY(is_program_running()); VERIFY(is_program_running());
auto dialog = EvaluateExpressionDialog::construct(window()); auto dialog = EvaluateExpressionDialog::construct(window());
@ -72,20 +78,22 @@ Editor::~Editor()
{ {
} }
void Editor::initialize_documentation_tooltip() ErrorOr<void> Editor::initialize_documentation_tooltip()
{ {
m_documentation_tooltip_window = GUI::Window::construct(); m_documentation_tooltip_window = GUI::Window::construct();
m_documentation_tooltip_window->set_rect(0, 0, 500, 400); m_documentation_tooltip_window->set_rect(0, 0, 500, 400);
m_documentation_tooltip_window->set_window_type(GUI::WindowType::Tooltip); m_documentation_tooltip_window->set_window_type(GUI::WindowType::Tooltip);
m_documentation_page_view = m_documentation_tooltip_window->set_main_widget<Web::OutOfProcessWebView>(); m_documentation_page_view = TRY(m_documentation_tooltip_window->try_set_main_widget<Web::OutOfProcessWebView>());
return {};
} }
void Editor::initialize_parameters_hint_tooltip() ErrorOr<void> Editor::initialize_parameters_hint_tooltip()
{ {
m_parameters_hint_tooltip_window = GUI::Window::construct(); m_parameters_hint_tooltip_window = GUI::Window::construct();
m_parameters_hint_tooltip_window->set_rect(0, 0, 280, 35); m_parameters_hint_tooltip_window->set_rect(0, 0, 280, 35);
m_parameters_hint_tooltip_window->set_window_type(GUI::WindowType::Tooltip); m_parameters_hint_tooltip_window->set_window_type(GUI::WindowType::Tooltip);
m_parameter_hint_page_view = m_parameters_hint_tooltip_window->set_main_widget<Web::OutOfProcessWebView>(); m_parameter_hint_page_view = TRY(m_parameters_hint_tooltip_window->try_set_main_widget<Web::OutOfProcessWebView>());
return {};
} }
EditorWrapper& Editor::wrapper() EditorWrapper& Editor::wrapper()

View file

@ -21,8 +21,10 @@ namespace HackStudio {
class EditorWrapper; class EditorWrapper;
class Editor final : public GUI::TextEditor { class Editor final : public GUI::TextEditor {
C_OBJECT(Editor) C_OBJECT_ABSTRACT(Editor)
public: public:
static ErrorOr<NonnullRefPtr<Editor>> try_create();
virtual ~Editor() override; virtual ~Editor() override;
Function<void()> on_focus; Function<void()> on_focus;
@ -115,8 +117,8 @@ private:
RefPtr<GUI::Action> m_move_execution_to_line_action; RefPtr<GUI::Action> m_move_execution_to_line_action;
OwnPtr<LanguageClient> m_language_client; OwnPtr<LanguageClient> m_language_client;
void initialize_documentation_tooltip(); ErrorOr<void> initialize_documentation_tooltip();
void initialize_parameters_hint_tooltip(); ErrorOr<void> initialize_parameters_hint_tooltip();
}; };
} }

View file

@ -30,7 +30,8 @@ EditorWrapper::EditorWrapper()
m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
m_filename_label->set_fixed_height(14); m_filename_label->set_fixed_height(14);
m_editor = add<Editor>(); // FIXME: Propagate errors instead of giving up
m_editor = MUST(try_add<Editor>());
m_editor->set_ruler_visible(true); m_editor->set_ruler_visible(true);
m_editor->set_automatic_indentation_enabled(true); m_editor->set_automatic_indentation_enabled(true);