mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +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
|
@ -307,6 +307,7 @@ void MainWidget::open_page(Optional<String> const& path)
|
|||
m_web_view->load_empty_document();
|
||||
return;
|
||||
}
|
||||
dbgln("open page: {}", path.value());
|
||||
open_url(URL::create_with_url_or_path(path.value().to_deprecated_string()));
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,10 @@ Optional<String> ManualModel::page_name(const GUI::ModelIndex& index) const
|
|||
if (!node->is_page())
|
||||
return {};
|
||||
auto* page = static_cast<Manual::PageNode const*>(node);
|
||||
return page->name();
|
||||
auto path = page->name();
|
||||
if (path.is_error())
|
||||
return {};
|
||||
return path.release_value();
|
||||
}
|
||||
|
||||
Optional<String> ManualModel::page_path(const GUI::ModelIndex& index) const
|
||||
|
@ -159,7 +162,9 @@ GUI::Variant ManualModel::data(const GUI::ModelIndex& index, GUI::ModelRole role
|
|||
return DeprecatedString(page.release_value());
|
||||
return {};
|
||||
case GUI::ModelRole::Display:
|
||||
return node->name();
|
||||
if (auto name = node->name(); !name.is_error())
|
||||
return name.release_value();
|
||||
return {};
|
||||
case GUI::ModelRole::Icon:
|
||||
if (node->is_page())
|
||||
return m_page_icon;
|
||||
|
|
|
@ -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…
Reference in a new issue