From 5a346c4297266a307d9b0f3beb8d53c47b4bfe0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Sun, 11 Dec 2022 22:32:35 +0100 Subject: [PATCH] Help+LibManual: Without arguments, open index page instead of crashing This is the old behavior before the recent LibManual refactor. It also moves the definition of the index page into LibManual for better reuse. --- Userland/Applications/Help/MainWidget.cpp | 2 +- Userland/Libraries/LibManual/Node.cpp | 3 +-- Userland/Libraries/LibManual/PageNode.cpp | 7 +++++++ Userland/Libraries/LibManual/PageNode.h | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/Help/MainWidget.cpp b/Userland/Applications/Help/MainWidget.cpp index 0ba220d696..b67390b1eb 100644 --- a/Userland/Applications/Help/MainWidget.cpp +++ b/Userland/Applications/Help/MainWidget.cpp @@ -213,7 +213,7 @@ ErrorOr MainWidget::set_start_page(Vector query_parameters) ErrorOr MainWidget::initialize_fallibles(GUI::Window& window) { - static String const help_index_path = TRY(TRY(try_make_ref_counted(Manual::sections[7 - 1], TRY(String::from_utf8("Help-index"sv))))->path()); + static String const help_index_path = TRY(TRY(Manual::PageNode::help_index_page())->path()); m_go_home_action = GUI::CommonActions::make_go_home_action([this](auto&) { m_history.push(help_index_path); open_page(help_index_path); diff --git a/Userland/Libraries/LibManual/Node.cpp b/Userland/Libraries/LibManual/Node.cpp index e8720f88ab..40c17d1913 100644 --- a/Userland/Libraries/LibManual/Node.cpp +++ b/Userland/Libraries/LibManual/Node.cpp @@ -25,8 +25,7 @@ ErrorOr> Node::try_create_from_query(Vector namespace Manual { @@ -26,4 +27,10 @@ ErrorOr PageNode::path() const return TRY(String::formatted("{}/{}.md", TRY(m_section->path()), m_page)); } +ErrorOr> PageNode::help_index_page() +{ + static NonnullRefPtr const help_index_page = TRY(try_make_ref_counted(sections[7 - 1], TRY(String::from_utf8("Help-index"sv)))); + return help_index_page; +} + } diff --git a/Userland/Libraries/LibManual/PageNode.h b/Userland/Libraries/LibManual/PageNode.h index 2e7a184669..66976a593f 100644 --- a/Userland/Libraries/LibManual/PageNode.h +++ b/Userland/Libraries/LibManual/PageNode.h @@ -30,6 +30,8 @@ public: ErrorOr path() const; + static ErrorOr> help_index_page(); + private: NonnullRefPtr m_section; String m_page;