mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 11:39:44 +03:00
parent
055e955a1c
commit
d1a9afa7cd
Notes:
sideshowbarker
2024-07-19 06:57:20 +09:00
Author: https://github.com/Dexesttp Commit: https://github.com/SerenityOS/serenity/commit/d1a9afa7cd9 Pull-request: https://github.com/SerenityOS/serenity/pull/2119
@ -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())
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user