Help: Clicking on link changes the treeview selection

Fixes #1259
This commit is contained in:
DexesTTP 2020-05-05 13:58:31 +02:00 committed by Andreas Kling
parent 055e955a1c
commit d1a9afa7cd
Notes: sideshowbarker 2024-07-19 06:57:20 +09:00
3 changed files with 27 additions and 0 deletions

View File

@ -47,6 +47,24 @@ ManualModel::ManualModel()
m_page_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png"));
}
Optional<GUI::ModelIndex> ManualModel::index_from_path(const StringView& path) const
{
for (int section = 0; section < row_count(); ++section) {
auto parent_index = index(section, 0);
for (int row = 0; row < row_count(parent_index); ++row) {
auto child_index = index(row, 0, parent_index);
auto* node = static_cast<const ManualNode*>(child_index.internal_data());
if (!node->is_page())
continue;
auto* page = static_cast<const ManualPageNode*>(node);
if (page->path() != path)
continue;
return child_index;
}
}
return {};
}
String ManualModel::page_path(const GUI::ModelIndex& index) const
{
if (!index.is_valid())

View File

@ -27,6 +27,7 @@
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <LibGUI/Model.h>
@ -39,6 +40,8 @@ public:
virtual ~ManualModel() override {};
Optional<GUI::ModelIndex> index_from_path(const StringView&) const;
String page_path(const GUI::ModelIndex&) const;
String page_and_section(const GUI::ModelIndex&) const;

View File

@ -156,6 +156,12 @@ int main(int argc, char* argv[])
char* dir_path = dirname(current_path);
char* path = realpath(String::format("%s/%s", dir_path, href.characters()).characters(), nullptr);
free(current_path);
auto tree_view_index = model->index_from_path(path);
if (tree_view_index.has_value()) {
dbg() << "Found path _" << path << "_ in model at index " << tree_view_index.value();
tree_view.selection().set(tree_view_index.value());
return;
}
history.push(path);
update_actions();
open_page(path);