diff --git a/Libraries/LibGUI/GAbstractColumnView.cpp b/Libraries/LibGUI/GAbstractColumnView.cpp index c334400d70a..31b4f4a6786 100644 --- a/Libraries/LibGUI/GAbstractColumnView.cpp +++ b/Libraries/LibGUI/GAbstractColumnView.cpp @@ -383,9 +383,7 @@ void GAbstractColumnView::keydown_event(GKeyEvent& event) return; auto& model = *this->model(); if (event.key() == KeyCode::Key_Return) { - selection().for_each_index([this](auto& index) { - activate(index); - }); + activate_selected(); return; } if (event.key() == KeyCode::Key_Up) { @@ -457,13 +455,10 @@ void GAbstractColumnView::doubleclick_event(GMouseEvent& event) if (event.y() < header_height()) return; if (!selection().is_empty()) { - if (is_editable()) { + if (is_editable()) begin_editing(selection().first()); - } else { - selection().for_each_index([this](auto& index) { - activate(index); - }); - } + else + activate_selected(); } } } diff --git a/Libraries/LibGUI/GAbstractView.cpp b/Libraries/LibGUI/GAbstractView.cpp index dc2b1edd274..41c9f7ca0ed 100644 --- a/Libraries/LibGUI/GAbstractView.cpp +++ b/Libraries/LibGUI/GAbstractView.cpp @@ -113,6 +113,16 @@ void GAbstractView::activate(const GModelIndex& index) on_activation(index); } +void GAbstractView::activate_selected() +{ + if (!on_activation) + return; + + selection().for_each_index([this](auto& index) { + on_activation(index); + }); +} + void GAbstractView::notify_selection_changed(Badge) { did_update_selection(); diff --git a/Libraries/LibGUI/GAbstractView.h b/Libraries/LibGUI/GAbstractView.h index 2f8feb6ee08..e3c9edf33fe 100644 --- a/Libraries/LibGUI/GAbstractView.h +++ b/Libraries/LibGUI/GAbstractView.h @@ -51,6 +51,7 @@ protected: virtual void did_scroll() override; void activate(const GModelIndex&); + void activate_selected(); void update_edit_widget_position(); bool m_editable { false }; diff --git a/Libraries/LibGUI/GItemView.cpp b/Libraries/LibGUI/GItemView.cpp index 8f025c06099..a3be11df318 100644 --- a/Libraries/LibGUI/GItemView.cpp +++ b/Libraries/LibGUI/GItemView.cpp @@ -258,9 +258,7 @@ void GItemView::doubleclick_event(GMouseEvent& event) return; if (event.button() == GMouseButton::Left) { mousedown_event(event); - selection().for_each_index([this](auto& index) { - activate(index); - }); + activate_selected(); } } @@ -352,9 +350,7 @@ void GItemView::keydown_event(GKeyEvent& event) auto& model = *this->model(); if (event.key() == KeyCode::Key_Return) { - selection().for_each_index([this](auto& index) { - activate(index); - }); + activate_selected(); return; } if (event.key() == KeyCode::Key_Home) { diff --git a/Libraries/LibGUI/GListView.cpp b/Libraries/LibGUI/GListView.cpp index 2e7785313cb..53ef4541c0b 100644 --- a/Libraries/LibGUI/GListView.cpp +++ b/Libraries/LibGUI/GListView.cpp @@ -161,9 +161,7 @@ void GListView::keydown_event(GKeyEvent& event) return; auto& model = *this->model(); if (event.key() == KeyCode::Key_Return) { - selection().for_each_index([this](auto& index) { - activate(index); - }); + activate_selected(); return; } if (event.key() == KeyCode::Key_Up) { @@ -233,13 +231,10 @@ void GListView::doubleclick_event(GMouseEvent& event) return; if (event.button() == GMouseButton::Left) { if (!selection().is_empty()) { - if (is_editable()) { + if (is_editable()) begin_editing(selection().first()); - } else { - selection().for_each_index([this](auto& index) { - activate(index); - }); - } + else + activate_selected(); } } }