summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-12 18:59:13 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-12 18:59:13 +0200
commitd86fb8033eabd2250117465f2575a1c00a2d3614 (patch)
treeb5f297921f8cf9d8cdd2facd9a74b4559e567119 /Applications
parent13ca1ee8dc56014dc42a66d1f86c8bbe8a086d16 (diff)
downloadserenity-d86fb8033eabd2250117465f2575a1c00a2d3614.zip
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.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/FileManager/DirectoryView.cpp48
-rw-r--r--Applications/FileManager/DirectoryView.h3
-rw-r--r--Applications/FileManager/main.cpp7
3 files changed, 42 insertions, 16 deletions
diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp
index d3aa3e5068..31bdb6cce1 100644
--- a/Applications/FileManager/DirectoryView.cpp
+++ b/Applications/FileManager/DirectoryView.cpp
@@ -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" : ""));
+}
diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h
index 6a3bb9c76d..458f8cf065 100644
--- a/Applications/FileManager/DirectoryView.h
+++ b/Applications/FileManager/DirectoryView.h
@@ -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 };
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp
index 0c4dd836c0..257c77955c 100644
--- a/Applications/FileManager/main.cpp
+++ b/Applications/FileManager/main.cpp
@@ -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;