mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:12:43 +00:00 
			
		
		
		
	FileManager: Show info about currently selected items in statusbar
When there's a non-zero number of selected items, we now show the number in the statusbar, along with the total selected file size. :^) Fixes #271.
This commit is contained in:
		
							parent
							
								
									13ca1ee8dc
								
							
						
					
					
						commit
						d86fb8033e
					
				
					 3 changed files with 42 additions and 16 deletions
				
			
		|  | @ -69,12 +69,7 @@ DirectoryView::DirectoryView(GWidget* parent) | |||
|     m_item_view->set_model_column(GDirectoryModel::Column::Name); | ||||
| 
 | ||||
|     m_table_view->model()->on_update = [this] { | ||||
|         set_status_message(String::format("%d item%s (%u byte%s)", | ||||
|             model().row_count(), | ||||
|             model().row_count() != 1 ? "s" : "", | ||||
|             model().bytes_in_files(), | ||||
|             model().bytes_in_files() != 1 ? "s" : "")); | ||||
| 
 | ||||
|         update_statusbar(); | ||||
|         if (on_path_change) | ||||
|             on_path_change(model().path()); | ||||
|     }; | ||||
|  | @ -92,13 +87,15 @@ DirectoryView::DirectoryView(GWidget* parent) | |||
|         handle_activation(filter_model.map_to_target(index)); | ||||
|     }; | ||||
| 
 | ||||
|     m_table_view->on_selection = [this](const GModelIndex&) { | ||||
|         if (on_selection) | ||||
|             on_selection(*m_table_view); | ||||
|     m_table_view->on_selection_change = [this] { | ||||
|         update_statusbar(); | ||||
|         if (on_selection_change) | ||||
|             on_selection_change(*m_table_view); | ||||
|     }; | ||||
|     m_item_view->on_selection = [this](const GModelIndex&) { | ||||
|         if (on_selection) | ||||
|             on_selection(*m_item_view); | ||||
|     m_item_view->on_selection_change = [this] { | ||||
|         update_statusbar(); | ||||
|         if (on_selection_change) | ||||
|             on_selection_change(*m_item_view); | ||||
|     }; | ||||
| 
 | ||||
|     set_view_mode(ViewMode::Icon); | ||||
|  | @ -172,3 +169,30 @@ void DirectoryView::open_next_directory() | |||
|         model().open(m_path_history[m_path_history_position]); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void DirectoryView::update_statusbar() | ||||
| { | ||||
|     if (current_view().selection().is_empty()) { | ||||
|         set_status_message(String::format("%d item%s (%u byte%s)", | ||||
|             model().row_count(), | ||||
|             model().row_count() != 1 ? "s" : "", | ||||
|             model().bytes_in_files(), | ||||
|             model().bytes_in_files() != 1 ? "s" : "")); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     int selected_item_count = current_view().selection().size(); | ||||
|     size_t selected_byte_count = 0; | ||||
| 
 | ||||
|     current_view().selection().for_each_index([&](auto& index) { | ||||
|         auto size_index = current_view().model()->index(index.row(), GDirectoryModel::Column::Size); | ||||
|         auto file_size = current_view().model()->data(size_index).to_int(); | ||||
|         selected_byte_count += file_size; | ||||
|     }); | ||||
| 
 | ||||
|     set_status_message(String::format("%d item%s selected (%u byte%s)", | ||||
|         selected_item_count, | ||||
|         selected_item_count != 1 ? "s" : "", | ||||
|         selected_byte_count, | ||||
|         selected_byte_count != 1 ? "s" : "")); | ||||
| } | ||||
|  |  | |||
|  | @ -24,7 +24,7 @@ public: | |||
|     void refresh(); | ||||
| 
 | ||||
|     Function<void(const StringView&)> on_path_change; | ||||
|     Function<void(GAbstractView&)> on_selection; | ||||
|     Function<void(GAbstractView&)> on_selection_change; | ||||
|     Function<void(const StringView&)> on_status_message; | ||||
|     Function<void(int done, int total)> on_thumbnail_progress; | ||||
| 
 | ||||
|  | @ -62,6 +62,7 @@ private: | |||
|     void handle_activation(const GModelIndex&); | ||||
| 
 | ||||
|     void set_status_message(const StringView&); | ||||
|     void update_statusbar(); | ||||
| 
 | ||||
|     ViewMode m_view_mode { Invalid }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -93,11 +93,12 @@ int main(int argc, char** argv) | |||
|         directory_view->open_parent_directory(); | ||||
|     }); | ||||
| 
 | ||||
|     directory_view->on_selection = [&](GAbstractView& view) { | ||||
|     directory_view->on_selection_change = [&](GAbstractView& view) { | ||||
|         Vector<String> paths; | ||||
|         auto model = static_cast<GDirectoryModel*>(view.model()); | ||||
|         auto& model = *view.model(); | ||||
|         view.selection().for_each_index([&](const GModelIndex& index) { | ||||
|             auto path = model->entry(index.row()).full_path(*model); | ||||
|             auto name_index = model.index(index.row(), GDirectoryModel::Column::Name); | ||||
|             auto path = model.data(name_index, GModel::Role::Custom).to_string(); | ||||
|             paths.append(path); | ||||
|         }); | ||||
|         selected_file_paths = paths; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling