ManualSectionNode.cpp 1.1 KB

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