mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 04:55:09 +00:00
Help: Add a search mode
This closes #2685, and brings some much needed nostalgia :^)
This commit is contained in:
parent
6131417904
commit
21094b4725
3 changed files with 104 additions and 16 deletions
|
@ -28,6 +28,9 @@
|
|||
#include "ManualNode.h"
|
||||
#include "ManualPageNode.h"
|
||||
#include "ManualSectionNode.h"
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibGUI/FilteringProxyModel.h>
|
||||
|
||||
static ManualSectionNode s_sections[] = {
|
||||
{ "1", "Command-line programs" },
|
||||
|
@ -76,6 +79,25 @@ String ManualModel::page_path(const GUI::ModelIndex& index) const
|
|||
return page->path();
|
||||
}
|
||||
|
||||
Result<StringView, int> ManualModel::page_view(const String& path) const
|
||||
{
|
||||
if (path.is_empty())
|
||||
return StringView {};
|
||||
|
||||
auto mapped_file = m_mapped_files.get(path);
|
||||
if (mapped_file.has_value())
|
||||
return StringView { (const char*)mapped_file.value()->data(), mapped_file.value()->size() };
|
||||
|
||||
auto map = make<MappedFile>(path);
|
||||
if (!map->is_valid())
|
||||
return map->errno_if_invalid();
|
||||
|
||||
StringView view { (const char*)map->data(), map->size() };
|
||||
m_mapped_files.set(path, move(map));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
String ManualModel::page_and_section(const GUI::ModelIndex& index) const
|
||||
{
|
||||
if (!index.is_valid())
|
||||
|
@ -137,6 +159,10 @@ GUI::Variant ManualModel::data(const GUI::ModelIndex& index, Role role) const
|
|||
{
|
||||
auto* node = static_cast<const ManualNode*>(index.internal_data());
|
||||
switch (role) {
|
||||
case Role::Search:
|
||||
if (!node->is_page())
|
||||
return {};
|
||||
return String(page_view(page_path(index)).value());
|
||||
case Role::Display:
|
||||
return node->name();
|
||||
case Role::Icon:
|
||||
|
@ -156,6 +182,15 @@ void ManualModel::update_section_node_on_toggle(const GUI::ModelIndex& index, co
|
|||
node->set_open(open);
|
||||
}
|
||||
|
||||
TriState ManualModel::data_matches(const GUI::ModelIndex& index, GUI::Variant term) const
|
||||
{
|
||||
auto view_result = page_view(page_path(index));
|
||||
if (view_result.is_error() || view_result.value().is_empty())
|
||||
return TriState::False;
|
||||
|
||||
return view_result.value().contains(term.as_string()) ? TriState::True : TriState::False;
|
||||
}
|
||||
|
||||
void ManualModel::update()
|
||||
{
|
||||
did_update();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue