diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-07 20:15:33 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-07 20:15:33 +0200 |
commit | 56c360591cad988aba8905e3291d7d9e26afca75 (patch) | |
tree | c1a3dbefdc2ef49647500588c95830f4164a5248 /Libraries/LibGUI/GTreeView.cpp | |
parent | f8c0168adc501f7d576aefa5e01f1c1b64123ba1 (diff) | |
download | serenity-56c360591cad988aba8905e3291d7d9e26afca75.zip |
GTreeView: Switch to using GModelSelection
We don't support multi-select in GTreeView yet. Some day though :^)
Diffstat (limited to 'Libraries/LibGUI/GTreeView.cpp')
-rw-r--r-- | Libraries/LibGUI/GTreeView.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/Libraries/LibGUI/GTreeView.cpp b/Libraries/LibGUI/GTreeView.cpp index eedb672656..d20ae6d4ea 100644 --- a/Libraries/LibGUI/GTreeView.cpp +++ b/Libraries/LibGUI/GTreeView.cpp @@ -69,9 +69,8 @@ void GTreeView::mousedown_event(GMouseEvent& event) if (!index.is_valid()) return; - if (model.selected_index() != index) { - model.set_selected_index(index); - update(); + if (selection().first() != index) { + selection().set(index); } if (is_toggle && model.row_count(index)) @@ -170,7 +169,7 @@ void GTreeView::paint_event(GPaintEvent& event) icon_rect.right() + 1 + icon_spacing(), rect.y(), rect.width() - icon_size() - icon_spacing(), rect.height() }; - if (index == model.selected_index()) { + if (selection().contains(index)) { background_color = is_focused() ? Color::from_rgb(0x84351a) : Color::from_rgb(0x606060); text_color = Color::from_rgb(0xffffff); painter.fill_rect(text_rect, background_color); @@ -232,8 +231,7 @@ void GTreeView::did_update_model() void GTreeView::did_update_selection() { ASSERT(model()); - auto& model = *this->model(); - auto index = model.selected_index(); + auto index = selection().first(); if (!index.is_valid()) return; bool opened_any = false; @@ -267,7 +265,7 @@ void GTreeView::keydown_event(GKeyEvent& event) { if (!model()) return; - auto cursor_index = model()->selected_index(); + auto cursor_index = selection().first(); if (event.key() == KeyCode::Key_Space) { if (model()->row_count(cursor_index)) @@ -287,7 +285,7 @@ void GTreeView::keydown_event(GKeyEvent& event) return IterationDecision::Continue; }); if (found_index.is_valid()) { - model()->set_selected_index(found_index); + selection().set(found_index); update(); } return; @@ -304,7 +302,7 @@ void GTreeView::keydown_event(GKeyEvent& event) return IterationDecision::Continue; }); if (found_index.is_valid()) - model()->set_selected_index(found_index); + selection().set(found_index); return; } } |