blob: c11292638da736661cca9ebfeab1d513e677f092 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/*
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ManualSectionNode.h"
#include "ManualPageNode.h"
#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <AK/String.h>
#include <LibCore/DirIterator.h>
String ManualSectionNode::path() const
{
return String::formatted("/usr/share/man/man{}", m_section);
}
void ManualSectionNode::reify_if_needed() const
{
if (m_reified)
return;
m_reified = true;
Core::DirIterator dir_iter { path(), Core::DirIterator::Flags::SkipDots };
Vector<String> page_names;
while (dir_iter.has_next()) {
LexicalPath lexical_path(dir_iter.next_path());
if (lexical_path.extension() != "md")
continue;
page_names.append(lexical_path.title());
}
quick_sort(page_names);
for (auto& page_name : page_names)
m_children.append(make<ManualPageNode>(*this, move(page_name)));
}
void ManualSectionNode::set_open(bool open)
{
if (m_open == open)
return;
m_open = open;
}
|