mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:52:43 +00:00 
			
		
		
		
	LibGUI: Add GAbstractView::activate_selected()
This is a nice little utility to activate all the selected items, which is what you usually want to do.
This commit is contained in:
		
							parent
							
								
									caa08938e5
								
							
						
					
					
						commit
						0f18a16e2c
					
				
					 5 changed files with 21 additions and 24 deletions
				
			
		|  | @ -383,9 +383,7 @@ void GAbstractColumnView::keydown_event(GKeyEvent& event) | ||||||
|         return; |         return; | ||||||
|     auto& model = *this->model(); |     auto& model = *this->model(); | ||||||
|     if (event.key() == KeyCode::Key_Return) { |     if (event.key() == KeyCode::Key_Return) { | ||||||
|         selection().for_each_index([this](auto& index) { |         activate_selected(); | ||||||
|             activate(index); |  | ||||||
|         }); |  | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     if (event.key() == KeyCode::Key_Up) { |     if (event.key() == KeyCode::Key_Up) { | ||||||
|  | @ -457,13 +455,10 @@ void GAbstractColumnView::doubleclick_event(GMouseEvent& event) | ||||||
|         if (event.y() < header_height()) |         if (event.y() < header_height()) | ||||||
|             return; |             return; | ||||||
|         if (!selection().is_empty()) { |         if (!selection().is_empty()) { | ||||||
|             if (is_editable()) { |             if (is_editable()) | ||||||
|                 begin_editing(selection().first()); |                 begin_editing(selection().first()); | ||||||
|             } else { |             else | ||||||
|                 selection().for_each_index([this](auto& index) { |                 activate_selected(); | ||||||
|                     activate(index); |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -113,6 +113,16 @@ void GAbstractView::activate(const GModelIndex& index) | ||||||
|         on_activation(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<GModelSelection>) | void GAbstractView::notify_selection_changed(Badge<GModelSelection>) | ||||||
| { | { | ||||||
|     did_update_selection(); |     did_update_selection(); | ||||||
|  |  | ||||||
|  | @ -51,6 +51,7 @@ protected: | ||||||
| 
 | 
 | ||||||
|     virtual void did_scroll() override; |     virtual void did_scroll() override; | ||||||
|     void activate(const GModelIndex&); |     void activate(const GModelIndex&); | ||||||
|  |     void activate_selected(); | ||||||
|     void update_edit_widget_position(); |     void update_edit_widget_position(); | ||||||
| 
 | 
 | ||||||
|     bool m_editable { false }; |     bool m_editable { false }; | ||||||
|  |  | ||||||
|  | @ -258,9 +258,7 @@ void GItemView::doubleclick_event(GMouseEvent& event) | ||||||
|         return; |         return; | ||||||
|     if (event.button() == GMouseButton::Left) { |     if (event.button() == GMouseButton::Left) { | ||||||
|         mousedown_event(event); |         mousedown_event(event); | ||||||
|         selection().for_each_index([this](auto& index) { |         activate_selected(); | ||||||
|             activate(index); |  | ||||||
|         }); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -352,9 +350,7 @@ void GItemView::keydown_event(GKeyEvent& event) | ||||||
| 
 | 
 | ||||||
|     auto& model = *this->model(); |     auto& model = *this->model(); | ||||||
|     if (event.key() == KeyCode::Key_Return) { |     if (event.key() == KeyCode::Key_Return) { | ||||||
|         selection().for_each_index([this](auto& index) { |         activate_selected(); | ||||||
|             activate(index); |  | ||||||
|         }); |  | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     if (event.key() == KeyCode::Key_Home) { |     if (event.key() == KeyCode::Key_Home) { | ||||||
|  |  | ||||||
|  | @ -161,9 +161,7 @@ void GListView::keydown_event(GKeyEvent& event) | ||||||
|         return; |         return; | ||||||
|     auto& model = *this->model(); |     auto& model = *this->model(); | ||||||
|     if (event.key() == KeyCode::Key_Return) { |     if (event.key() == KeyCode::Key_Return) { | ||||||
|         selection().for_each_index([this](auto& index) { |         activate_selected(); | ||||||
|             activate(index); |  | ||||||
|         }); |  | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     if (event.key() == KeyCode::Key_Up) { |     if (event.key() == KeyCode::Key_Up) { | ||||||
|  | @ -233,13 +231,10 @@ void GListView::doubleclick_event(GMouseEvent& event) | ||||||
|         return; |         return; | ||||||
|     if (event.button() == GMouseButton::Left) { |     if (event.button() == GMouseButton::Left) { | ||||||
|         if (!selection().is_empty()) { |         if (!selection().is_empty()) { | ||||||
|             if (is_editable()) { |             if (is_editable()) | ||||||
|                 begin_editing(selection().first()); |                 begin_editing(selection().first()); | ||||||
|             } else { |             else | ||||||
|                 selection().for_each_index([this](auto& index) { |                 activate_selected(); | ||||||
|                     activate(index); |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sergey Bugaev
						Sergey Bugaev