1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:37:35 +00:00

Help+LibManual: Move non-UI-specific manual handling to LibManual

This is a first step in deduplicating code within and across Help and
man.

Because LibManual also doesn't contain any DeprecatedString, some
adjustments to Help's string handling is included, just to interoperate
with LibManual better. Further work in this area mostly requires String
APIs in LibGUI.
This commit is contained in:
kleines Filmröllchen 2022-07-13 00:20:27 +02:00 committed by Linus Groh
parent 78353ec184
commit ad6a55e1f0
18 changed files with 339 additions and 265 deletions

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/String.h>
#include <LibManual/Node.h>
namespace Manual {
class SectionNode : public Node {
public:
virtual ~SectionNode() override = default;
SectionNode(StringView section, StringView name)
: m_section(MUST(String::from_utf8(section)))
, m_full_name(MUST(String::formatted("{}. {}", section, name)))
{
}
virtual NonnullRefPtrVector<Node>& children() const override
{
MUST(reify_if_needed());
return m_children;
}
virtual Node const* parent() const override { return nullptr; }
virtual String name() const override { return m_full_name; }
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;
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 };
};
constexpr size_t number_of_sections = 8;
extern Array<NonnullRefPtr<SectionNode>, number_of_sections> const sections;
constexpr Array<StringView, number_of_sections> const section_numbers = {
"1"sv,
"2"sv,
"3"sv,
"4"sv,
"5"sv,
"6"sv,
"7"sv,
"8"sv,
};
}