mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 11:39:44 +03:00
Help: Make section books open and close when toggled
Much more satisfying!
This commit is contained in:
parent
cbf3c2caeb
commit
d86dbfe9e8
Notes:
sideshowbarker
2024-07-19 05:02:42 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/d86dbfe9e8c Pull-request: https://github.com/SerenityOS/serenity/pull/2726
@ -42,7 +42,7 @@ static ManualSectionNode s_sections[] = {
|
||||
|
||||
ManualModel::ManualModel()
|
||||
{
|
||||
// FIXME: need some help from the icon fairy ^)
|
||||
m_section_open_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/book-open.png"));
|
||||
m_section_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/book.png"));
|
||||
m_page_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png"));
|
||||
}
|
||||
@ -142,12 +142,20 @@ GUI::Variant ManualModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
case Role::Icon:
|
||||
if (node->is_page())
|
||||
return m_page_icon;
|
||||
if (node->is_open())
|
||||
return m_section_open_icon;
|
||||
return m_section_icon;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void ManualModel::update_section_node_on_toggle(const GUI::ModelIndex& index, const bool open)
|
||||
{
|
||||
auto* node = static_cast<ManualSectionNode*>(index.internal_data());
|
||||
node->set_open(open);
|
||||
}
|
||||
|
||||
void ManualModel::update()
|
||||
{
|
||||
did_update();
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
String page_path(const GUI::ModelIndex&) const;
|
||||
String page_and_section(const GUI::ModelIndex&) const;
|
||||
|
||||
void update_section_node_on_toggle(const GUI::ModelIndex&, const bool);
|
||||
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
|
||||
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
|
||||
@ -55,6 +56,7 @@ public:
|
||||
private:
|
||||
ManualModel();
|
||||
|
||||
GUI::Icon m_section_open_icon;
|
||||
GUI::Icon m_section_icon;
|
||||
GUI::Icon m_page_icon;
|
||||
};
|
||||
|
@ -37,4 +37,5 @@ public:
|
||||
virtual const ManualNode* parent() const = 0;
|
||||
virtual String name() const = 0;
|
||||
virtual bool is_page() const { return false; }
|
||||
virtual bool is_open() const { return false; }
|
||||
};
|
||||
|
@ -57,3 +57,10 @@ void ManualSectionNode::reify_if_needed() const
|
||||
for (auto& page_name : page_names)
|
||||
m_children.append(make<ManualPageNode>(*this, move(page_name)));
|
||||
}
|
||||
|
||||
void ManualSectionNode::set_open(bool open)
|
||||
{
|
||||
if (m_open == open)
|
||||
return;
|
||||
m_open = open;
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
|
||||
virtual const ManualNode* parent() const override { return nullptr; }
|
||||
virtual String name() const override { return m_full_name; }
|
||||
virtual bool is_open() const override { return m_open; }
|
||||
void set_open(bool open);
|
||||
|
||||
const String& section_name() const { return m_section; }
|
||||
String path() const;
|
||||
@ -57,4 +59,5 @@ private:
|
||||
String m_full_name;
|
||||
mutable NonnullOwnPtrVector<ManualNode> m_children;
|
||||
mutable bool m_reified { false };
|
||||
bool m_open { false };
|
||||
};
|
||||
|
@ -147,6 +147,7 @@ int main(int argc, char* argv[])
|
||||
String path = model->page_path(tree_view.selection().first());
|
||||
if (path.is_null()) {
|
||||
page_view.set_document(nullptr);
|
||||
window->set_title("Help");
|
||||
return;
|
||||
}
|
||||
history.push(path);
|
||||
@ -154,6 +155,10 @@ int main(int argc, char* argv[])
|
||||
open_page(path);
|
||||
};
|
||||
|
||||
tree_view.on_toggle = [&](const GUI::ModelIndex& index, const bool open) {
|
||||
model->update_section_node_on_toggle(index, open);
|
||||
};
|
||||
|
||||
page_view.on_link_click = [&](auto& url, auto&, unsigned) {
|
||||
char* current_path = strdup(history.current().characters());
|
||||
char* path = realpath(url.path().characters(), nullptr);
|
||||
|
Loading…
Reference in New Issue
Block a user