summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibManual
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-12-14 17:53:41 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2023-01-02 06:15:13 -0700
commit201c9d7c775da90763f562e0ed3d414a7d3eaf9e (patch)
tree1a9e81fa698471036bdbfb4d48fd05a2637b4f25 /Userland/Libraries/LibManual
parent3e67f14e584f9c700d8ee04b757286edf80b0c56 (diff)
downloadserenity-201c9d7c775da90763f562e0ed3d414a7d3eaf9e.zip
Help+LibManual: Open sibling page for subsections
Clicking on a subsection now displays the sibling page, which is intended to be the main page for that section.
Diffstat (limited to 'Userland/Libraries/LibManual')
-rw-r--r--Userland/Libraries/LibManual/Node.h1
-rw-r--r--Userland/Libraries/LibManual/PageNode.h1
-rw-r--r--Userland/Libraries/LibManual/SectionNode.h1
-rw-r--r--Userland/Libraries/LibManual/SubsectionNode.cpp20
-rw-r--r--Userland/Libraries/LibManual/SubsectionNode.h1
5 files changed, 24 insertions, 0 deletions
diff --git a/Userland/Libraries/LibManual/Node.h b/Userland/Libraries/LibManual/Node.h
index aceca11084..9e1c2aeda1 100644
--- a/Userland/Libraries/LibManual/Node.h
+++ b/Userland/Libraries/LibManual/Node.h
@@ -26,6 +26,7 @@ public:
virtual bool is_page() const { return false; }
virtual bool is_open() const { return false; }
virtual ErrorOr<String> path() const = 0;
+ virtual PageNode const* document() 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 3dc33d9a67..7c48a7dc8d 100644
--- a/Userland/Libraries/LibManual/PageNode.h
+++ b/Userland/Libraries/LibManual/PageNode.h
@@ -27,6 +27,7 @@ public:
virtual Node const* parent() const override;
virtual ErrorOr<String> name() const override { return m_page; };
virtual bool is_page() const override { return true; }
+ virtual PageNode const* document() const override { return this; };
virtual ErrorOr<String> path() const override;
diff --git a/Userland/Libraries/LibManual/SectionNode.h b/Userland/Libraries/LibManual/SectionNode.h
index d0d4476eaa..4e228799f9 100644
--- a/Userland/Libraries/LibManual/SectionNode.h
+++ b/Userland/Libraries/LibManual/SectionNode.h
@@ -33,6 +33,7 @@ public:
virtual ErrorOr<String> name() const override;
String const& section_name() const { return m_section; }
virtual ErrorOr<String> path() const override;
+ virtual PageNode const* document() const override { return nullptr; }
virtual bool is_open() const override { return m_open; }
void set_open(bool open);
diff --git a/Userland/Libraries/LibManual/SubsectionNode.cpp b/Userland/Libraries/LibManual/SubsectionNode.cpp
index 1d166b9282..18f81d54fe 100644
--- a/Userland/Libraries/LibManual/SubsectionNode.cpp
+++ b/Userland/Libraries/LibManual/SubsectionNode.cpp
@@ -5,6 +5,8 @@
*/
#include "SubsectionNode.h"
+#include "PageNode.h"
+#include <AK/TypeCasts.h>
namespace Manual {
@@ -16,6 +18,24 @@ SubsectionNode::SubsectionNode(NonnullRefPtr<SectionNode> parent, StringView nam
Node const* SubsectionNode::parent() const { return m_parent; }
+PageNode const* SubsectionNode::document() const
+{
+ auto maybe_siblings = parent()->children();
+ if (maybe_siblings.is_error())
+ return nullptr;
+ auto siblings = maybe_siblings.release_value();
+ for (auto const& sibling : siblings) {
+ if (&*sibling == this)
+ continue;
+ auto sibling_name = sibling->name();
+ if (sibling_name.is_error())
+ continue;
+ if (sibling_name.value() == m_name && is<PageNode>(*sibling))
+ return static_cast<PageNode*>(&*sibling);
+ }
+ return nullptr;
+}
+
ErrorOr<String> SubsectionNode::name() const { return m_name; }
ErrorOr<String> SubsectionNode::path() const
diff --git a/Userland/Libraries/LibManual/SubsectionNode.h b/Userland/Libraries/LibManual/SubsectionNode.h
index c2f8461bd8..fec53604dc 100644
--- a/Userland/Libraries/LibManual/SubsectionNode.h
+++ b/Userland/Libraries/LibManual/SubsectionNode.h
@@ -19,6 +19,7 @@ public:
virtual Node const* parent() const override;
virtual ErrorOr<String> path() const override;
virtual ErrorOr<String> name() const override;
+ virtual PageNode const* document() const override;
protected:
NonnullRefPtr<SectionNode> m_parent;