From 44e4a38535be929ca2cc7d14fc3e0a409304071f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Wed, 14 Dec 2022 13:46:13 +0100 Subject: [PATCH] LibManual: Allow overriding a Node's path calculation This is necessary for subclassing SectionNode, but generally allows more code to rely on path() virtual dispatch always finding the correct path regardless of the static type. --- Userland/Libraries/LibManual/Node.h | 1 + Userland/Libraries/LibManual/PageNode.h | 2 +- Userland/Libraries/LibManual/SectionNode.h | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibManual/Node.h b/Userland/Libraries/LibManual/Node.h index cf72a984a2..5fcd241121 100644 --- a/Userland/Libraries/LibManual/Node.h +++ b/Userland/Libraries/LibManual/Node.h @@ -25,6 +25,7 @@ public: virtual ErrorOr name() const = 0; virtual bool is_page() const { return false; } virtual bool is_open() const { return false; } + virtual ErrorOr path() const = 0; // Backend for the command-line argument format that Help and man accept. Handles: // [/path/to/documentation.md] (no second argument) diff --git a/Userland/Libraries/LibManual/PageNode.h b/Userland/Libraries/LibManual/PageNode.h index e505e228a0..3dc33d9a67 100644 --- a/Userland/Libraries/LibManual/PageNode.h +++ b/Userland/Libraries/LibManual/PageNode.h @@ -28,7 +28,7 @@ public: virtual ErrorOr name() const override { return m_page; }; virtual bool is_page() const override { return true; } - ErrorOr path() const; + virtual ErrorOr path() const override; static ErrorOr> help_index_page(); diff --git a/Userland/Libraries/LibManual/SectionNode.h b/Userland/Libraries/LibManual/SectionNode.h index 14ddd5bbda..d0d4476eaa 100644 --- a/Userland/Libraries/LibManual/SectionNode.h +++ b/Userland/Libraries/LibManual/SectionNode.h @@ -32,7 +32,7 @@ public: virtual Node const* parent() const override { return nullptr; } virtual ErrorOr name() const override; String const& section_name() const { return m_section; } - ErrorOr path() const; + virtual ErrorOr path() const override; virtual bool is_open() const override { return m_open; } void set_open(bool open); @@ -40,6 +40,7 @@ public: static ErrorOr> try_create_from_number(StringView section_number); protected: + // In this class, the section is a number, but in lower sections it might be the same as the name. String m_section; String m_name;