mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:17:41 +00:00
FileManager: Show human-readable file size info in the status bar
Fixes #553.
This commit is contained in:
parent
2976e889e9
commit
4463adc0ff
1 changed files with 22 additions and 6 deletions
|
@ -4,6 +4,24 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
// FIXME: Remove this hackery once printf() supports floats.
|
||||||
|
static String number_string_with_one_decimal(float number, const char* suffix)
|
||||||
|
{
|
||||||
|
float decimals = number - (int)number;
|
||||||
|
return String::format("%d.%d %s", (int)number, (int)(decimals * 10), suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String human_readable_size(size_t size)
|
||||||
|
{
|
||||||
|
if (size < 1 * KB)
|
||||||
|
return String::format("%zu bytes", size);
|
||||||
|
if (size < 1 * MB)
|
||||||
|
return number_string_with_one_decimal((float)size / (float)KB, "KB");
|
||||||
|
if (size < 1 * GB)
|
||||||
|
return number_string_with_one_decimal((float)size / (float)MB, "MB");
|
||||||
|
return number_string_with_one_decimal((float)size / (float)GB, "GB");
|
||||||
|
}
|
||||||
|
|
||||||
void DirectoryView::handle_activation(const GModelIndex& index)
|
void DirectoryView::handle_activation(const GModelIndex& index)
|
||||||
{
|
{
|
||||||
if (!index.is_valid())
|
if (!index.is_valid())
|
||||||
|
@ -191,11 +209,10 @@ void DirectoryView::open_next_directory()
|
||||||
void DirectoryView::update_statusbar()
|
void DirectoryView::update_statusbar()
|
||||||
{
|
{
|
||||||
if (current_view().selection().is_empty()) {
|
if (current_view().selection().is_empty()) {
|
||||||
set_status_message(String::format("%d item%s (%u byte%s)",
|
set_status_message(String::format("%d item%s (%s)",
|
||||||
model().row_count(),
|
model().row_count(),
|
||||||
model().row_count() != 1 ? "s" : "",
|
model().row_count() != 1 ? "s" : "",
|
||||||
model().bytes_in_files(),
|
human_readable_size(model().bytes_in_files()).characters()));
|
||||||
model().bytes_in_files() != 1 ? "s" : ""));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,9 +225,8 @@ void DirectoryView::update_statusbar()
|
||||||
selected_byte_count += file_size;
|
selected_byte_count += file_size;
|
||||||
});
|
});
|
||||||
|
|
||||||
set_status_message(String::format("%d item%s selected (%u byte%s)",
|
set_status_message(String::format("%d item%s selected (%s)",
|
||||||
selected_item_count,
|
selected_item_count,
|
||||||
selected_item_count != 1 ? "s" : "",
|
selected_item_count != 1 ? "s" : "",
|
||||||
selected_byte_count,
|
human_readable_size(selected_byte_count).characters()));
|
||||||
selected_byte_count != 1 ? "s" : ""));
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue