mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +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:
parent
4c0b8a70e2
commit
d4484f4de3
Notes:
sideshowbarker
2024-07-17 21:21:45 +09:00
Author: https://github.com/creator1creeper1 Commit: https://github.com/SerenityOS/serenity/commit/d4484f4de30 Pull-request: https://github.com/SerenityOS/serenity/pull/11698
3 changed files with 21 additions and 10 deletions
|
@ -40,11 +40,17 @@
|
|||
|
||||
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()
|
||||
{
|
||||
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&) {
|
||||
VERIFY(is_program_running());
|
||||
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->set_rect(0, 0, 500, 400);
|
||||
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->set_rect(0, 0, 280, 35);
|
||||
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()
|
||||
|
|
|
@ -21,8 +21,10 @@ namespace HackStudio {
|
|||
class EditorWrapper;
|
||||
|
||||
class Editor final : public GUI::TextEditor {
|
||||
C_OBJECT(Editor)
|
||||
C_OBJECT_ABSTRACT(Editor)
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<Editor>> try_create();
|
||||
|
||||
virtual ~Editor() override;
|
||||
|
||||
Function<void()> on_focus;
|
||||
|
@ -115,8 +117,8 @@ private:
|
|||
RefPtr<GUI::Action> m_move_execution_to_line_action;
|
||||
|
||||
OwnPtr<LanguageClient> m_language_client;
|
||||
void initialize_documentation_tooltip();
|
||||
void initialize_parameters_hint_tooltip();
|
||||
ErrorOr<void> initialize_documentation_tooltip();
|
||||
ErrorOr<void> initialize_parameters_hint_tooltip();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ EditorWrapper::EditorWrapper()
|
|||
m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
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_automatic_indentation_enabled(true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue