From b0a06e944aee9c83f2680544965c7ff6d7f6add4 Mon Sep 17 00:00:00 2001 From: reionwong Date: Mon, 27 Sep 2021 12:54:47 +0800 Subject: [PATCH] Optimize the logic for selecting file sizes --- model/foldermodel.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 77a35e2..ab37d96 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -1198,6 +1198,15 @@ void FolderModel::selectionChanged(const QItemSelection &selected, const QItemSe } } + updateActions(); + + emit selectionCountChanged(); + + // The desktop does not need to calculate the selected file size. + if (m_isDesktop) + return; + + // Start calculating file size. if (m_sizeJob == nullptr) { m_sizeJob = new CFileSizeJob; @@ -1223,13 +1232,22 @@ void FolderModel::selectionChanged(const QItemSelection &selected, const QItemSe m_selectedItemSize = ""; emit selectedItemSizeChanged(); } else { - m_sizeJob->blockSignals(false); - m_sizeJob->start(selectedUrls()); + bool fileExists = false; + + for (const QModelIndex &index : m_selectionModel->selectedIndexes()) { + if (itemForIndex(index).isFile()) { + fileExists = true; + break; + } + } + + // Reion: The size label at the bottom needs to be updated + // only if you select the include file. + if (fileExists) { + m_sizeJob->blockSignals(false); + m_sizeJob->start(selectedUrls()); + } } - - updateActions(); - - emit selectionCountChanged(); } void FolderModel::dragSelectedInternal(int x, int y)