From de82901d4c6775517e519798b9a4c438b64b15f1 Mon Sep 17 00:00:00 2001 From: creator1creeper1 Date: Fri, 7 Jan 2022 14:14:47 +0100 Subject: [PATCH] TextEditor: Propagate errors using try_set_main_widget in main --- Userland/Applications/TextEditor/main.cpp | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Userland/Applications/TextEditor/main.cpp b/Userland/Applications/TextEditor/main.cpp index 39dafd459e..2a0c9fce5e 100644 --- a/Userland/Applications/TextEditor/main.cpp +++ b/Userland/Applications/TextEditor/main.cpp @@ -44,30 +44,30 @@ ErrorOr serenity_main(Main::Arguments arguments) auto window = TRY(GUI::Window::try_create()); window->resize(640, 400); - auto& text_widget = window->set_main_widget(); + auto text_widget = TRY(window->try_set_main_widget()); - text_widget.editor().set_focus(true); + text_widget->editor().set_focus(true); window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision { - if (text_widget.request_close()) + if (text_widget->request_close()) return GUI::Window::CloseRequestDecision::Close; return GUI::Window::CloseRequestDecision::StayOpen; }; if (preview_mode_view == "auto") { - text_widget.set_auto_detect_preview_mode(true); + text_widget->set_auto_detect_preview_mode(true); } else if (preview_mode_view == "markdown") { - text_widget.set_preview_mode(MainWidget::PreviewMode::Markdown); + text_widget->set_preview_mode(MainWidget::PreviewMode::Markdown); } else if (preview_mode_view == "html") { - text_widget.set_preview_mode(MainWidget::PreviewMode::HTML); + text_widget->set_preview_mode(MainWidget::PreviewMode::HTML); } else if (preview_mode_view == "none") { - text_widget.set_preview_mode(MainWidget::PreviewMode::None); + text_widget->set_preview_mode(MainWidget::PreviewMode::None); } else { warnln("Invalid mode '{}'", preview_mode); return 1; } - text_widget.initialize_menubar(*window); + text_widget->initialize_menubar(*window); window->show(); window->set_icon(app_icon.bitmap_for_size(16)); @@ -77,14 +77,14 @@ ErrorOr serenity_main(Main::Arguments arguments) auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window->window_id(), parsed_argument.filename()); if (response.error == 0) { - if (!text_widget.read_file_and_close(*response.fd, *response.chosen_file)) + if (!text_widget->read_file_and_close(*response.fd, *response.chosen_file)) return 1; - text_widget.editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0)); + text_widget->editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0)); } else { - text_widget.open_nonexistent_file(parsed_argument.filename()); + text_widget->open_nonexistent_file(parsed_argument.filename()); } } - text_widget.update_title(); + text_widget->update_title(); return app->exec(); }