mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
GTreeView: Make double-clicking toggle openable items
This commit is contained in:
parent
2f5b2685af
commit
64b1e9deec
Notes:
sideshowbarker
2024-07-19 12:13:17 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/64b1e9deec8
2 changed files with 19 additions and 0 deletions
|
@ -77,6 +77,24 @@ void GTreeView::mousedown_event(GMouseEvent& event)
|
|||
toggle_index(index);
|
||||
}
|
||||
|
||||
void GTreeView::doubleclick_event(GMouseEvent& event)
|
||||
{
|
||||
if (!model())
|
||||
return;
|
||||
auto& model = *this->model();
|
||||
auto adjusted_position = event.position().translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness());
|
||||
bool is_toggle;
|
||||
auto index = index_at_content_position(adjusted_position, is_toggle);
|
||||
if (!index.is_valid())
|
||||
return;
|
||||
|
||||
if (selection().first() != index)
|
||||
selection().set(index);
|
||||
|
||||
if (model.row_count(index))
|
||||
toggle_index(index);
|
||||
}
|
||||
|
||||
void GTreeView::toggle_index(const GModelIndex& index)
|
||||
{
|
||||
ASSERT(model()->row_count(index));
|
||||
|
|
|
@ -13,6 +13,7 @@ public:
|
|||
protected:
|
||||
virtual void paint_event(GPaintEvent&) override;
|
||||
virtual void mousedown_event(GMouseEvent&) override;
|
||||
virtual void doubleclick_event(GMouseEvent&) override;
|
||||
virtual void keydown_event(GKeyEvent&) override;
|
||||
virtual void did_update_selection() override;
|
||||
virtual void did_update_model() override;
|
||||
|
|
Loading…
Reference in a new issue