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.
This commit is contained in:
kleines Filmröllchen 2022-12-14 13:46:13 +01:00 committed by Andrew Kaster
parent aa5e574872
commit 44e4a38535
3 changed files with 4 additions and 2 deletions

View file

@ -25,6 +25,7 @@ public:
virtual ErrorOr<String> name() const = 0;
virtual bool is_page() const { return false; }
virtual bool is_open() const { return false; }
virtual ErrorOr<String> path() const = 0;
// Backend for the command-line argument format that Help and man accept. Handles:
// [/path/to/documentation.md] (no second argument)

View file

@ -28,7 +28,7 @@ public:
virtual ErrorOr<String> name() const override { return m_page; };
virtual bool is_page() const override { return true; }
ErrorOr<String> path() const;
virtual ErrorOr<String> path() const override;
static ErrorOr<NonnullRefPtr<PageNode>> help_index_page();

View file

@ -32,7 +32,7 @@ public:
virtual Node const* parent() const override { return nullptr; }
virtual ErrorOr<String> name() const override;
String const& section_name() const { return m_section; }
ErrorOr<String> path() const;
virtual ErrorOr<String> path() const override;
virtual bool is_open() const override { return m_open; }
void set_open(bool open);
@ -40,6 +40,7 @@ public:
static ErrorOr<NonnullRefPtr<SectionNode>> 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;