mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
parent
055e955a1c
commit
d1a9afa7cd
3 changed files with 27 additions and 0 deletions
|
@ -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"));
|
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
|
String ManualModel::page_path(const GUI::ModelIndex& index) const
|
||||||
{
|
{
|
||||||
if (!index.is_valid())
|
if (!index.is_valid())
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
|
#include <AK/Optional.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibGUI/Model.h>
|
#include <LibGUI/Model.h>
|
||||||
|
|
||||||
|
@ -39,6 +40,8 @@ public:
|
||||||
|
|
||||||
virtual ~ManualModel() override {};
|
virtual ~ManualModel() override {};
|
||||||
|
|
||||||
|
Optional<GUI::ModelIndex> index_from_path(const StringView&) const;
|
||||||
|
|
||||||
String page_path(const GUI::ModelIndex&) const;
|
String page_path(const GUI::ModelIndex&) const;
|
||||||
String page_and_section(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* dir_path = dirname(current_path);
|
||||||
char* path = realpath(String::format("%s/%s", dir_path, href.characters()).characters(), nullptr);
|
char* path = realpath(String::format("%s/%s", dir_path, href.characters()).characters(), nullptr);
|
||||||
free(current_path);
|
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);
|
history.push(path);
|
||||||
update_actions();
|
update_actions();
|
||||||
open_page(path);
|
open_page(path);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue