mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 05:07:35 +00:00
LibManual: Refactor SectionNode in preparation for subsections
- Calculate the full name on demand - Make section and name protected - Reorder some members logically - Change the name getter to be fallible, as some implementors need to allocate
This commit is contained in:
parent
f502e24bd7
commit
4625f7aab5
6 changed files with 23 additions and 10 deletions
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
virtual NonnullRefPtrVector<Node>& children() const = 0;
|
||||
virtual Node const* parent() const = 0;
|
||||
virtual String name() const = 0;
|
||||
virtual ErrorOr<String> name() const = 0;
|
||||
virtual bool is_page() const { return false; }
|
||||
virtual bool is_open() const { return false; }
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
virtual NonnullRefPtrVector<Node>& children() const override;
|
||||
virtual Node const* parent() const override;
|
||||
virtual String name() const override { return m_page; };
|
||||
virtual ErrorOr<String> name() const override { return m_page; };
|
||||
virtual bool is_page() const override { return true; }
|
||||
|
||||
ErrorOr<String> path() const;
|
||||
|
|
|
@ -17,6 +17,11 @@ ErrorOr<String> SectionNode::path() const
|
|||
return String::formatted("/usr/share/man/man{}", m_section);
|
||||
}
|
||||
|
||||
ErrorOr<String> SectionNode::name() const
|
||||
{
|
||||
return String::formatted("{}. {}", m_section, m_name);
|
||||
}
|
||||
|
||||
ErrorOr<void> SectionNode::reify_if_needed() const
|
||||
{
|
||||
if (m_reified)
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
|
||||
SectionNode(StringView section, StringView name)
|
||||
: m_section(MUST(String::from_utf8(section)))
|
||||
, m_full_name(MUST(String::formatted("{}. {}", section, name)))
|
||||
, m_name(MUST(String::from_utf8(name)))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -30,18 +30,20 @@ public:
|
|||
}
|
||||
|
||||
virtual Node const* parent() const override { return nullptr; }
|
||||
virtual String name() const override { return m_full_name; }
|
||||
virtual ErrorOr<String> name() const override;
|
||||
String const& section_name() const { return m_section; }
|
||||
ErrorOr<String> path() const;
|
||||
|
||||
virtual bool is_open() const override { return m_open; }
|
||||
void set_open(bool open);
|
||||
|
||||
String const& section_name() const { return m_section; }
|
||||
ErrorOr<String> path() const;
|
||||
protected:
|
||||
String m_section;
|
||||
String m_name;
|
||||
|
||||
private:
|
||||
ErrorOr<void> reify_if_needed() const;
|
||||
|
||||
String m_section;
|
||||
String m_full_name;
|
||||
mutable NonnullRefPtrVector<Node> m_children;
|
||||
mutable bool m_reified { false };
|
||||
bool m_open { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue