mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 07:05:08 +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" : ""));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue